react-addons-update
Advanced tools
Comparing version 15.5.0-rc.1 to 15.5.0-rc.2
199
index.js
@@ -1,1 +0,198 @@ | ||
module.exports = require('react/lib/update'); | ||
/** | ||
* Copyright 2013-present, Facebook, Inc. | ||
* All rights reserved. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. An additional grant | ||
* of patent rights can be found in the PATENTS file in the same directory. | ||
* | ||
* @providesModule update | ||
*/ | ||
/* global hasOwnProperty:true */ | ||
'use strict'; | ||
var NODE_ENV = process.env.NODE_ENV; | ||
var invariant = function(condition, format, a, b, c, d, e, f) { | ||
if (NODE_ENV !== 'production') { | ||
if (format === undefined) { | ||
throw new Error('invariant requires an error message argument'); | ||
} | ||
} | ||
if (!condition) { | ||
var error; | ||
if (format === undefined) { | ||
error = new Error( | ||
'Minified exception occurred; use the non-minified dev environment ' + | ||
'for the full error message and additional helpful warnings.' | ||
); | ||
} else { | ||
var args = [a, b, c, d, e, f]; | ||
var argIndex = 0; | ||
error = new Error( | ||
format.replace(/%s/g, function() { return args[argIndex++]; }) | ||
); | ||
error.name = 'Invariant Violation'; | ||
} | ||
error.framesToPop = 1; // we don't care about invariant's own frame | ||
throw error; | ||
} | ||
}; | ||
var hasOwnProperty = {}.hasOwnProperty; | ||
function shallowCopy(x) { | ||
if (Array.isArray(x)) { | ||
return x.concat(); | ||
} else if (x && typeof x === 'object') { | ||
return Object.assign(new x.constructor(), x); | ||
} else { | ||
return x; | ||
} | ||
} | ||
var COMMAND_PUSH = '$push'; | ||
var COMMAND_UNSHIFT = '$unshift'; | ||
var COMMAND_SPLICE = '$splice'; | ||
var COMMAND_SET = '$set'; | ||
var COMMAND_MERGE = '$merge'; | ||
var COMMAND_APPLY = '$apply'; | ||
var ALL_COMMANDS_LIST = [ | ||
COMMAND_PUSH, | ||
COMMAND_UNSHIFT, | ||
COMMAND_SPLICE, | ||
COMMAND_SET, | ||
COMMAND_MERGE, | ||
COMMAND_APPLY, | ||
]; | ||
var ALL_COMMANDS_SET = {}; | ||
ALL_COMMANDS_LIST.forEach(function(command) { | ||
ALL_COMMANDS_SET[command] = true; | ||
}); | ||
function invariantArrayCase(value, spec, command) { | ||
invariant( | ||
Array.isArray(value), | ||
'update(): expected target of %s to be an array; got %s.', | ||
command, | ||
value | ||
); | ||
var specValue = spec[command]; | ||
invariant( | ||
Array.isArray(specValue), | ||
'update(): expected spec of %s to be an array; got %s. ' + | ||
'Did you forget to wrap your parameter in an array?', | ||
command, | ||
specValue | ||
); | ||
} | ||
/** | ||
* Returns a updated shallow copy of an object without mutating the original. | ||
* See https://facebook.github.io/react/docs/update.html for details. | ||
*/ | ||
function update(value, spec) { | ||
invariant( | ||
typeof spec === 'object', | ||
'update(): You provided a key path to update() that did not contain one ' + | ||
'of %s. Did you forget to include {%s: ...}?', | ||
ALL_COMMANDS_LIST.join(', '), | ||
COMMAND_SET | ||
); | ||
if (hasOwnProperty.call(spec, COMMAND_SET)) { | ||
invariant( | ||
Object.keys(spec).length === 1, | ||
'Cannot have more than one key in an object with %s', | ||
COMMAND_SET | ||
); | ||
return spec[COMMAND_SET]; | ||
} | ||
var nextValue = shallowCopy(value); | ||
if (hasOwnProperty.call(spec, COMMAND_MERGE)) { | ||
var mergeObj = spec[COMMAND_MERGE]; | ||
invariant( | ||
mergeObj && typeof mergeObj === 'object', | ||
'update(): %s expects a spec of type \'object\'; got %s', | ||
COMMAND_MERGE, | ||
mergeObj | ||
); | ||
invariant( | ||
nextValue && typeof nextValue === 'object', | ||
'update(): %s expects a target of type \'object\'; got %s', | ||
COMMAND_MERGE, | ||
nextValue | ||
); | ||
Object.assign(nextValue, spec[COMMAND_MERGE]); | ||
} | ||
if (hasOwnProperty.call(spec, COMMAND_PUSH)) { | ||
invariantArrayCase(value, spec, COMMAND_PUSH); | ||
spec[COMMAND_PUSH].forEach(function(item) { | ||
nextValue.push(item); | ||
}); | ||
} | ||
if (hasOwnProperty.call(spec, COMMAND_UNSHIFT)) { | ||
invariantArrayCase(value, spec, COMMAND_UNSHIFT); | ||
spec[COMMAND_UNSHIFT].forEach(function(item) { | ||
nextValue.unshift(item); | ||
}); | ||
} | ||
if (hasOwnProperty.call(spec, COMMAND_SPLICE)) { | ||
invariant( | ||
Array.isArray(value), | ||
'Expected %s target to be an array; got %s', | ||
COMMAND_SPLICE, | ||
value | ||
); | ||
invariant( | ||
Array.isArray(spec[COMMAND_SPLICE]), | ||
'update(): expected spec of %s to be an array of arrays; got %s. ' + | ||
'Did you forget to wrap your parameters in an array?', | ||
COMMAND_SPLICE, | ||
spec[COMMAND_SPLICE] | ||
); | ||
spec[COMMAND_SPLICE].forEach(function(args) { | ||
invariant( | ||
Array.isArray(args), | ||
'update(): expected spec of %s to be an array of arrays; got %s. ' + | ||
'Did you forget to wrap your parameters in an array?', | ||
COMMAND_SPLICE, | ||
spec[COMMAND_SPLICE] | ||
); | ||
nextValue.splice.apply(nextValue, args); | ||
}); | ||
} | ||
if (hasOwnProperty.call(spec, COMMAND_APPLY)) { | ||
invariant( | ||
typeof spec[COMMAND_APPLY] === 'function', | ||
'update(): expected spec of %s to be a function; got %s.', | ||
COMMAND_APPLY, | ||
spec[COMMAND_APPLY] | ||
); | ||
nextValue = spec[COMMAND_APPLY](nextValue); | ||
} | ||
for (var k in spec) { | ||
if (!(ALL_COMMANDS_SET.hasOwnProperty(k) && ALL_COMMANDS_SET[k])) { | ||
nextValue[k] = update(value[k], spec[k]); | ||
} | ||
} | ||
return nextValue; | ||
} | ||
module.exports = update; |
{ | ||
"name": "react-addons-update", | ||
"version": "15.5.0-rc.1", | ||
"version": "15.5.0-rc.2", | ||
"main": "index.js", | ||
@@ -15,5 +15,8 @@ "repository": "facebook/react", | ||
}, | ||
"peerDependencies": { | ||
"react": "^15.5.0-rc.1" | ||
"devDependencies": { | ||
"jest": "^19.0.2" | ||
}, | ||
"scripts": { | ||
"test": "jest" | ||
}, | ||
"files": [ | ||
@@ -23,4 +26,6 @@ "LICENSE", | ||
"README.md", | ||
"index.js" | ||
"index.js", | ||
"react-addons-update.js", | ||
"react-addons-update.min.js" | ||
] | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
Unidentified License
License(Experimental) Something that seems like a license was found, but its contents could not be matched with a known license.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Empty package
Supply chain riskPackage does not contain any code. It may be removed, is name squatting, or the result of a faulty package publish.
Found 1 instance in 1 package
28392
2
7
571
1
1
80
3
7