Skip to content

Commit

Permalink
merge with remote
Browse files Browse the repository at this point in the history
  • Loading branch information
jquense committed Nov 8, 2015
1 parent 5d65038 commit a41f4c1
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 10 deletions.
11 changes: 7 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "yup",
"version": "0.10.0",
"version": "0.10.1",
"description": "Dead simple Object schema validation",
"main": "lib/index.js",
"scripts": {
Expand All @@ -21,25 +21,28 @@
"homepage": "https://github.com/jquense/yup",
"devDependencies": {
"babel": "^5.8.23",
"babel-eslint": "^4.1.4",
"babel-loader": "^5.3.2",
"babel-plugin-external-helpers": "^1.1.1",
"chai": "^1.9.1",
"chai-as-promised": "^4.1.1",
"karma": "^0.12.2",
"eslint": "^0.24.1",
"karma": "^0.13.14",
"karma-chrome-launcher": "^0.2.0",
"karma-jsdom-launcher": "^1.0.0",
"karma-mocha": "^0.2.0",
"karma-mocha-reporter": "^1.0.2",
"karma-phantomjs-launcher": "^0.2.0",
"karma-sourcemap-loader": "^0.3.5",
"karma-webpack": "^1.6.0",
"karma-webpack": "^1.7.0",
"mocha": "^1.21.4",
"mt-changelog": "^0.6.2",
"node-libs-browser": "^0.5.2",
"phantomjs": "^1.9.17",
"release-script": "^0.5.2",
"sinon": "^1.10.3",
"sinon-chai": "^2.5.0",
"webpack": "^1.10.1"
"webpack": "^1.12.2"
},
"dependencies": {
"case": "^1.2.1",
Expand Down
14 changes: 9 additions & 5 deletions src/object.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,13 +178,17 @@ inherits(ObjectSchema, MixedSchema, {

from(from, to, alias) {
return this.transform( obj => {
if ( obj == null)
var newObj = obj;

if (obj == null)
return obj

var newObj = transform(obj, (o, val, key) => key !== from && (o[key] = val), {})
if (has(obj, from)) {
newObj = transform(obj, (o, val, key) => key !== from && (o[key] = val), {})
newObj[to] = obj[from]

newObj[to] = obj[from]
if(alias) newObj[from] = obj[from]
if(alias) newObj[from] = obj[from]
}

return newObj
})
Expand Down Expand Up @@ -248,4 +252,4 @@ function sortFields(fields, excludes = []){
}

return toposort.array(nodes, edges).reverse()
}
}
15 changes: 14 additions & 1 deletion test/object.js
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,19 @@ describe('Object types', function(){
.should.eql({ myProp: 5, other: 6, Other: 6 })
})

it('should not move keys when it does not exist', function(){
var inst = object().shape({
myProp: mixed(),
})
.from('prop', 'myProp')

inst.cast({ myProp: 5 })
.should.eql({ myProp: 5 })

inst.cast({ myProp: 5, prop: 7 })
.should.eql({ myProp: 7 })
})

it('should handle conditionals', function(){
var inst = object().shape({
noteDate: number()
Expand Down Expand Up @@ -415,4 +428,4 @@ describe('Object types', function(){
})


})
})

0 comments on commit a41f4c1

Please sign in to comment.