json-megatron
v1.0.50
Published
# Install
Downloads
21
Readme
Megatron
Install
yarn add json-megatron
Use
const Megatron = require('json-megatron');
Examples
Return a simple value and parse from string to number
const template = {
newValue: {
type: 'number',
path: '$.value',
}
};
const input = {
value: '10',
};
const result = Megatron(template, input);
// result
{
"newValue": 10,
}
Example with text-transform
We use lib TextTranform to offer string transformations.
const template = {
newValue: {
type: 'string',
path: '$.value',
textTransform: 'uppercase',
},
};
const input = {
value: 'Testing',
};
const result = Megatron(template, input);
// result
{
"newValue": 'TESTING',
}
Example with string-mask
We use lib StringMask to offer mask for strings.
const template = {
newValue: {
type: 'string',
path: '$.value',
stringMask: '000.000.000-00',
},
};
const input = {
value: 12965815620,
};
const result = Megatron(template, input);
// result
{
"newValue": '129.658.156-20',
}