Skip to content

Commit

Permalink
refactor(keysRecorder):rename whitelist 2 select and blacklist 2 unse…
Browse files Browse the repository at this point in the history
…lects
  • Loading branch information
yidinghan committed Apr 11, 2017
1 parent 6731973 commit f5ae9b1
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 18 deletions.
26 changes: 13 additions & 13 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ const pick = require('lodash.pick');
*
* @param {object} payload - input arguments
* @param {string[]} [payload.defaults] - default keys will be collected
* @param {string[]} [payload.whitelist] - keys will be collected as
* @param {string[]} [payload.selects] - keys will be collected as
* additional part
* @param {string[]} [payload.blacklist] - keys that will be ignored at last
* @param {string[]} [payload.unselects] - keys that will be ignored at last
* @return {function} closure function, setting by given payload
* @example
* // without payload
Expand All @@ -25,29 +25,29 @@ const pick = require('lodash.pick');
* recorder() // {}
* recorder({ foo: 1, bar: 2, foobar: { a: 3, b: 4 } }) // { foo: 1 }
*
* // with defaults and whitelist
* const recorder = keysRecorder({ defaults: ['foo'], whitelist: ['foobar'] });
* // with defaults and selects
* const recorder = keysRecorder({ defaults: ['foo'], selects: ['foobar'] });
* recorder() // {}
* recorder({
* foo: 1,
* bar: 2,
* foobar: { a: 3, b: 4 }
* }) // { foo: 1, foobar: { a: 3, b: 4 } }
*
* // with defaults and blacklist
* const recorder = keysRecorder({ defaults: ['foobar'], blacklist: ['foobar.a'] });
* // with defaults and unselects
* const recorder = keysRecorder({ defaults: ['foobar'], unselects: ['foobar.a'] });
* recorder() // {}
* recorder({
* foo: 1,
* bar: 2,
* foobar: { a: 3, b: 4 }
* }) // { foobar: { a: 3 } }
*
* // with defaults and whitelist and blacklist
* // with defaults and selects and unselects
* const recorder = keysRecorder({
* defaults: ['foo'],
* whitelist: ['foobar'],
* blacklist: ['foobar.b'],
* selects: ['foobar'],
* unselects: ['foobar.b'],
* });
* recorder() // {}
* recorder({
Expand All @@ -59,18 +59,18 @@ const pick = require('lodash.pick');
exports.keysRecorder = (payload = {}) => {
const {
defaults = [],
whitelist = [],
blacklist = [],
selects = [],
unselects = [],
} = payload;

return (target) => {
if (!target) { return {}; }

const logObject = {};
defaults.concat(whitelist).forEach((path) => {
defaults.concat(selects).forEach((path) => {
set(logObject, path, get(target, path));
});
blacklist.forEach((path) => {
unselects.forEach((path) => {
unset(logObject, path, get(target, path));
});

Expand Down
10 changes: 5 additions & 5 deletions test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,20 @@ test('keysRecorder:should get defaults keys', (t) => {
t.deepEqual(result, { a: 1 });
});

test('keysRecorder:should get defaults and whitelist', (t) => {
test('keysRecorder:should get defaults and selects', (t) => {
const recorder = keysRecorder({
defaults: ['a'],
whitelist: ['b'],
selects: ['b'],
});
const result = recorder(testTarget);

t.deepEqual(result, { a: 1, b: 2 });
});

test('keysRecorder:should get defaults and blacklist', (t) => {
test('keysRecorder:should get defaults and unselects', (t) => {
const recorder = keysRecorder({
defaults: ['c'],
blacklist: ['c.e'],
unselects: ['c.e'],
});
const result = recorder(testTarget);

Expand All @@ -52,7 +52,7 @@ test('keysRecorder:should get defaults and blacklist', (t) => {
test('keysRecorder:should get empty object without target', (t) => {
const recorder = keysRecorder({
defaults: ['c'],
blacklist: ['c.e'],
unselects: ['c.e'],
});
const result = recorder();

Expand Down

0 comments on commit f5ae9b1

Please sign in to comment.