mirror of
https://github.com/flynx/serialize.js.git
synced 2026-07-10 03:00:57 +00:00
minor tweaks + docs...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
9a35039e68
commit
445b29d051
23
README.md
23
README.md
@ -53,7 +53,7 @@ Thus, care must be taken when serializing structures containing function.
|
||||
|
||||
### `serialize(..)` / `eJSON.stringify(..)`
|
||||
|
||||
Serialize a JavaScript value into a JSON or JSON-like string.
|
||||
Serialize a JavaScript value into a JSON/eJSON string.
|
||||
```
|
||||
serialize(<value>)
|
||||
eJSON.stringify(<value>)
|
||||
@ -89,12 +89,33 @@ Supported options:
|
||||
|
||||
### `deserialize(..)` / 'eJSON.parse(..)'
|
||||
|
||||
Deserialize a JSON/eJSON into a value.
|
||||
```
|
||||
deserialize(<string>)
|
||||
eJSON.parse(<string>)
|
||||
-> <value>
|
||||
```
|
||||
|
||||
Deserializing function is disabled by default as it can be a security
|
||||
risk if the eJSON came from an untrusted source.
|
||||
|
||||
Enable function deserialization:
|
||||
```
|
||||
deserialize(<string>, true)
|
||||
eJSON.parse(<string>, true)
|
||||
deserialize(<string>, {functions: true})
|
||||
eJSON.parse(<string>, {functions: true})
|
||||
-> <value>
|
||||
```
|
||||
|
||||
Passing a function list (generated by `serialize(<value>, {functions: <functions>})`)
|
||||
for deserialization:
|
||||
```
|
||||
deserialize(<string>, {functions: <functions>})
|
||||
eJSON.parse(<string>, {functions: <functions>})
|
||||
-> <value>
|
||||
```
|
||||
|
||||
|
||||
### `deepCopy(..)`
|
||||
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "ig-serialize",
|
||||
"version": "1.2.0",
|
||||
"version": "1.2.1",
|
||||
"description": "experimental extended json serializaion...",
|
||||
"main": "serialize.js",
|
||||
"scripts": {
|
||||
|
||||
29
serialize.js
29
serialize.js
@ -93,12 +93,26 @@ module.MIN_LENGTH_REF = REFERENCE.length * 16
|
||||
// _serialize(obj, base_path, seen, indent, depth, options)
|
||||
// -> str
|
||||
//
|
||||
// Options format:
|
||||
//
|
||||
// options format:
|
||||
// {
|
||||
// // Indent to use
|
||||
// // Indent to use for formatting output.
|
||||
// // Can be:
|
||||
// // <number> - number of spaces to use for indent
|
||||
// // <string> - string to use for indent
|
||||
// // NOTE: only whitespace characters are supported
|
||||
// // currently.
|
||||
// indent: undefined,
|
||||
//
|
||||
// // Top level indent.
|
||||
// depth: 0,
|
||||
//
|
||||
// // Minimum length of string/bigint to reference.
|
||||
// min_length_ref: MIN_LENGTH_REF,
|
||||
//
|
||||
// // Stored functions.
|
||||
// // If set to an array functions will be pushed to it and stored
|
||||
// // by index.
|
||||
// functions: undefined,
|
||||
// }
|
||||
//
|
||||
@ -711,7 +725,12 @@ module.eJSON = {
|
||||
return this[handler](state, path, match, str, i, line) },
|
||||
|
||||
|
||||
parse: function(str, options={}){
|
||||
parse: function(str, options){
|
||||
options =
|
||||
options === true ?
|
||||
{functions: true}
|
||||
: (options
|
||||
?? {})
|
||||
|
||||
// stage 1: build the object...
|
||||
var state = {functions: options.functions}
|
||||
@ -731,10 +750,6 @@ module.eJSON = {
|
||||
var deserialize =
|
||||
module.deserialize =
|
||||
function(str, options){
|
||||
options =
|
||||
options === true ?
|
||||
{functions: true}
|
||||
: options
|
||||
return eJSON.parse(str, options) }
|
||||
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user