convert object to array
npm install obj2arr
var obj2arr = require('obj2arr');
var defs = {
case1: {
type: 'array',
items: [
{
id: 'key',
type: 'string'
},
{
id: 'num',
type: 'number'
}
]
}
};
obj2arr.define(defs);
var data = {
key: 'test1',
num: 10
};
var encoded = obj2arr.encode('case1', data);
console.log(encoded);
// -- output --
// [ 'test1', 10 ]
var decoded = obj2arr.decode('case1', encoded);
console.log(decoded);
// -- output --
// { key: 'test1', num: 10 }
var objSchema = {
type: 'object',
properties: {
key: {
id: 'key',
type: 'string'
},
num: {
id: 'num',
type: 'number'
}
}
};
var arrSchema = obj2arr.tools.toArrSchema(objSchema);
console.log(arrSchema);
// -- output --
// { type: 'array',
// items: [ { id: 'key', type: 'string' }, { id: 'num', type: 'number' } ] }
var arrSchema = {
type: 'array',
items: [
{
id: 'key',
type: 'string'
},
{
id: 'num',
type: 'number'
}
]
};
var objSchema = obj2arr.tools.toObjSchema(arrSchema);
console.log(objSchema);
// -- output --
// { type: 'object',
// properties:
// { key: { id: 'key', type: 'string' },
// num: { id: 'num', type: 'number' } } }
- Fork it ( https://github.com/iyu/obj2arr/fork )
- Create a feature branch
- Commit your changes
- Rebase your local changes against the master branch
- Run test suite with the
npm test
command and confirm that it passes - Create new Pull Request