Socket
Socket
Sign inDemoInstall

merge-anything

Package Overview
Dependencies
Maintainers
1
Versions
49
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

merge-anything - npm Package Compare versions

Comparing version 2.0.1 to 2.1.0

dist/index.esm.js

121

build/rollup.js
/* eslint-disable */
/* Required packages: */
// npm i -D \
// @babel/core \
// @babel/plugin-proposal-object-rest-spread \
// @babel/preset-env \
// rollup \
// rollup-plugin-babel@latest \
// rollup-plugin-commonjs \
// rollup-plugin-node-resolve \
// rollup-plugin-terser \
// is-what
/* Required .babelrc setup: */
// {
// "presets": [
// ["@babel/preset-env", {
// "modules": false
// }]
// ],
// "plugins": [
// "@babel/plugin-proposal-object-rest-spread"
// ]
// }
import babel from 'rollup-plugin-babel'
import commonjs from 'rollup-plugin-commonjs'
import { terser } from 'rollup-plugin-terser'
import { isArray } from 'is-what'
// npm install rollup-plugin-typescript2 typescript --save-dev
import typescript from 'rollup-plugin-typescript2'
// import { terser } from 'rollup-plugin-terser'
// import resolve from 'rollup-plugin-node-resolve'

@@ -36,6 +11,8 @@

// ------------------------------------------------------------------------------------------
// amd – Asynchronous Module Definition, used with module loaders like RequireJS
// cjs – CommonJS, suitable for Node and Browserify/Webpack
// es – Keep the bundle as an ES module file
// esm – Keep the bundle as an ES module file
// iife – A self-executing function, suitable for inclusion as a <script> tag. (If you want to create a bundle for your application, you probably want to use this, because it leads to smaller file sizes.)
// umd – Universal Module Definition, works as amd, cjs and iife all in one
// system – Native format of the SystemJS loader

@@ -45,14 +22,2 @@ // ------------------------------------------------------------------------------------------

// ------------------------------------------------------------------------------------------
const files = [
{in: 'src/index.js', out: 'dist', formats: ['cjs', 'es']},
]
const minify = false
const sourcemap = false
const plugins = [
babel({
exclude: 'node_modules/**' // only transpile our source code
}),
commonjs()
]
// ------------------------------------------------------------------------------------------
const pkg = require('../package.json')

@@ -62,2 +27,5 @@ const name = pkg.name

const external = Object.keys(pkg.dependencies || [])
const plugins = [
typescript({useTsconfigDeclarationDir: true}),
]

@@ -67,56 +35,27 @@ // ------------------------------------------------------------------------------------------

