Skip to content

iamdevonbutler/js-jsonf

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

42 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

js-jsonf Build Status

JS Objects w/ function support.

Move JS from one live system to another.

engines: node >= 8.x

Example

const {encode, decode} = require('js-jsonf');
const obj = {
  a: 1,
  b() {
    return 1;
  }
};
const str = encode(obj);
const obj1 = decode(str);

Installation

npm i js-jsonf --save

API

.encode(obj, [throwOnInvalidType = false])

Returns false given an invalid type.

.decode(str, [throwOnInvalidSyntax = false])

Returns undefined given a invalid syntax.

Supported data types

  • String
  • Boolean
  • Number
  • Array
  • Object
  • Date
  • Function (all combinations of: regular, async, generator, arrow)
  • NaN
  • null
  • undefined

All types are supported when wrapped in a function.

Caveats

Function behavior is normalized and consistent; however, the parsed function may contain slight formatting differences from the original; its functionality however, will remain consistent.

Perf

As fast as native JSON.parse() JSON.stringify():

// 1M iterations. Each iteration calls both encode and decode.

// js-jsonf:
// milliseconds: 6833.45
// ops/sec: 146,338.965
// ---
// control (native):
// milliseconds: 7033.58
// ops/sec: 142,175.109

License

MIT

About

Next level JS data interchange w/ functions.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published