Skip to content
This repository has been archived by the owner on Aug 26, 2022. It is now read-only.

Commit

Permalink
[added] deep path support for from
Browse files Browse the repository at this point in the history
  • Loading branch information
jquense committed Jan 18, 2017
1 parent f0d3c94 commit 7bc01e0
Show file tree
Hide file tree
Showing 3 changed files with 120 additions and 96 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
"dependencies": {
"case": "^1.2.1",
"fn-name": "~1.0.1",
"lodash": "^4.13.1",
"lodash": "^4.17.0",
"property-expr": "^1.2.0",
"toposort": "^0.2.10",
"type-name": "^2.0.1",
Expand Down
10 changes: 5 additions & 5 deletions src/object.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import snakeCase from 'lodash/snakeCase';
import camelCase from 'lodash/camelCase';
import mapKeys from 'lodash/mapKeys';
import transform from 'lodash/transform';
import { getter } from 'property-expr';

import MixedSchema from './mixed';
import { object as locale } from './locale.js';
Expand Down Expand Up @@ -192,18 +193,17 @@ inherits(ObjectSchema, MixedSchema, {
},

from(from, to, alias) {
let fromGetter = getter(from, true);

return this.transform(obj => {
var newObj = obj;

if (obj == null)
return obj

if (has(obj, from)) {
newObj = omit(obj, from);
newObj[to] = obj[from]

if (alias)
newObj[from] = obj[from]
newObj = alias ? { ...obj } : omit(obj, from);
newObj[to] = fromGetter(obj)
}

return newObj
Expand Down
Loading

0 comments on commit 7bc01e0

Please sign in to comment.