UNPKG

1.49 kBMarkdownView Raw
1# @yodata/transform
2
3declarative, composable JSON transformation utility.
4
5## Installation
6
7```sh
8> npm install --save @yodata/transform
9```
10
11## Usage
12
13```javascript
14const {Context, pluginDefaultValues} = require('@yodata/transform')
15
16const input = {
17 Name: 'Bruce Wayne',
18 Address: '1007 Mountain Drive',
19 City: 'Gotham City',
20 State: 'NJ',
21 Zip: '00001',
22 Phone: '1-800-4-BATMAN'
23}
24
25const toPerson = new Context({
26 Name: 'name',
27 Address: 'streetAddress',
28 City: 'addressLocality',
29 State: 'addressRegion',
30 Zip: 'postalCode',
31 Phone: 'telephone'
32})
33
34toPerson.map(input)
35// result
36{
37 name: 'Bruce Wayne',
38 streetAddress: '1007 Mountain Drive',
39 addressRegion: 'NJ',
40 addressLocality: 'Gotham City',
41 postalCode: '00001',
42 telephone: '1-800-4-BATMAN'
43}
44
45```
46
47## Transformation features
48
49```yaml
50# Context Options
51MyContext:
52 id: {string} # sets the property name on map
53 name: {string} # adds the property 'name' with the value provided
54 value: {any} # replace value of source with provided value
55 value: {#name} # gets the value from the document source
56 value: {function} # ({value, key, object}): any => { return newValue }
57 value: {function} # ({value, key, object}): any => { return newValue }
58 '@context': {object} # sub-context will be applied for current node + child nodes
59
60```
61
62See more examples in the examples directory
63
64## License
65
66MIT © [Dave Duran](mailto:dave@yodata.io)