New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

for-each-plus

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

for-each-plus - npm Package Compare versions

Comparing version 1.0.1 to 1.0.2

118

index.js

@@ -1,2 +0,72 @@

const { isArrayLike, getKeys } = require('@jonkemp/package-utils');
const shallowProperty = key => obj => obj == null ? void 0 : obj[key];
const MAX_ARRAY_INDEX = 2 ** 53 - 1;
const getLength = shallowProperty('length');
const isArrayLike = (collection) => {
const length = getLength(collection);
return typeof length == 'number' && length >= 0 && length <= MAX_ARRAY_INDEX;
};
const isFunction = obj => toString.call(obj) === '[object Function]';
const isObject = obj => {
const type = typeof obj;
return type === 'function' || type === 'object' && !!obj;
};
const isArguments = obj => toString.call(obj) === '[object Arguments]';
const identity = value => value;
const getKeys = (obj) => {
if (!isObject(obj)) return [];
return Object.keys(obj);
};
const isMatch = (object, attrs) => {
const keys = getKeys(attrs);
const {length} = keys;
if (object == null) return !length;
const obj = Object(object);
for (let i = 0; i < length; i++) {
const key = keys[i];
if (attrs[key] !== obj[key] || !(key in obj)) return false;
}
return true;
};
const matcher = attrs => {
attrs = Object.assign({}, attrs);
return obj => isMatch(obj, attrs);
};
const deepGet = (obj, path) => {
const { length } = path;
for (let i = 0; i < length; i++) {
if (obj == null) return void 0;
obj = obj[path[i]];
}
return length ? obj : void 0;
};
const property = path => {
if (!Array.isArray(path)) {
return shallowProperty(path);
}
return obj => deepGet(obj, path);
};
const optimizeCb = (func, context, argCount) => {

@@ -14,5 +84,41 @@ if (context === void 0) return func;

module.exports = (obj, iteratee, context) => {
iteratee = optimizeCb(iteratee, context);
if (isArrayLike(obj)) {
const baseIteratee = (value, context, argCount) => {
if (value == null) return identity;
if (isFunction(value)) return optimizeCb(value, context, argCount);
if (isObject(value) && !Array.isArray(value)) return matcher(value);
return property(value);
};
let iteratee;
const exportIteratee = iteratee = (value, context) => baseIteratee(value, context, Infinity);
const cb = (value, context, argCount) => {
if (iteratee !== exportIteratee) return iteratee(value, context);
return baseIteratee(value, context, argCount);
};
var lib = {
shallowProperty,
getLength,
isArrayLike,
isFunction,
isObject,
isArguments,
identity,
getKeys,
property,
matcher,
isMatch,
optimizeCb,
cb
};
const { getKeys: getKeys$1, isArrayLike: isArrayLike$1, optimizeCb: optimizeCb$1 } = lib;
var forEach = (obj, iteratee, context) => {
iteratee = optimizeCb$1(iteratee, context);
if (isArrayLike$1(obj)) {
let i = 0;

@@ -24,3 +130,3 @@

} else {
const keys = getKeys(obj);
const keys = getKeys$1(obj);

@@ -34,1 +140,3 @@ for (const key of keys) {

};
module.exports = forEach;

12

package.json
{
"name": "for-each-plus",
"version": "1.0.1",
"version": "1.0.2",
"description": "A better forEach.",

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

"lint:fix": "eslint . --fix --max-warnings 0",
"test": "mocha"
"test": "npm run build && karma start --single-run --browsers ChromeHeadless karma.conf.js"
},

@@ -41,9 +41,11 @@ "files": [

"babel-eslint": "^10.1.0",
"chai": "^4.2.0",
"eslint": "^6.8.0",
"karma": "^4.4.1",
"karma-chai": "^0.1.0",
"karma-chrome-launcher": "^3.1.0",
"karma-mocha": "^1.3.0",
"mocha": "^7.1.1",
"rollup": "^2.1.0"
},
"dependencies": {
"@jonkemp/package-utils": "^1.0.0"
}
}

@@ -10,3 +10,5 @@ (function (global, factory) {

const MAX_ARRAY_INDEX = 2 ** 53 - 1;
const getLength = shallowProperty('length');
const isArrayLike = (collection) => {

@@ -18,2 +20,4 @@ const length = getLength(collection);

const isFunction = obj => toString.call(obj) === '[object Function]';
const isObject = obj => {

@@ -25,2 +29,6 @@ const type = typeof obj;

const isArguments = obj => toString.call(obj) === '[object Arguments]';
const identity = value => value;
const getKeys = (obj) => {

@@ -32,4 +40,2 @@ if (!isObject(obj)) return [];

const isFunction = obj => toString.call(obj) === '[object Function]';
const isMatch = (object, attrs) => {

@@ -51,6 +57,10 @@ const keys = getKeys(attrs);

const identity = value => value;
const matcher = attrs => {
attrs = Object.assign({}, attrs);
return obj => isMatch(obj, attrs);
};
const deepGet = (obj, path) => {
const {length} = path;
const { length } = path;

@@ -85,8 +95,2 @@ for (let i = 0; i < length; i++) {

const matcher = attrs => {
attrs = Object.assign({}, attrs);
return obj => isMatch(obj, attrs);
};
const baseIteratee = (value, context, argCount) => {

@@ -111,69 +115,22 @@ if (value == null) return identity;

var lib = {
shallowProperty,
getLength,
isArrayLike,
isFunction,
isObject,
isArguments,
identity,
getKeys,
property,
matcher,
isMatch,
optimizeCb,
cb
};
const { cb: cb$1, isArrayLike: isArrayLike$1, getKeys: getKeys$1 } = lib;
const { getKeys: getKeys$1, isArrayLike: isArrayLike$1, optimizeCb: optimizeCb$1 } = lib;
var mapPlus = (obj, iteratee, context) => {
iteratee = cb$1(iteratee, context);
const keys = !isArrayLike$1(obj) && getKeys$1(obj);
const {length} = keys || obj;
const results = Array(length);
for (let index = 0; index < length; index++) {
const currentKey = keys ? keys[index] : index;
results[index] = iteratee(obj[currentKey], currentKey, obj);
}
return results;
};
const shallowProperty$1 = key => obj => obj == null ? void 0 : obj[key];
const MAX_ARRAY_INDEX$1 = 2 ** 53 - 1;
const getLength$1 = shallowProperty$1('length');
const isArrayLike$2 = (collection) => {
const length = getLength$1(collection);
return typeof length == 'number' && length >= 0 && length <= MAX_ARRAY_INDEX$1;
};
const isObject$1 = obj => {
const type = typeof obj;
return type === 'function' || type === 'object' && !!obj;
};
const getKeys$2 = (obj) => {
if (!isObject$1(obj)) return [];
return Object.keys(obj);
};
const optimizeCb$1 = (func, context, argCount) => {
if (context === void 0) return func;
switch (argCount == null ? 3 : argCount) {
case 1: return value => func.call(context, value);
// The 2-argument case is omitted because we’re not using it.
case 3: return (value, index, collection) => func.call(context, value, index, collection);
case 4: return (accumulator, value, index, collection) => func.call(context, accumulator, value, index, collection);
}
return (...args) => func.apply(context, args);
};
var lib$1 = {
isArrayLike: isArrayLike$2,
getKeys: getKeys$2,
optimizeCb: optimizeCb$1
};
const { optimizeCb: optimizeCb$2, isArrayLike: isArrayLike$3, getKeys: getKeys$3 } = lib$1;
var forEachPlus = (obj, iteratee, context) => {
iteratee = optimizeCb$2(iteratee, context);
if (isArrayLike$3(obj)) {
var forEach = (obj, iteratee, context) => {
iteratee = optimizeCb$1(iteratee, context);
if (isArrayLike$1(obj)) {
let i = 0;

@@ -185,3 +142,3 @@

} else {
const keys = getKeys$3(obj);
const keys = getKeys$1(obj);

@@ -196,295 +153,6 @@ for (const key of keys) {

const shallowProperty$2 = key => obj => obj == null ? void 0 : obj[key];
var forEachPlus = forEach;
const MAX_ARRAY_INDEX$2 = 2 ** 53 - 1;
return forEachPlus;
const getLength$2 = shallowProperty$2('length');
const isArrayLike$4 = (collection) => {
const length = getLength$2(collection);
return typeof length == 'number' && length >= 0 && length <= MAX_ARRAY_INDEX$2;
};
const isFunction$1 = obj => toString.call(obj) === '[object Function]';
const isNumber = obj => toString.call(obj) === '[object Number]';
const isArguments = obj => toString.call(obj) === '[object Arguments]';
const isString = obj => toString.call(obj) === '[object String]';
const isObject$2 = obj => {
const type = typeof obj;
return type === 'function' || type === 'object' && !!obj;
};
const getKeys$4 = (obj) => {
if (!isObject$2(obj)) return [];
return Object.keys(obj);
};
const isMatch$1 = (object, attrs) => {
const keys = getKeys$4(attrs);
const {length} = keys;
if (object == null) return !length;
const obj = Object(object);
for (let i = 0; i < length; i++) {
const key = keys[i];
if (attrs[key] !== obj[key] || !(key in obj)) return false;
}
return true;
};
const has = (obj, path) => obj != null && Object.prototype.hasOwnProperty.call(obj, path);
const hasProperty = (obj, path) => {
if (!Array.isArray(path)) {
return has(obj, path);
}
const { length } = path;
for (let i = 0; i < length; i++) {
const key = path[i];
if (obj == null || !Object.prototype.hasOwnProperty.call(obj, key)) {
return false;
}
obj = obj[key];
}
return !!length;
};
const identity$1 = value => value;
const constant = value => () => value;
const keyInObj = (value, key, obj) => key in obj;
const allKeys = obj => {
if (!isObject$2(obj)) return [];
const keys = [];
for (const key in obj) keys.push(key);
return keys;
};
const values = (obj) => {
const keys = getKeys$4(obj);
const { length } = keys;
const values = Array(length);
for (let i = 0; i < length; i++) {
values[i] = obj[keys[i]];
}
return values;
};
const toPairs = (obj) => {
const keys = getKeys$4(obj);
const pairs = [];
for (const key of keys) {
pairs.push([key, obj[key]]);
}
return pairs;
};
const optimizeCb$3 = (func, context, argCount) => {
if (context === void 0) return func;
switch (argCount == null ? 3 : argCount) {
case 1: return value => func.call(context, value);
// The 2-argument case is omitted because we’re not using it.
case 3: return (value, index, collection) => func.call(context, value, index, collection);
case 4: return (accumulator, value, index, collection) => func.call(context, accumulator, value, index, collection);
}
return (...args) => func.apply(context, args);
};
const matcher$1 = attrs => {
attrs = Object.assign({}, attrs);
return obj => isMatch$1(obj, attrs);
};
const deepGet$1 = (obj, path) => {
const { length } = path;
for (let i = 0; i < length; i++) {
if (obj == null) return void 0;
obj = obj[path[i]];
}
return length ? obj : void 0;
};
const property$1 = path => {
if (!Array.isArray(path)) {
return shallowProperty$2(path);
}
return obj => deepGet$1(obj, path);
};
const baseIteratee$1 = (value, context, argCount) => {
if (value == null) return identity$1;
if (isFunction$1(value)) return optimizeCb$3(value, context, argCount);
if (isObject$2(value) && !Array.isArray(value)) return matcher$1(value);
return property$1(value);
};
let iteratee$1;
const exportIteratee$1 = iteratee$1 = (value, context) => baseIteratee$1(value, context, Infinity);
const cb$2 = (value, context, argCount) => {
if (iteratee$1 !== exportIteratee$1) return iteratee$1(value, context);
return baseIteratee$1(value, context, argCount);
};
const noop = () => {};
const initial = (array, n, guard) => Array.prototype.slice.call(array, 0, Math.max(0, array.length - (n == null || guard ? 1 : n)));
const createPredicateIndexFinder = dir => (array, predicate, context) => {
predicate = cb$2(predicate, context);
const length = getLength$2(array);
let index = dir > 0 ? 0 : length - 1;
for (; index >= 0 && index < length; index += dir) {
if (predicate(array[index], index, array)) return index;
}
return -1;
};
const findIndex = createPredicateIndexFinder(1);
const findKey = (obj, predicate, context) => {
predicate = cb$2(predicate, context);
const keys = getKeys$4(obj);
let key;
for (let i = 0, { length } = keys; i < length; i++) {
key = keys[i];
if (predicate(obj[key], key, obj)) return key;
}
};
const find = (obj, predicate, context) => {
const keyFinder = isArrayLike$4(obj) ? findIndex : findKey;
const key = keyFinder(obj, predicate, context);
if (key !== void 0 && key !== -1) return obj[key];
};
const filter = (obj, predicate, context) => {
const results = [];
predicate = cb$2(predicate, context);
forEachPlus(obj, (value, index, list) => {
if (predicate(value, index, list)) results.push(value);
});
return results;
};
const reStrSymbol = /[^\ud800-\udfff]|[\ud800-\udbff][\udc00-\udfff]|[\ud800-\udfff]/g;
const toArray = (obj) => {
if (!obj) return [];
if (Array.isArray(obj)) return Array.prototype.slice.call(obj);
if (isString(obj)) {
// Keep surrogate pair characters together
return obj.match(reStrSymbol);
}
if (isArrayLike$4(obj)) return mapPlus(identity$1);
return values(obj);
};
const first = (array, n, guard) => {
if (array == null || array.length < 1) return n == null ? void 0 : [];
if (n == null || guard) return array[0];
return initial(array, array.length - n);
};
var packageUtils = {
getLength: getLength$2,
isArrayLike: isArrayLike$4,
isFunction: isFunction$1,
isNumber,
isArguments,
isString,
isObject: isObject$2,
getKeys: getKeys$4,
hasProperty,
property: property$1,
isMatch: isMatch$1,
matcher: matcher$1,
findKey,
identity: identity$1,
constant,
keyInObj,
allKeys,
values,
toPairs,
cb: cb$2,
noop,
find,
filter,
toArray,
first,
initial,
findIndex
};
const { isArrayLike: isArrayLike$5, getKeys: getKeys$5 } = packageUtils;
const optimizeCb$4 = (func, context, argCount) => {
if (context === void 0) return func;
switch (argCount == null ? 3 : argCount) {
case 1: return value => func.call(context, value);
// The 2-argument case is omitted because we’re not using it.
case 3: return (value, index, collection) => func.call(context, value, index, collection);
case 4: return (accumulator, value, index, collection) => func.call(context, accumulator, value, index, collection);
}
return (...args) => func.apply(context, args);
};
var forEachPlus$1 = (obj, iteratee, context) => {
iteratee = optimizeCb$4(iteratee, context);
if (isArrayLike$5(obj)) {
let i = 0;
for (const item of obj) {
iteratee(item, i++, obj);
}
} else {
const keys = getKeys$5(obj);
for (const key of keys) {
iteratee(obj[key], key, obj);
}
}
return obj;
};
return forEachPlus$1;
})));
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