Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
bluet authored May 1, 2017
1 parent 7735c28 commit c98e973
Showing 1 changed file with 30 additions and 11 deletions.
41 changes: 30 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ Support **wildcard**, **nested**, and **filter_function** in *template*.
~~~~ js
"use strict";

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

var template = {
"runtime": {
"connectionState": undefined,
"powerState": function () {return "HELLOWORLD"},
"powerState": function (args) {return "HELLOWORLD " + args},
"bootTime": "my boot time",
"paused": false,
"snapshotInBackground": 1111111
Expand All @@ -36,15 +36,34 @@ var data = function_or_somewhere();
//};


var result = objectFilter(template, data);
var result = objFilter(template, data);

// result is:
// {
// "runtime": {
// "powerState": "HELLOWORLD",
// "bootTime": "2017-04-20T13:56:19.377Z",
// "paused": false,
// "snapshotInBackground": true
// }
// };
{
"runtime": {
"powerState": "HELLOWORLD poweredOn",
"bootTime": "2017-04-20T13:56:19.377Z",
"paused": false,
"snapshotInBackground": true
}
};
~~~~

## Template Object
According to the **Template Object structure**, `obj-filter` supports the following types of value with different behaviour to build the result object.

### undefined
If the *value* of the key is `undefined`, the key will be **filtered** (skipped) and will not included in result object.

### object
If the *value* of the key is an `object`, `obj-filter` will _dive into it and check the **deeper** level of keys_.

### function
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.
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.

- If return `undefined`, the key will be **filtered** (skipped).
- If return anything else, the key will be **included**.

### Anything else (string, integer, `true`, `false`, etc)
The value of the key will be **included**.

0 comments on commit c98e973

Please sign in to comment.