Skip to content

Commit 7bc01e0

Browse files
committed
[added] deep path support for from
1 parent f0d3c94 commit 7bc01e0

File tree

3 files changed

+120
-96
lines changed

3 files changed

+120
-96
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@
6565
"dependencies": {
6666
"case": "^1.2.1",
6767
"fn-name": "~1.0.1",
68-
"lodash": "^4.13.1",
68+
"lodash": "^4.17.0",
6969
"property-expr": "^1.2.0",
7070
"toposort": "^0.2.10",
7171
"type-name": "^2.0.1",

src/object.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import snakeCase from 'lodash/snakeCase';
44
import camelCase from 'lodash/camelCase';
55
import mapKeys from 'lodash/mapKeys';
66
import transform from 'lodash/transform';
7+
import { getter } from 'property-expr';
78

89
import MixedSchema from './mixed';
910
import { object as locale } from './locale.js';
@@ -192,18 +193,17 @@ inherits(ObjectSchema, MixedSchema, {
192193
},
193194

194195
from(from, to, alias) {
196+
let fromGetter = getter(from, true);
197+
195198
return this.transform(obj => {
196199
var newObj = obj;
197200

198201
if (obj == null)
199202
return obj
200203

201204
if (has(obj, from)) {
202-
newObj = omit(obj, from);
203-
newObj[to] = obj[from]
204-
205-
if (alias)
206-
newObj[from] = obj[from]
205+
newObj = alias ? { ...obj } : omit(obj, from);
206+
newObj[to] = fromGetter(obj)
207207
}
208208

209209
return newObj

0 commit comments

Comments
 (0)