Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@stamp/core

Package Overview
Dependencies
Maintainers
2
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@stamp/core - npm Package Compare versions

Comparing version 0.1.0 to 0.1.1

__tests__/merge.js

7

assign.js

@@ -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')
};

@@ -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.
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc