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

[acc].flat error : undefined is not a function. #5

Closed wkmcyz closed 5 years ago

wkmcyz commented 5 years ago

This is because the use of Array.flat API, which is not supported below node v11.0.0.Here is the Browser Compatibility of Array.flat. So as far as I am concerned, other implementations here may be better for more scenarios.

wkmcyz commented 5 years ago

Actually I want to use sjs in react-native, however it seems that react-native does not support Array.flat according to https://stackoverflow.com/a/52878753/9798666.

wkmcyz commented 5 years ago

I found a workaround for this, which is to use array-flat-polyfill to add Array.flat property.

lucagez commented 5 years ago

Hi @wkmcyz πŸ‘‹ Thank you for pointing out this compatibility issue! I was using [acc].flat() just for its convenient syntax. I replaced it with an array check with a consequent manual wrapping into an array. As it's a lightweight workaround and it adds zero external dependencies.

This is the modified line: https://github.com/lucagez/slow-json-stringify/blob/master/src/_makeQueue.mjs#L35

Let me know if this fix your issues!

wkmcyz commented 5 years ago

Hi @lucagez 😁. Of course this fixed the issue, thank you for such a great job to write sjs. It's really fastπŸš€.