Closed dimitry12 closed 5 years ago
Yes, thanks to its template nature. When you compile a schema, SJS will create a template and a queue. So, given two objects with the same props/values, SJS will always outputs two equal strings.
E.g.
const stringify = sjs({ a: 'string', b: 'number' });
// output template => [ { "a":" ] x1 [ ", "b": ] x2 [ } ]
stringify({a:"hello", b: 42 }) // {"a":"hello","b":42}
stringify({b:42, a:"hello" }) // {"a":"hello","b":42}
The order of the properties inside the object is irrelevant. As the template requires to be filled following the exact queue order. In this particular case [a, b]
Is SJS deterministic in the same sense as https://github.com/substack/json-stable-stringify is?