Comparing version
@@ -15,7 +15,4 @@ { | ||
"./transform" | ||
], | ||
"bindings": "esm", | ||
"exportStart": "_start" | ||
}, | ||
"extends": "./node_modules/@assemblyscript/wasi-shim/asconfig.json" | ||
] | ||
} | ||
} |
import { JSON } from ".."; | ||
@json | ||
class Vec2 { | ||
class Vec3 { | ||
x: f32; | ||
y: f32; | ||
z: f32; | ||
} | ||
const vec: Vec2 = blackbox<Vec2>({ | ||
const vec: Vec3 = blackbox<Vec3>({ | ||
x: 0.0, | ||
y: 0.0, | ||
z: 0.0 | ||
}); | ||
bench("Stringify Object (Vec2)", () => { | ||
bench("Stringify Object (Vec3)", () => { | ||
blackbox(JSON.stringify(vec)); | ||
}); | ||
});/* | ||
bench("Parse Object (Vec2)", () => { | ||
blackbox(JSON.parse<Vec2>(blackbox('{"x":0.0,"y":0.0}'))); | ||
bench("Parse Object (Vec3)", () => { | ||
blackbox(JSON.parse<Vec3>(blackbox('{"x":0.0,"y":0.0,"z":0.0}'))); | ||
}); | ||
@@ -42,10 +44,10 @@ | ||
blackbox(JSON.parse<string[][]>(blackbox('[["a","b","c"]]'))); | ||
}); | ||
});*/ | ||
bench("Stringify String", () => { | ||
blackbox(JSON.stringify(blackbox("Hello"))); | ||
blackbox(JSON.stringify(blackbox("Hello \"World!"))); | ||
}); | ||
bench("Parse String", () => { | ||
blackbox(JSON.parse<string>(blackbox('"Hello"'))); | ||
blackbox(JSON.parse<string>(blackbox('"Hello \"World!"'))); | ||
}); | ||
@@ -52,0 +54,0 @@ /* |
@@ -44,49 +44,60 @@ import { u128, u128Safe, u256, u256Safe, i128, i128Safe } from "as-bignum/assembly"; | ||
// @ts-ignore | ||
if (data.length === 0) return "\"\""; | ||
let result = new StringSink("\""); | ||
if (data.length === 0) return "\"\""; | ||
let result = "\""; | ||
let char: i32 = 0; | ||
let last: i32 = 0; | ||
let found: boolean = false; | ||
// @ts-ignore | ||
for (let i = 0; i < data.length; i++) { | ||
// @ts-ignore | ||
switch (unsafeCharCodeAt(data, i)) { | ||
case 0x22: { | ||
result.write("\\\""); | ||
break; | ||
char = unsafeCharCodeAt(<string>data, i); | ||
if (char === 34 || char === 92) { | ||
result += (<string>data).slice(last, i) + "\\"; | ||
last = i; | ||
found = true; | ||
i++; | ||
} else if (char <= 13 && char >= 8) { | ||
result += (<string>data).slice(last, i); | ||
last = ++i; | ||
found = true; | ||
switch (char) { | ||
case 0x22: { | ||
result += "\\\""; | ||
break; | ||
} | ||
case 0x5C: { | ||
result += "\\\\"; | ||
break; | ||
} | ||
case 0x08: { | ||
result += "\\b"; | ||
break; | ||
} | ||
case 0x0A: { | ||
result += "\\n"; | ||
break; | ||
} | ||
case 0x0D: { | ||
result += "\\r"; | ||
break; | ||
} | ||
case 0x09: { | ||
result += "\\t"; | ||
break; | ||
} | ||
case 0x0C: { | ||
result += "\\f"; | ||
break; | ||
} | ||
case 0x0B: { | ||
result += "\\u000b"; | ||
break; | ||
} | ||
} | ||
case 0x5C: { | ||
result.write("\\\\"); | ||
break; | ||
} | ||
case 0x08: { | ||
result.write("\\b"); | ||
break; | ||
} | ||
case 0x0A: { | ||
result.write("\\n"); | ||
break; | ||
} | ||
case 0x0D: { | ||
result.write("\\r"); | ||
break; | ||
} | ||
case 0x09: { | ||
result.write("\\t"); | ||
break; | ||
} | ||
case 0x0C: { | ||
result.write("\\f"); | ||
break; | ||
} | ||
case 0x0B: { | ||
result.write("\\u000b"); | ||
break; | ||
} | ||
default: { | ||
// @ts-ignore | ||
result.write(data.charAt(i)); | ||
break; | ||
} | ||
} | ||
} | ||
result.write("\""); | ||
return result.toString(); | ||
}// 8 10 13 9 12 | ||
if (!found) return "\"" + data + "\""; | ||
else result += (<string>data).slice(last); | ||
return result + "\""; | ||
} | ||
@@ -211,13 +222,13 @@ // Boolean | ||
if (idof<T>() == idof<u128>()) return u128.fromString(data); | ||
// @ts-ignore | ||
// @ts-ignore | ||
if (idof<T>() == idof<u128Safe>()) return u128Safe.fromString(data); | ||
// @ts-ignore | ||
// @ts-ignore | ||
if (idof<T>() == idof<u256>()) return u128Safe.fromString(data); | ||
// @ts-ignore | ||
// @ts-ignore | ||
if (idof<T>() == idof<u256Safe>()) return u256Safe.fromString(data); | ||
// @ts-ignore | ||
// @ts-ignore | ||
if (idof<T>() == idof<i128>()) return i128.fromString(data); | ||
// @ts-ignore | ||
// @ts-ignore | ||
if (idof<T>() == idof<i128Safe>()) return i128Safe.fromString(data); | ||
// @ts-ignore | ||
// @ts-ignore | ||
//if (idof<T>() == idof<i256Safe>()) return data. | ||
@@ -401,3 +412,3 @@ } | ||
} else if (isManaged<valueof<T>>() || isReference<valueof<T>>()) { | ||
const type = changetype<nonnull<valueof<T>>>(__new(offsetof<nonnull<valueof<T>>>(), idof <nonnull<valueof<T>>>())); | ||
const type = changetype<nonnull<valueof<T>>>(__new(offsetof<nonnull<valueof<T>>>(), idof<nonnull<valueof<T>>>())); | ||
// @ts-ignore | ||
@@ -404,0 +415,0 @@ if (isDefined(type.__JSON_Set_Key)) { |
@@ -8,4 +8,4 @@ import { u128 } from "as-bignum/assembly"; | ||
console.log(exp); | ||
console.log(JSON.stringify([ | ||
///console.log(exp); | ||
/*console.log(JSON.stringify([ | ||
"abcdefg", | ||
@@ -15,3 +15,15 @@ 'st"ring" w""ith quotes"', | ||
'string with colon : comma , brace [ ] bracket { } and quote " and other quote "', | ||
])) | ||
]));*/ | ||
console.log("abcdefg"); | ||
console.log('st"ring" w""ith quotes"'); | ||
console.log('string \t\r"with ran\tdom spa\nces and \nnewlines\n\n\n'); | ||
console.log('string with colon : comma , brace [ ] bracket { } and quote " and other quote "'); | ||
console.log(JSON.stringify("abcdefg")); | ||
console.log(JSON.stringify('st"ring" w""ith quotes"')); | ||
console.log(JSON.stringify('string \t\r"with ran\tdom spa\nces and \nnewlines\n\n\n')); | ||
console.log(JSON.stringify('string with colon : comma , brace [ ] bracket { } and quote " and other quote "')); | ||
console.log(JSON.stringify("Hello W\"orld!")); | ||
// @ts-ignore | ||
@@ -18,0 +30,0 @@ @JSON |
{ | ||
"name": "json-as", | ||
"version": "0.5.26", | ||
"version": "0.5.27", | ||
"description": "JSON encoder/decoder for AssemblyScript", | ||
@@ -5,0 +5,0 @@ "types": "assembly/index.ts", |
{ | ||
"name": "@json-as/transform", | ||
"version": "0.5.26", | ||
"version": "0.5.27", | ||
"description": "JSON encoder/decoder for AssemblyScript", | ||
@@ -5,0 +5,0 @@ "main": "./lib/index.js", |
66519
1.52%1484
1.16%