Skip to content

Commit c98e973

Browse files
authored
Update README.md
1 parent 7735c28 commit c98e973

File tree

1 file changed

+30
-11
lines changed

1 file changed

+30
-11
lines changed

README.md

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ Support **wildcard**, **nested**, and **filter_function** in *template*.
66
~~~~ js
77
"use strict";
88

9-
var objectFilter = require('obj-filter');
9+
var objFilter = require('obj-filter');
1010

1111
var template = {
1212
"runtime": {
1313
"connectionState": undefined,
14-
"powerState": function () {return "HELLOWORLD"},
14+
"powerState": function (args) {return "HELLOWORLD " + args},
1515
"bootTime": "my boot time",
1616
"paused": false,
1717
"snapshotInBackground": 1111111
@@ -36,15 +36,34 @@ var data = function_or_somewhere();
3636
//};
3737

3838

39-
var result = objectFilter(template, data);
39+
var result = objFilter(template, data);
4040

4141
// result is:
42-
// {
43-
// "runtime": {
44-
// "powerState": "HELLOWORLD",
45-
// "bootTime": "2017-04-20T13:56:19.377Z",
46-
// "paused": false,
47-
// "snapshotInBackground": true
48-
// }
49-
// };
42+
{
43+
"runtime": {
44+
"powerState": "HELLOWORLD poweredOn",
45+
"bootTime": "2017-04-20T13:56:19.377Z",
46+
"paused": false,
47+
"snapshotInBackground": true
48+
}
49+
};
5050
~~~~
51+
52+
## Template Object
53+
According to the **Template Object structure**, `obj-filter` supports the following types of value with different behaviour to build the result object.
54+
55+
### undefined
56+
If the *value* of the key is `undefined`, the key will be **filtered** (skipped) and will not included in result object.
57+
58+
### object
59+
If the *value* of the key is an `object`, `obj-filter` will _dive into it and check the **deeper** level of keys_.
60+
61+
### function
62+
If the *value* of the key is an `function`, `obj-filter` will _pass the **value** of the same key in **input data** to the **function**_, and includes it's returned data in result.
63+
So it's your call to customize how you would like to handle, define what you want to do with the input data. Be sure to **return something** from your function.
64+
65+
- If return `undefined`, the key will be **filtered** (skipped).
66+
- If return anything else, the key will be **included**.
67+
68+
### Anything else (string, integer, `true`, `false`, etc)
69+
The value of the key will be **included**.

0 commit comments

Comments
 (0)