num-record-packer
v0.0.7
Published
A JSON to JSON mapper in TypeScript for compacting NUM objects according to an unpacker spec.
Downloads
3
Readme
TypeScript NUM Record Packer
This program takes a JSON object and convertes it to a more compact JSON object using a mapping specification, also written as JSON.
Running the example code in a web browser
- Clone the repository using
git clone [email protected]:NUMtechnology/num-record-packer.git
. cd num-record-packer
- Run
npm install -g webpack
- Run
npm install -g webpack-cli
- Run
npm install
- Open the
test/index.html
file using a web browser (Only tested using Brave browser) - Paste your JSON into the first two text areas and click
Pack
to see the result.
Use the Packer in JavaScript
const api = require('num-record-packer');
const mapperData = {
phonetic: {
assignKeys: ['a', 'b', 'c'],
},
};
const data = {
phonetic: {
a: 'alpha',
b: 'bravo',
c: 'charlie',
},
};
const packed = api.mapper.pack(data, mapperData);
console.log(JSON.stringify(packed));
Use the Packer in TypeScript
import { createNumRecordPacker } from 'num-record-packer';
const mapperData = {
phonetic: {
assignKeys: ['a', 'b', 'c'],
},
};
const data: object = {
phonetic: {
a: 'alpha',
b: 'bravo',
c: 'charlie',
},
};
const packer = createNumRecordPacker();
const packed: object = packer.pack(data, mapperData);
console.log(JSON.stringify(packed));```