// ------------------------------------------------------------------------------------------
const nsNameExt = new RegExp('(.+)\/([^\/]+)\.([^\.]+$)', 'g')
function getNS (name) {
if (!name.includes('/')) return ''
return name.replace(nsNameExt, '$1')
}
function getName (name) {
if (!name.includes('/')) name = 'a/' + name
name = name.replace(nsNameExt, '$2')
if (name.endsWith('.')) name = name.slice(0, -1)
return name
}
function getExt (name) {
return name.split('.').pop()
}
function getFileInfo (file) {
return {
ns: getNS(file.in),
name: getName(file.in),
ext: getExt(file.in),
out: file.out,
formats: !isArray(file.formats) ? [file.formats] : file.formats,
plugins: (file.plugins === undefined) ? plugins : file.plugins,
min: (file.minify === undefined) ? minify : file.minify,
map: (file.sourcemap === undefined) ? sourcemap : file.sourcemap,
external: external,
function defaults (config) {
// defaults
const defaults = {
plugins,
external
}
}
function getRollupObject (info, format) {
return {
input: `${info.ns}/${info.name}.${info.ext}`,
output: {
// defaults.output
config.output = config.output.map(output => {
return Object.assign({
sourcemap: false,
name: className,
sourcemap: info.map,
exports: 'named',
file: (!info.min)
? `${info.out}/${info.name}.${format}.${info.ext}`
: `${info.out}/${info.name}.${format}.min.${info.ext}`,
format
},
plugins: (!info.min) ? plugins : plugins.concat(terser()),
external: info.external
}
}, output)
})
return Object.assign(defaults, config)
}
const builds = files.reduce((carry, file) => {
const info = getFileInfo(file)
const _builds = info.formats
.reduce((carry, format) => {
return carry
.concat(getRollupObject(info, format))
}, [])
return carry.concat(_builds)
}, [])
export default builds
export default [
defaults({
input: 'src/index.ts',
output: [
{file: 'dist/index.cjs.js', format: 'cjs'},
{file: 'dist/index.esm.js', format: 'esm'},
],
}),
]

@@ -8,74 +8,74 @@ 'use strict';

function mergeRecursively(origin, newComer, extensions) {
// work directly on newComer if its not an object
if (!isWhat.isObject(newComer)) {
// extend merge rules
if (extensions && isWhat.isArray(extensions)) {
extensions.forEach(function (extend) {
newComer = extend(origin, newComer);
});
// work directly on newComer if its not an object
if (!isWhat.isObject(newComer)) {
// extend merge rules
if (extensions && isWhat.isArray(extensions)) {
extensions.forEach(function (extend) {
newComer = extend(origin, newComer);
});
}
return newComer;
}
return newComer;
} // define newObject to merge all values upon
var newObject = isWhat.isObject(origin) ? Object.keys(origin).reduce(function (carry, key) {
var targetVal = origin[key];
if (!Object.keys(newComer).includes(key)) carry[key] = targetVal;
return carry;
}, {}) : {};
return Object.keys(newComer).reduce(function (carry, key) {
// re-define the origin and newComer as targetVal and newVal
var newVal = newComer[key];
var targetVal = isWhat.isObject(origin) ? origin[key] : undefined; // extend merge rules
if (extensions && isWhat.isArray(extensions)) {
extensions.forEach(function (extend) {
newVal = extend(targetVal, newVal);
});
} // early return when targetVal === undefined
if (targetVal === undefined) {
carry[key] = newVal;
return carry;
} // When newVal is an object do the merge recursively
if (isWhat.isObject(newVal)) {
carry[key] = mergeRecursively(targetVal, newVal, extensions);
return carry;
} // all the rest
carry[key] = newVal;
return carry;
}, newObject);
// define newObject to merge all values upon
var newObject = (isWhat.isObject(origin))
? Object.keys(origin)
.reduce(function (carry, key) {
var targetVal = origin[key];
// @ts-ignore
if (!Object.keys(newComer).includes(key))
carry[key] = targetVal;
return carry;
}, {})
: {};
return Object.keys(newComer)
.reduce(function (carry, key) {
// re-define the origin and newComer as targetVal and newVal
var newVal = newComer[key];
var targetVal = (isWhat.isObject(origin))
? origin[key]
: undefined;
// extend merge rules
if (extensions && isWhat.isArray(extensions)) {
extensions.forEach(function (extend) {
newVal = extend(targetVal, newVal);
});
}
// early return when targetVal === undefined
if (targetVal === undefined) {
carry[key] = newVal;
return carry;
}
// When newVal is an object do the merge recursively
if (isWhat.isObject(newVal)) {
carry[key] = mergeRecursively(targetVal, newVal, extensions);
return carry;
}
// all the rest
carry[key] = newVal;
return carry;
}, newObject);
}
/**
* Merge anything
* Merge anything recursively. objects get merged, basic types overwrite objects or other basic types.
*
* @param {object} origin the default values, OR {extensions} to pass an array of functions with extentions
* @param {object} newComer on which to set the default values
* @param {(config | any)} origin
* @param {...any[]} newComers
* @returns the result
*/
function index (origin) {
var extensions = null;
var base = origin;
if (origin['extensions'] && Object.keys(origin).length === 1) {
base = {};
extensions = origin.extensions;
}
for (var _len = arguments.length, newComers = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
newComers[_key - 1] = arguments[_key];
}
return newComers.reduce(function (result, newComer) {
return mergeRecursively(result, newComer, extensions);
}, base);
function merge(origin) {
var newComers = [];
for (var _i = 1; _i < arguments.length; _i++) {
newComers[_i - 1] = arguments[_i];
}
var extensions = null;
var base = origin;
if (isWhat.isObject(origin) && origin.extensions && Object.keys(origin).length === 1) {
base = {};
extensions = origin.extensions;
}
return newComers.reduce(function (result, newComer) {
return mergeRecursively(result, newComer, extensions);
}, base);
}
exports.default = index;
exports.default = merge;
{
"name": "merge-anything",
"version": "2.0.1",
"description": "Merge two objects recursively. A simple & small integration.",
"version": "2.1.0",
"description": "Merge objects & other types recursively. A simple & small integration.",
"main": "dist/index.cjs.js",
"module": "dist/index.es.js",
"module": "dist/index.esm.js",
"typings": "types/index.d.ts",
"scripts": {

@@ -28,15 +29,10 @@ "test": "ava",

"devDependencies": {
"@babel/core": "^7.0.0",
"@babel/plugin-proposal-object-rest-spread": "^7.0.0",
"@babel/preset-env": "^7.0.0",
"ava": "1.0.0-beta.8",
"rollup": "^0.65.2",
"rollup-plugin-babel": "^4.0.3",
"rollup-plugin-commonjs": "^9.1.6",
"rollup-plugin-node-resolve": "^3.4.0",
"rollup-plugin-terser": "^2.0.2"
"rollup-plugin-typescript2": "^0.17.0",
"typescript": "^3.0.3"
},
"dependencies": {
"is-what": "^2.0.2"
"is-what": "^2.1.0"
}
}

@@ -7,3 +7,3 @@ # Merge anything 🥡

Merge two objects recursively. A simple & small integration.
Merge objects & other types recursively. A simple & small integration.

@@ -10,0 +10,0 @@ ## Motivation

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