npm.io
0.0.4 • Published 6 years ago

binarynator

Licence
MIT
Version
0.0.4
Deps
1
Size
20 kB
Vulns
0
Weekly
0

Binarynator

Just a simple "transcoder" which converts JSON structures, defined by a schema, to binary and back.

Why?

Why not?

Example

import { encode, decode, object, string, int32, array } from 'binarynator';

const schema = object({
  word: string(),
  number: int32().nullable(),
  optional_number: int32().optional(),
  nested: object({
    child: string(),
  }),
  array: array(int32()),
});

const input = {
  word: 'something',
  number: null,
  optional_number: 1337,
  nested: {
    child: 'hello!',
  },
  array: [1, 2, 3, 4],
}

const encoded = encode(schema, input);
// encoded is now a Buffer, use this to write to a file or something...

const decoded = decode(schema, encoded);
// decoded is in the exact structure as defined by the schema, filled with the decoded data

TODO

  • include a version number of the schema in the binary
  • InferType on arrays and oneOf doesn't work yet
  • Improve error handling & messaging