File: README.md

package info (click to toggle)
node-json-localizer 0.0.3-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid, stretch
  • size: 96 kB
  • ctags: 43
  • sloc: makefile: 4; sh: 2
file content (44 lines) | stat: -rw-r--r-- 1,285 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# localize-json
When you need humans to localize a json object from a
config file. Typical use case is for a local config file to extend
an application config on the fly.

## Example

```
var Localizer = require('localize-json').Localizer;
var localizer = new Localizer(myobj);
localizer.where('path.to.prop').if({'prop': 'hasvalue'}.then({'addthis': 'propandvalue'}));
// `if` is optional
localizer.where('simpleprop').then('setthisvalue');
```

## API

### .where(rules)

`rules`: path to an object; eg.: `prop`, `nested.prop`.

Define which object(s) to target.

### .if(rules)

`rules`: object of rules to filter the targeted objects.
Eg.: `{'thisprop': 'hasthisvalue'}

Can be a single flat value instead of an object, and then the targeted
key will be checked against this value.

### .then(rules)

`rules`: object of rules to apply on the filtered objects.
Eg.: `{sethis: 'propandvalue', {anotherprop: 'tobeset'}}`

Can be a single flat value instead of an object, and then the targeted key
will be replaced by this value.

Can be a function, which then should return either a flat value or an object.
The function will take the current targeted object as parameter.


See [tests](https://github.com/yohanboniface/json-localizer/blob/master/tests/index.js) for more examples.