0.2.8 • Published 4 years ago

json-map-cycle v0.2.8

Weekly downloads
1
License
MIT
Repository
-
Last release
4 years ago

json-map-cycle

JSON library with parse and stringify for Map, Set, Date, comments (remove only) and manage cycle.

Use the default JSON package an has exactly the same signature.

replacer and reviver can still be used.

decycle and recycle from package cycle are both optional.

Can be used as static or as an object with different parameters.

You can use Json.setOptions({...}) when starting your app before using static form.

stringify

Stringify Map to

  • { anyKey: { "$map": [...] } }
  • [...]

Stringify Set to

  • { anyKey: { "$set": ... } }`
  • [...]

Stringify Date for JSON or UTC format to

  • { anyKey: { "$date": "..." } }
  • "..."

Can decycle the parsed object with $ref keys (off by default).

parse

Remove comments by default

  • // ...
  • /* ... */

Parse a new Map() from

  • { anyKey: { "$map": [...] } }
  • { knownMapKeys: [...] }
  • { regexMapKeys: [...] }

Parse a new Set() from

  • { anyKey: { "$set": [...] } }
  • { knownSetKeys: [...] }
  • { regexSetKeys: [...] }

Parse a new Date() from

  • { anyKey: { "$date": "..." } }
  • { knownDateKeys: "..." }
  • { regexDateKeys: "..." }

Can recycle the parsed object from $ref keys (on by default).

Examples

With the static form :

import { Json } from 'json-map-cycle'

// replacer to decycle "of" keys to "$ref" a known type
function replacer(this: any, key: string, value: any): any {
  if(key && key === 'of') {
    return { $ref: `$[\"types\"][\"${value.name}\"]` }
  }
}
const jsonApiSchema = Json.stringify(apiSchema, replacer, 2)

With object form :

import { Json } from 'json-map-cycle'

const json = new Json({
  ...opions...
})
const apiSchema = Json.parse(jsonApiSchema)
0.2.8

4 years ago

0.2.7

4 years ago

0.2.6

4 years ago

0.2.5

4 years ago

0.2.4

4 years ago

0.2.3

4 years ago

0.2.2

4 years ago

0.2.1

4 years ago

0.2.0

4 years ago

0.1.1

4 years ago

0.1.0

4 years ago

0.0.3

4 years ago

0.0.2

4 years ago

0.0.1

4 years ago