1.0.12 • Published 9 years ago

jsencode v1.0.12

Weekly downloads
1
License
MIT
Repository
github
Last release
9 years ago

jsencode

Build Status npm version

An implementation for encoding typed JavaScript objects, similar to BEncode

Example

var JSEncoder = require('jsencode');
var Foo = require('foo');
var encoder = new JSEncoder({types:[Foo]});  // or, encoder.registerTypes(Foo, Bar, ...);

encoder.encode("foo"); // returns "3:foo"
encoder.encode({foo: "bar"}); // returns "{3:foo3:bar}"
encoder.encode(new Foo()); // returns "<3:Foo>"

encoder.decode("3:foo"); // returns "foo"
encoder.decode("{3:foo3:bar}"); // returns {foo: "bar"}
encoder.decode("<3:Foo>"); // returns Foo() instance

Options

types - specify a list of type constructors to register for deserializing Objects

includePrivateFields - allows exclusion of fields that start with '_'

ignoreUnregisteredTypes - ignore unregistered types, deserializing it as a null value instead

Encoding

Any

any := <string> | <number> | <boolean> | <dictionary> | <object> | <array> | <null>

Undefined

undefined := 'u'

Null

null := 'n'

String

string := <length> ':' <value>

length = any valid Number value that is an integer >= 0

value = any utf-8 encoded string value

Number

number := '(' <value> ')'

value = any valid Number value

Boolean

boolean := 't' | 'f'

Array

array := '[' <values> ']'

values := (<any>)*

Dictionary (Object with constructor Object)

dictionary := '{' <string-value-pairs> '}'

string-value-pairs := (string-value-pair)*

string-value-pair := <string><any>

Object (Object with registered constructor Function)

object := '<' <type> <string-value-pairs> '>'

type := <string>

string-value-pairs := (string-value-pair)*

string-value-pair := <string><any>

1.0.12

9 years ago

1.0.11

9 years ago

1.0.10

9 years ago

1.0.9

10 years ago

1.0.8

10 years ago

1.0.7

10 years ago

1.0.6

11 years ago

1.0.5

11 years ago

1.0.4

11 years ago

1.0.3

11 years ago

1.0.2

11 years ago

1.0.1

11 years ago

1.0.0

11 years ago