🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Sign inDemoInstall
Socket

@commercial/hoek

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@commercial/hoek - npm Package Compare versions

Comparing version

to
9.0.4

58

lib/applyToDefaults.js

@@ -6,3 +6,3 @@ 'use strict';

const Merge = require('./merge');
const Utils = require('./utils');
const Reach = require('./reach');

@@ -43,15 +43,55 @@

options = Object.assign({}, options);
options.shallow = false;
const seen = new Map();
const merge = source === true ? null : new Set();
const copy = Clone(defaults, { shallow: keys });
for (let key of keys) {
key = Array.isArray(key) ? key : key.split('.'); // Pre-split optimization
if (source === true) { // If source is set to true, use defaults
const ref = Reach(defaults, key);
if (ref &&
typeof ref === 'object') {
seen.set(ref, merge && Reach(source, key) || ref);
}
else if (merge) {
merge.add(key);
}
}
const copy = Clone(defaults, {}, seen);
if (!merge) {
return copy;
}
const storage = Utils.store(source, keys); // Move shallow copy items to storage
Merge(copy, source, { mergeArrays: false, nullOverride: false }); // Deep copy the rest
Utils.restore(copy, source, storage); // Shallow copy the stored items and restore
return copy;
for (const key of merge) {
internals.reachCopy(copy, source, key);
}
return Merge(copy, source, { mergeArrays: false, nullOverride: false });
};
internals.reachCopy = function (dst, src, path) {
for (const segment of path) {
if (!(segment in src)) {
return;
}
src = src[segment];
}
const value = src;
let ref = dst;
for (let i = 0; i < path.length - 1; ++i) {
const segment = path[i];
if (typeof ref[segment] !== 'object') {
ref[segment] = {};
}
ref = ref[segment];
}
ref[path[path.length - 1]] = value;
};

39

lib/clone.js
'use strict';
const Reach = require('./reach');
const Types = require('./types');

@@ -30,5 +31,3 @@ const Utils = require('./utils');

}
else {
seen = seen || new Map();
else if (seen) {
const lookup = seen.get(obj);

@@ -39,2 +38,5 @@ if (lookup) {

}
else {
seen = new Map();
}

@@ -125,6 +127,14 @@ // Built-in object types

const storage = Utils.store(source, keys); // Move shallow copy items to storage
const copy = internals.clone(source, options); // Deep copy the rest
Utils.restore(copy, source, storage); // Shallow copy the stored items and restore
return copy;
const seen = new Map();
for (const key of keys) {
const ref = Reach(source, key);
if (typeof ref === 'object' ||
typeof ref === 'function') {
seen.set(ref, ref);
}
}
return internals.clone(source, options, seen);
};

@@ -135,6 +145,2 @@

if (baseProto === Types.array) {
return [];
}
if (options.prototype === false) { // Defaults to true

@@ -145,3 +151,3 @@ if (internals.needsProtoHack.has(baseProto)) {

return {};
return baseProto === Types.array ? [] : {};
}

@@ -156,2 +162,11 @@

if (baseProto === Types.array) {
const newObj = [];
if (proto !== baseProto) {
Object.setPrototypeOf(newObj, proto);
}
return newObj;
}
if (internals.needsProtoHack.has(baseProto)) {

@@ -158,0 +173,0 @@ const newObj = new proto.constructor();

@@ -111,2 +111,4 @@ 'use strict';

else {
compare = compare || internals.compare(options);
for (const [key, existing] of map.entries()) {

@@ -113,0 +115,0 @@ if (compare(key, item)) {

@@ -48,2 +48,6 @@ 'use strict';

if (target[key] === value) {
continue; // Can occur for shallow merges
}
if (!target[key] ||

@@ -50,0 +54,0 @@ typeof target[key] !== 'object' ||

'use strict';
const Reach = require('./reach');
const internals = {};

@@ -13,43 +10,1 @@

};
exports.store = function (source, keys) {
const storage = new Map();
for (let i = 0; i < keys.length; ++i) {
const key = keys[i];
const value = Reach(source, key);
if (typeof value === 'object' ||
typeof value === 'function') {
storage.set(key, value);
internals.reachSet(source, key, undefined);
}
}
return storage;
};
exports.restore = function (copy, source, storage) {
for (const [key, value] of storage) {
internals.reachSet(copy, key, value);
internals.reachSet(source, key, value);
}
};
internals.reachSet = function (obj, key, value) {
const path = Array.isArray(key) ? key : key.split('.');
let ref = obj;
for (let i = 0; i < path.length; ++i) {
const segment = path[i];
if (i + 1 === path.length) {
ref[segment] = value;
}
ref = ref[segment];
}
};

@@ -5,4 +5,4 @@ COMMERCIAL LICENSE

This package requires a commercial license. You may not use, copy, or distribute it without first acquiring a commercial license from Sideway Inc. Using this software without a license is a violation of US and international law. To obtain a license, please contact sales@sideway.com.
This package requires a commercial license. You may not use, copy, or distribute it without first acquiring a commercial license from Sideway Inc. Using this software without a license is a violation of US and international law. To obtain a license, please contact [sales@sideway.com](mailto:sales@sideway.com).
This package contains code previously published under an open source license. You can find the previous materials and the terms under which they were originally published at: https://github.com/hapijs/hoek/blob/master/LICENSE.
This package contains code previously published under an open source license. You can find the previous materials and the terms under which they were originally published at: [https://github.com/hapijs/catbox-memory/blob/master/LICENSE](https://github.com/hapijs/hoek/master/LICENSE).
{
"name": "@commercial/hoek",
"description": "General purpose node utilities",
"version": "8.5.1",
"version": "9.0.4",
"repository": "git://github.com/hapijs/hoek",
"engines": {
"node": ">=12.0.0"
},
"main": "lib/index.js",

@@ -16,4 +19,4 @@ "types": "lib/index.d.ts",

"devDependencies": {
"@hapi/code": "6.x.x",
"@hapi/lab": "20.x.x"
"@hapi/code": "8.x.x",
"@hapi/lab": "22.x.x"
},

@@ -20,0 +23,0 @@ "scripts": {

@@ -1,5 +0,3 @@

<a href="https://hapi.dev"><img src="https://raw.githubusercontent.com/hapijs/assets/master/images/family.png" width="180px" align="right" /></a>
# @commercial/hoek
# @hapi/hoek
#### Utility methods for the hapi ecosystem.

@@ -17,3 +15,4 @@

- [Version status](https://hapi.dev/resources/status/#hoek) (builds, dependencies, node versions, licenses, eol)
- [Changelog](https://hapi.dev/family/hoek/changelog/)
- [Project policies](https://hapi.dev/policies/)
- [Free and commercial support options](https://hapi.dev/support/)