lucagez / slow-json-stringify

The slowest stringifier in the known universe. Just kidding, it's the fastest (:
https://github.com/lucagez/slow-json-stringify
MIT License
468 stars 17 forks source link

possible error in example #2

Closed imthenachoman closed 5 years ago

imthenachoman commented 5 years ago

First, great job. I love the idea of using a schema. Very clever.

In the Defining schema with nested objects example, the schema has e as a number but the data passed is not a number.

A few questions/points:

lucagez commented 5 years ago

Thank you! 🎉

Yes, it was definitely an error, thank you for pointing it out!

What happens if a data type in the object does not match the schema?

The template that SJS build is made specifically for the data type that has to be inserted.

E.g.

const schema = { a: 'string', b: 'number' };

// output template =>  [{ "a":" ]  x1  [", "b": ]  x2  [ } ] 

Where you insert the values at x positions. So, it's very important that the data type matches the schema.

Initially, I designed like that for maximum performance. However, I have to check how much a data type check could have an impact on performance.

Can you modify the schema after the sjs has been initialized/created?

There is no built-in feature for that. The template creation is not meant to be a repeated operation. So, it is not optimized for performance. You can however simply compile another schema.

imthenachoman commented 5 years ago

Thank you!