Function: canonicalize()
canonicalize<
T
>(object
):string
Defined in: packages/hypergraph/src/utils/jsc.ts:53
JSON canonicalize function. Creates crypto safe predictable canocalization of JSON as defined by RFC8785.
Type Parameters
T
T
= unknown
Parameters
object
T
object to JSC canonicalize
Returns
string
See
Examples
import { canonicalize } from '@graph-framework/utils'
console.log(canonicalize(null)) // 'null'
console.log(canonicalize(1)) // '1'
console.log(canonicalize("test")) // "string"
console.log(canonicalize(true)) // 'true'
import { canonicalize } from '@graph-framework/utils'
const json = {
from_account: '543 232 625-3',
to_account: '321 567 636-4',
amount: 500,
currency: 'USD',
};
console.log(canonicalize(json)) // '{"amount":500,"currency":"USD","from_account":"543 232 625-3","to_account":"321 567 636-4"}'
import { canonicalize } from '@graph-framework/utils'
console.log(canonicalize([1, 'text', null, true, false])) // '[1,"text",null,true,false]'
Throws
NaNNotAllowedError if given object is of type number, but is not a valid number
Throws
InfinityNotAllowedError if given object is of type number, but is the infinite number