Skip to content

Commit

Permalink
fix: handle passing array of paths to Type.omit()
Browse files Browse the repository at this point in the history
  • Loading branch information
vkarpov15 committed Oct 19, 2017
1 parent 1f8d56e commit 0cfc96f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,15 @@ class Archetype {
return newSchema;
}

omit(path) {
omit(paths) {
const newSchema = new Archetype(this._obj);
_.unset(newSchema._obj, path);
if (Array.isArray(paths)) {
for (const path of paths) {
_.unset(newSchema._obj, path);
}
} else {
_.unset(newSchema._obj, paths);
}
return newSchema;
}

Expand Down
13 changes: 13 additions & 0 deletions test/unit.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -725,6 +725,19 @@ describe('schema modifications', function() {
});
});

it('omit() multiple paths', function() {
const Test = new Archetype({
str: 'string',
num: 'number',
bool: 'boolean'
}).compile();

const Test2 = Test.omit(['num', 'str']).compile('Test2');
assert.deepEqual(new Test2({ str: 123, num: '123', bool: 'yes' }), {
bool: true
});
});

it('pick() creates a new schema with a subset of paths', function() {
const Test = new Archetype({
str: 'string',
Expand Down

0 comments on commit 0cfc96f

Please sign in to comment.