Function isSerializable

  • Check to see if the value is serializable without losing information

    Parameters

    • value: unknown

      Value to test

    Returns boolean

    True if serializable; false otherwise

    Note: the values undefined and null are serializable (on their own or in an array), but null values get transformed into undefined when serializing/deserializing.

    WARNING: This is inefficient right now as it stringifies, parses, stringifies, and === the value. Please only use this if you need to

    DISCLAIMER: this does not successfully detect that values are not serializable in some cases:

    • Losses of removed properties like functions and Maps
    • Class instances (not deserializable into class instances without special code)

    We intend to improve this in the future if it becomes important to do so. See JSON.stringify documentation for more information.