@stamp/core
Advanced tools
Comparing version 0.1.0 to 0.1.1
@@ -1,6 +0,1 @@ | ||
import mergeFew from './mergeFew'; | ||
import slice from './slice'; | ||
export default function assign(dst) { | ||
return mergeFew(dst, slice.call(arguments, 1), true); | ||
} | ||
module.exports = Object.assign; |
@@ -1,4 +0,4 @@ | ||
export {assign} from './assign'; | ||
export {merge} from './merge'; | ||
export {slice} from './slice'; | ||
export {values} from './values'; | ||
module.exports = { | ||
assign: require('./assign'), | ||
merge: require('./merge') | ||
}; |
53
merge.js
@@ -1,6 +0,51 @@ | ||
import mergeFew from './mergeFew'; | ||
import slice from './slice'; | ||
var isPlainObject = require('@stamp/is/plain-object'); | ||
var isObject = require('@stamp/is/object'); | ||
var isArray = require('@stamp/is/array'); | ||
export default function merge(dst) { | ||
return mergeFew(dst, slice.call(arguments, 1), false); | ||
/** | ||
* The 'src' argument plays the command role. | ||
* The returned values is always of the same type as the 'src'. | ||
* @param dst The object to merge into | ||
* @param src The object to merge from | ||
* @returns {*} | ||
*/ | ||
function mergeOne(dst, src) { | ||
if (src === undefined) return dst; | ||
// According to specification arrays must be concatenated. | ||
// Also, the '.concat' creates a new array instance. Overrides the 'dst'. | ||
if (isArray(src)) return (isArray(dst) ? dst : []).concat(src); | ||
// Now deal with non plain 'src' object. 'src' overrides 'dst' | ||
// Note that functions are also assigned! We do not deep merge functions. | ||
if (!isPlainObject(src)) return src; | ||
// See if 'dst' is allowed to be mutated. | ||
// If not - it's overridden with a new plain object. | ||
var returnValue = isObject(dst) ? dst : {}; | ||
var keys = Object.keys(src); | ||
for (var i = 0; i < keys.length; i += 1) { | ||
var key = keys[i]; | ||
var srcValue = src[key]; | ||
// Do not merge properties with the 'undefined' value. | ||
if (srcValue !== undefined) { | ||
var dstValue = returnValue[key]; | ||
// Recursive calls to mergeOne() must allow only plain objects or arrays in dst | ||
var newDst = isPlainObject(dstValue) || isArray(srcValue) ? dstValue : {}; | ||
// deep merge each property. Recursion! | ||
returnValue[key] = mergeOne(newDst, srcValue); | ||
} | ||
} | ||
return returnValue; | ||
} | ||
module.exports = function (dst) { | ||
for (var i = 1; i < arguments.length; i++) { | ||
dst = mergeOne(dst, arguments[i]); | ||
} | ||
return dst; | ||
}; |
{ | ||
"name": "@stamp/core", | ||
"version": "0.1.0", | ||
"version": "0.1.1", | ||
"license": "MIT", | ||
"description": "Core functions for creating stamps", | ||
"repository": "https://github.com/stampit-org/stamp/packages/core", | ||
"repository": "https://github.com/stampit-org/stamp/tree/master/packages/core", | ||
"dependencies": { | ||
"@stamp/is": "^0.1.0" | ||
"@stamp/is": "^0.1.1" | ||
} | ||
} |
@@ -6,8 +6,5 @@ # @stamp/core | ||
```js | ||
import { | ||
assign, | ||
merge, | ||
slice, | ||
values, | ||
} from '@stamp/core'; | ||
const {assign, merge} = require('@stamp/core'); | ||
// or | ||
import {assign, merge} from '@stamp/core'; | ||
``` | ||
@@ -23,12 +20,6 @@ | ||
Mutates destination object by deeply merging passed source objects. Arrays are concatenated, not overwritten. Returns destination object. | ||
* Mutates destination object by deeply merging passed source objects. | ||
* Arrays are concatenated, not overwritten. | ||
* Everything else but plain objects are copied by reference. | ||
### slice(array) | ||
_`@stamp/core/slice`_ | ||
Common function found in `Array.prototype.slice`. | ||
### values(object) | ||
_`@stamp/core/values`_ | ||
Uses `Object.values` if available, otherwise own implementation with same functionality is used. | ||
Returns destination object/array or a new object/array in case it was not. |
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
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
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
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
10745
330
6
24
1
Updated@stamp/is@^0.1.1