SipaSerializer
SipaSerializer
Serializer to serialize data of primitive types or even complex Objects, to ensure to be stored as valid JSON and can be deserialized back without data loss.
Includes support for
- Boolean, Number, String, Array, Object, null (native JS[SON] support) And special type handling to support the following types
- Functions
- RegExp, Date
- NaN, Infinity, undefined
- empty (special type when deleting an item of an array)
The special types are escaped by an internal escaping when serialized. See SipaSerializer.STORAGE_PLACEHOLDERS for the escapes.
- SipaSerializer
- .serialize(value) →
string
|null
- .deserialize(value) →
Boolean
|String
|Number
|Array
|Object
|RegExp
|Date
|undefined
|NaN
|Infinity
|null
|*
- .isFunctionString(value) →
boolean
- .isArrayString(value) →
boolean
- .isObjectString(value) →
boolean
- .deserializeFunctionString(value) →
function
- .deepSerializeSpecialTypes(obj) →
Array
|Object
- .deepDeserializeSpecialTypes(obj) →
Array
|Object
- .serialize(value) →
SipaSerializer.serialize(value) → string
| null
Serialize given value to be stored in JSON without loosing its original value
Returns: string
| null
- returns string or null if value is null
Param | Type |
---|---|
value | any |
SipaSerializer.deserialize(value) → Boolean
| String
| Number
| Array
| Object
| RegExp
| Date
| undefined
| NaN
| Infinity
| null
| *
Serialize given value to be stored in JSON without loosing its original value
Param | Type |
---|---|
value | String | null |
SipaSerializer.isFunctionString(value) → boolean
Check if given string is a valid javascript function
Param | Type |
---|---|
value | String |
SipaSerializer.isArrayString(value) → boolean
Check if given string is a valid javascript array
Param | Type |
---|---|
value | String |
SipaSerializer.isObjectString(value) → boolean
Check if given string is a valid javascript object
Param | Type |
---|---|
value | String |
SipaSerializer.deserializeFunctionString(value) → function
Deserialize a valid javascript string into a callable function
Param | Type |
---|---|
value | String |
SipaSerializer.deepSerializeSpecialTypes(obj) → Array
| Object
Serializes (escapes) all special types within an Array or Object to be stored in JSON without data loss.
Original Array or Object is cloned and will not be manipulated.
Param | Type |
---|---|
obj | Array | Object |
SipaSerializer.deepDeserializeSpecialTypes(obj) → Array
| Object
Deserializes (unescapes) all special types of the given Array or Object
Original Array or Object is cloned and will not be manipulated.
Param | Type |
---|---|
obj | Array | Object |