Example:
const obj = {
'153': 153,
'1000': 1000,
'0.5': 0.5,
'-1': -1,
'1e3': 1000,
'0x99': 153,
'9007199254740993': 9007199254740992,
'9007199254740992': 9007199254740992,
}
const encoded = rison.encode(obj);
// (-1:-1,0.5:0.5,0x99:153,1000:1000,153:153,1e3:1000,9007199254740992:9007199254740992,9007199254740993:9007199254740992)
console.log(encoded);
// rison parser error: missing ':'
// error: Uncaught (in promise) Error: rison decoder error: missing ':'
const decoded = rison.decode(encoded);
console.log(decoded);
This is because the current check accounts for infinities, non-numeric keys, and NaN, but it doesn't check that the numeric value is a valid Rison key or that it's round-trippable:
|
k = !isFinite(i) || isNaN(parseInt(i)) ? s.string(i) : s.number(i) |