Skip to content

Treat Date objects as primitive in schema.cloneKeySort()

Choose a tag to compare

@bmomberger-bitovi bmomberger-bitovi released this 24 May 04:49
· 27 commits to master since this release

cloneKeySort() creates a clone of an object with all keys and subkeys added in alphabetical order. This ensures that regardless of platform and JS engine, two objects with the same keys and values can stringify to the same string, regardless of the order in which keys were added.

However, Dates were being treated as any other object by cloneKeySort(), and the output would replace date objects with empty plain objects. The value of a Date isn't based on enumerable properties, but rather as internal state that is reflected in string representations. By treating Dates as primitives, more information is preserved when making the clone.