Socket
Socket
Sign inDemoInstall

hoek

Package Overview
Dependencies
0
Maintainers
5
Versions
116
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 5.0.4 to 6.0.0

lib/deep-equal.js

57

lib/escape.js

@@ -8,26 +8,2 @@ 'use strict';

exports.escapeJavaScript = function (input) {
if (!input) {
return '';
}
let escaped = '';
for (let i = 0; i < input.length; ++i) {
const charCode = input.charCodeAt(i);
if (internals.isSafe(charCode)) {
escaped += input[i];
}
else {
escaped += internals.escapeJavaScriptChar(charCode);
}
}
return escaped;
};
exports.escapeHtml = function (input) {

@@ -77,11 +53,15 @@

}
else if (charCode === greaterThan) {
if (charCode === greaterThan) {
return '\\u003e';
}
else if (charCode === andSymbol) {
if (charCode === andSymbol) {
return '\\u0026';
}
else if (charCode === lineSeperator) {
if (charCode === lineSeperator) {
return '\\u2028';
}
return '\\u2029';

@@ -92,13 +72,2 @@ });

internals.escapeJavaScriptChar = function (charCode) {
if (charCode >= 256) {
return '\\u' + internals.padLeft('' + charCode, 4);
}
const hexValue = Buffer.from(String.fromCharCode(charCode), 'ascii').toString('hex');
return '\\x' + internals.padLeft(hexValue, 2);
};
internals.escapeHtmlChar = function (charCode) {

@@ -116,16 +85,6 @@

const hexValue = Buffer.from(String.fromCharCode(charCode), 'ascii').toString('hex');
return '&#x' + internals.padLeft(hexValue, 2) + ';';
return `&#x${hexValue};`;
};
internals.padLeft = function (str, len) {
while (str.length < len) {
str = '0' + str;
}
return str;
};
internals.isSafe = function (charCode) {

@@ -132,0 +91,0 @@

@@ -8,3 +8,2 @@ 'use strict';

const Path = require('path');
const Util = require('util');

@@ -263,190 +262,45 @@ const Escape = require('./escape');

exports.deepEqual = function (obj, ref, options, seen) {
exports.deepEqual = require('./deep-equal');
if (obj === ref) { // Copied from Deep-eql, copyright(c) 2013 Jake Luer, jake@alogicalparadox.com, MIT Licensed, https://github.com/chaijs/deep-eql
return obj !== 0 || 1 / obj === 1 / ref; // -0 / +0
}
options = options || { prototype: true };
// Find the common unique items in two arrays
const type = typeof obj;
exports.intersect = function (array1, array2, justFirst) {
if (type !== typeof ref) {
return false;
}
if (!array1 ||
!array2) {
if (type !== 'object' ||
obj === null ||
ref === null) {
return obj !== obj && ref !== ref; // NaN
return (justFirst ? null : []);
}
seen = seen || [];
if (seen.indexOf(obj) !== -1) {
return true; // If previous comparison failed, it would have stopped execution
}
const common = [];
const hash = (Array.isArray(array1) ? new Set(array1) : array1);
const found = new Set();
for (const value of array2) {
if (internals.has(hash, value) &&
!found.has(value)) {
seen.push(obj);
if (Array.isArray(obj)) {
if (!Array.isArray(ref)) {
return false;
}
if (!options.part && obj.length !== ref.length) {
return false;
}
for (let i = 0; i < obj.length; ++i) {
if (options.part) {
let found = false;
for (let j = 0; j < ref.length; ++j) {
if (exports.deepEqual(obj[i], ref[j], options)) {
found = true;
break;
}
}
return found;
if (justFirst) {
return value;
}
if (!exports.deepEqual(obj[i], ref[i], options)) {
return false;
}
common.push(value);
found.add(value);
}
return true;
}
if (Buffer.isBuffer(obj)) {
if (!Buffer.isBuffer(ref)) {
return false;
}
if (obj.length !== ref.length) {
return false;
}
for (let i = 0; i < obj.length; ++i) {
if (obj[i] !== ref[i]) {
return false;
}
}
return true;
}
if (obj instanceof Date) {
return (ref instanceof Date && obj.getTime() === ref.getTime());
}
if (obj instanceof RegExp) {
return (ref instanceof RegExp && obj.toString() === ref.toString());
}
if (options.prototype) {
if (Object.getPrototypeOf(obj) !== Object.getPrototypeOf(ref)) {
return false;
}
}
const keys = Object.getOwnPropertyNames(obj);
if (!options.part && keys.length !== Object.getOwnPropertyNames(ref).length) {
return false;
}
for (let i = 0; i < keys.length; ++i) {
const key = keys[i];
const descriptor = Object.getOwnPropertyDescriptor(obj, key);
if (descriptor.get) {
if (!exports.deepEqual(descriptor, Object.getOwnPropertyDescriptor(ref, key), options, seen)) {
return false;
}
}
else if (!exports.deepEqual(obj[key], ref[key], options, seen)) {
return false;
}
}
return true;
return (justFirst ? null : common);
};
// Remove duplicate items from array
internals.has = function (ref, key) {
exports.unique = (array, key) => {
let result;
if (key) {
result = [];
const index = new Set();
array.forEach((item) => {
const identifier = item[key];
if (!index.has(identifier)) {
index.add(identifier);
result.push(item);
}
});
if (typeof ref.has === 'function') {
return ref.has(key);
}
else {
result = Array.from(new Set(array));
}
return result;
return ref[key] !== undefined;
};
// Convert array into object
exports.mapToObject = function (array, key) {
if (!array) {
return null;
}
const obj = {};
for (let i = 0; i < array.length; ++i) {
if (key) {
if (array[i][key]) {
obj[array[i][key]] = true;
}
}
else {
obj[array[i]] = true;
}
}
return obj;
};
// Find the common unique items in two arrays
exports.intersect = function (array1, array2, justFirst) {
if (!array1 || !array2) {
return [];
}
const common = [];
const hash = (Array.isArray(array1) ? exports.mapToObject(array1) : array1);
const found = {};
for (let i = 0; i < array2.length; ++i) {
if (hash[array2[i]] && !found[array2[i]]) {
if (justFirst) {
return array2[i];
}
common.push(array2[i]);
found[array2[i]] = true;
}
}
return (justFirst ? null : common);
};
// Test if the reference contains the values

@@ -648,75 +502,2 @@

exports.formatStack = function (stack) {
const trace = [];
for (let i = 0; i < stack.length; ++i) {
const item = stack[i];
trace.push([item.getFileName(), item.getLineNumber(), item.getColumnNumber(), item.getFunctionName(), item.isConstructor()]);
}
return trace;
};
exports.formatTrace = function (trace) {
const display = [];
for (let i = 0; i < trace.length; ++i) {
const row = trace[i];
display.push((row[4] ? 'new ' : '') + row[3] + ' (' + row[0] + ':' + row[1] + ':' + row[2] + ')');
}
return display;
};
exports.callStack = function (slice) {
// http://code.google.com/p/v8/wiki/JavaScriptStackTraceApi
const v8 = Error.prepareStackTrace;
Error.prepareStackTrace = function (_, stack) {
return stack;
};
const capture = {};
Error.captureStackTrace(capture, this);
const stack = capture.stack;
Error.prepareStackTrace = v8;
const trace = exports.formatStack(stack);
return trace.slice(1 + slice);
};
exports.displayStack = function (slice) {
const trace = exports.callStack(slice === undefined ? 1 : slice + 1);
return exports.formatTrace(trace);
};
exports.abortThrow = false;
exports.abort = function (message, hideStack) {
if (process.env.NODE_ENV === 'test' || exports.abortThrow === true) {
throw new Error(message || 'Unknown error');
}
let stack = '';
if (!hideStack) {
stack = exports.displayStack(1).join('\n\t');
}
console.log('ABORT: ' + message + '\n\t' + stack);
process.exit(1);
};
exports.assert = function (condition, ...args) {

@@ -784,31 +565,2 @@

// Base64url (RFC 4648) encode
exports.base64urlEncode = function (value, encoding) {
exports.assert(typeof value === 'string' || Buffer.isBuffer(value), 'value must be string or buffer');
const buf = (Buffer.isBuffer(value) ? value : Buffer.from(value, encoding || 'binary'));
return buf.toString('base64').replace(/\+/g, '-').replace(/\//g, '_').replace(/\=/g, '');
};
// Base64url (RFC 4648) decode
exports.base64urlDecode = function (value, encoding) {
if (typeof value !== 'string') {
throw new Error('Value not a string');
}
if (!/^[\w\-]*$/.test(value)) {
throw new Error('Invalid character');
}
const buf = Buffer.from(value, 'base64');
return (encoding === 'buffer' ? buf : buf.toString(encoding || 'binary'));
};
// Escape attribute value for use in HTTP header

@@ -832,8 +584,2 @@

exports.escapeJavaScript = function (string) {
return Escape.escapeJavaScript(string);
};
exports.escapeJson = function (string) {

@@ -856,3 +602,3 @@

once = true;
method.apply(null, args);
method(...args);
}

@@ -866,55 +612,5 @@ };

exports.isInteger = Number.isSafeInteger;
exports.ignore = function () { };
exports.inherits = Util.inherits;
exports.format = Util.format;
exports.transform = function (source, transform, options) {
exports.assert(source === null || source === undefined || typeof source === 'object' || Array.isArray(source), 'Invalid source object: must be null, undefined, an object, or an array');
const separator = (typeof options === 'object' && options !== null) ? (options.separator || '.') : '.';
if (Array.isArray(source)) {
const results = [];
for (let i = 0; i < source.length; ++i) {
results.push(exports.transform(source[i], transform, options));
}
return results;
}
const result = {};
const keys = Object.keys(transform);
for (let i = 0; i < keys.length; ++i) {
const key = keys[i];
const path = key.split(separator);
const sourcePath = transform[key];
exports.assert(typeof sourcePath === 'string', 'All mappings must be "." delineated strings');
let segment;
let res = result;
while (path.length > 1) {
segment = path.shift();
if (!res[segment]) {
res[segment] = {};
}
res = res[segment];
}
segment = path.shift();
res[segment] = exports.reach(source, sourcePath, options);
}
return result;
};
exports.uniqueFilename = function (path, extension) {

@@ -946,8 +642,2 @@

exports.shallow = function (source) {
return Object.assign({}, source);
};
exports.wait = function (timeout) {

@@ -954,0 +644,0 @@

{
"name": "hoek",
"description": "General purpose node utilities",
"version": "5.0.4",
"version": "6.0.0",
"repository": "git://github.com/hapijs/hoek",

@@ -11,3 +11,3 @@ "main": "lib/index.js",

"engines": {
"node": ">=8.9.0"
"node": ">=8.12.0"
},

@@ -17,3 +17,3 @@ "dependencies": {},

"code": "5.x.x",
"lab": "15.x.x"
"lab": "17.x.x"
},

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

![hoek Logo](https://raw.github.com/hapijs/hoek/master/images/hoek.png)
Utility methods for the hapi ecosystem. This module is not intended to solve every problem for everyone, but rather as a central place to store hapi-specific methods. If you're looking for a general purpose utility module, check out [lodash](https://github.com/lodash/lodash) or [underscore](https://github.com/jashkenas/underscore).
Utility methods for the hapi ecosystem. This module is not intended to solve every problem for
everyone, but rather as a central place to store hapi-specific methods. If you're looking for a
general purpose utility module, check out [lodash](https://github.com/lodash/lodash) or
[underscore](https://github.com/jashkenas/underscore).
[![Build Status](https://secure.travis-ci.org/hapijs/hoek.svg)](http://travis-ci.org/hapijs/hoek)
<a href="https://andyet.com"><img src="https://s3.amazonaws.com/static.andyet.com/images/%26yet-logo.svg" align="right" /></a>
Lead Maintainer: [Gil Pedersen](https://github.com/kanongil)
Lead Maintainer: [Nathan LaFreniere](https://github.com/nlf)
**hoek** is sponsored by [&yet](https://andyet.com)
## Usage
The *Hoek* library contains some common functions used within the hapi ecosystem. It comes with useful methods for Arrays (clone, merge, applyToDefaults), Objects (removeKeys, copy), Asserting and more.
For example, to use Hoek to set configuration with default options:
```javascript
const Hoek = require('hoek');
const default = {url : "www.github.com", port : "8000", debug : true};
const config = Hoek.applyToDefaults(default, {port : "3000", admin : true});
// In this case, config would be { url: 'www.github.com', port: '3000', debug: true, admin: true }
```
## Documentation
[**API Reference**](API.md)

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc