deep-for-each
Advanced tools
Comparing version 2.0.3 to 3.0.0
@@ -5,2 +5,11 @@ # Change Log | ||
<a name="3.0.0"></a> | ||
# [3.0.0](https://github.com/moxystudio/js-deep-for-each/compare/v2.0.3...v3.0.0) (2019-03-13) | ||
### Features | ||
* offer cjs build ([b266efd](https://github.com/moxystudio/js-deep-for-each/commit/b266efd)) | ||
<a name="2.0.3"></a> | ||
@@ -7,0 +16,0 @@ ## [2.0.3](https://github.com/moxystudio/js-deep-for-each/compare/v2.0.2...v2.0.3) (2018-03-16) |
import isPlainObject from 'lodash.isplainobject'; | ||
function forEachObject(obj, fn, path) { | ||
for (var key in obj) { | ||
var deepPath = path ? path + '.' + key : key; | ||
for (const key in obj) { | ||
const deepPath = path ? `${path}.${key}` : key; // Note that we always use obj[key] because it might be mutated by forEach | ||
// Note that we always use obj[key] because it might be mutated by forEach | ||
fn.call(obj, obj[key], key, obj, deepPath); | ||
forEach(obj[key], fn, deepPath); | ||
} | ||
fn.call(obj, obj[key], key, obj, deepPath); | ||
forEach(obj[key], fn, deepPath); | ||
} | ||
} | ||
function forEachArray(array, fn, path) { | ||
array.forEach(function (value, index, arr) { | ||
var deepPath = path + '[' + index + ']'; | ||
array.forEach((value, index, arr) => { | ||
const deepPath = `${path}[${index}]`; | ||
fn.call(arr, value, index, arr, deepPath); // Note that we use arr[index] because it might be mutated by forEach | ||
fn.call(arr, value, index, arr, deepPath); | ||
// Note that we use arr[index] because it might be mutated by forEach | ||
forEach(arr[index], fn, deepPath); | ||
}); | ||
forEach(arr[index], fn, deepPath); | ||
}); | ||
} | ||
function forEach(value, fn, path) { | ||
path = path || ''; | ||
path = path || ''; | ||
if (Array.isArray(value)) { | ||
forEachArray(value, fn, path); | ||
} else if (isPlainObject(value)) { | ||
forEachObject(value, fn, path); | ||
} | ||
if (Array.isArray(value)) { | ||
forEachArray(value, fn, path); | ||
} else if (isPlainObject(value)) { | ||
forEachObject(value, fn, path); | ||
} | ||
} | ||
export default forEach; |
@@ -1,44 +0,42 @@ | ||
'use strict'; | ||
"use strict"; | ||
exports.__esModule = true; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.default = void 0; | ||
var _lodash = require('lodash.isplainobject'); | ||
var _lodash = _interopRequireDefault(require("lodash.isplainobject")); | ||
var _lodash2 = _interopRequireDefault(_lodash); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
function forEachObject(obj, fn, path) { | ||
for (var key in obj) { | ||
var deepPath = path ? path + '.' + key : key; | ||
for (const key in obj) { | ||
const deepPath = path ? `${path}.${key}` : key; // Note that we always use obj[key] because it might be mutated by forEach | ||
// Note that we always use obj[key] because it might be mutated by forEach | ||
fn.call(obj, obj[key], key, obj, deepPath); | ||
forEach(obj[key], fn, deepPath); | ||
} | ||
fn.call(obj, obj[key], key, obj, deepPath); | ||
forEach(obj[key], fn, deepPath); | ||
} | ||
} | ||
function forEachArray(array, fn, path) { | ||
array.forEach(function (value, index, arr) { | ||
var deepPath = path + '[' + index + ']'; | ||
array.forEach((value, index, arr) => { | ||
const deepPath = `${path}[${index}]`; | ||
fn.call(arr, value, index, arr, deepPath); // Note that we use arr[index] because it might be mutated by forEach | ||
fn.call(arr, value, index, arr, deepPath); | ||
// Note that we use arr[index] because it might be mutated by forEach | ||
forEach(arr[index], fn, deepPath); | ||
}); | ||
forEach(arr[index], fn, deepPath); | ||
}); | ||
} | ||
function forEach(value, fn, path) { | ||
path = path || ''; | ||
path = path || ''; | ||
if (Array.isArray(value)) { | ||
forEachArray(value, fn, path); | ||
} else if ((0, _lodash2.default)(value)) { | ||
forEachObject(value, fn, path); | ||
} | ||
if (Array.isArray(value)) { | ||
forEachArray(value, fn, path); | ||
} else if ((0, _lodash.default)(value)) { | ||
forEachObject(value, fn, path); | ||
} | ||
} | ||
exports.default = forEach; | ||
module.exports = exports['default']; | ||
var _default = forEach; | ||
exports.default = _default; | ||
module.exports = exports.default; |
{ | ||
"name": "deep-for-each", | ||
"version": "2.0.3", | ||
"version": "3.0.0", | ||
"description": "Recursively iterates over arrays and objects", | ||
@@ -32,12 +32,10 @@ "keywords": [ | ||
"build": "npm run build:commonjs && npm run build:es", | ||
"lint": "eslint .", | ||
"lint": "eslint --ignore-path .gitignore .", | ||
"test": "jest --env node --coverage", | ||
"prerelease": "npm t && npm run lint && npm run build", | ||
"release": "standard-version", | ||
"precommit": "lint-staged", | ||
"commitmsg": "commitlint -e $GIT_PARAMS" | ||
"release": "standard-version" | ||
}, | ||
"standard-version": { | ||
"scripts": { | ||
"posttag": "git push --follow-tags origin master && npm publish" | ||
"posttag": "git push --follow-tags origin master" | ||
} | ||
@@ -57,16 +55,24 @@ }, | ||
"devDependencies": { | ||
"@commitlint/cli": "^6.0.0", | ||
"@commitlint/config-conventional": "^6.0.2", | ||
"babel-cli": "^6.26.0", | ||
"babel-preset-moxy": "^2.1.0", | ||
"eslint": "^4.3.0", | ||
"eslint-config-moxy": "^5.0.0", | ||
"husky": "^0.14.3", | ||
"jest": "^22.0.0", | ||
"lint-staged": "^7.0.0", | ||
"standard-version": "^4.2.0" | ||
"@babel/cli": "^7.2.3", | ||
"@babel/core": "^7.3.4", | ||
"@commitlint/cli": "^7.5.2", | ||
"@commitlint/config-conventional": "^7.5.0", | ||
"babel-jest": "^24.5.0", | ||
"babel-preset-moxy": "^3.0.4", | ||
"eslint": "^5.15.1", | ||
"eslint-config-moxy": "^7.0.1", | ||
"husky": "^1.3.1", | ||
"jest": "^24.5.0", | ||
"lint-staged": "^8.1.5", | ||
"standard-version": "^5.0.1" | ||
}, | ||
"dependencies": { | ||
"lodash.isplainobject": "^4.0.6" | ||
}, | ||
"husky": { | ||
"hooks": { | ||
"commit-msg": "commitlint -E HUSKY_GIT_PARAMS", | ||
"pre-commit": "lint-staged" | ||
} | ||
} | ||
} |
# deep-for-each | ||
[![NPM version][npm-image]][npm-url] [![Downloads][downloads-image]][npm-url] [![Build Status][travis-image]][travis-url] [![Coverage Status][codecov-image]][codecov-url] [![Dependency status][david-dm-image]][david-dm-url] [![Dev Dependency status][david-dm-dev-image]][david-dm-dev-url] [![Greenkeeper badge][greenkeeper-image]][greenkeeper-url] | ||
[![NPM version][npm-image]][npm-url] [![Downloads][downloads-image]][npm-url] [![Build Status][travis-image]][travis-url] [![Coverage Status][codecov-image]][codecov-url] [![Dependency status][david-dm-image]][david-dm-url] [![Dev Dependency status][david-dm-dev-image]][david-dm-dev-url] | ||
@@ -16,4 +16,2 @@ [npm-url]:https://npmjs.org/package/deep-for-each | ||
[david-dm-dev-image]:https://img.shields.io/david/dev/moxystudio/js-deep-for-each.svg | ||
[greenkeeper-image]:https://badges.greenkeeper.io/moxystudio/js-deep-for-each.svg | ||
[greenkeeper-url]:https://greenkeeper.io/ | ||
@@ -25,5 +23,7 @@ Recursively iterates over arrays and objects. The iteration is made using a [deep-first](https://en.wikipedia.org/wiki/Depth-first_search) algorithm. | ||
`$ npm install deep-for-each` | ||
```sh | ||
$ npm install deep-for-each | ||
``` | ||
This library expects the host environment to be up-to-date or polyfilled with [core-js](https://github.com/zloirock/core-js) or similar. | ||
This library is written in modern JavaScript and is published in both CommonJS and ES module transpiled variants. If you target older browsers please make sure to transpile accordingly. | ||
@@ -72,4 +72,6 @@ | ||
`$ npm test` | ||
`$ npm test -- --watch` during development | ||
```sh | ||
$ npm test | ||
$ npm test -- --watch # during development | ||
``` | ||
@@ -76,0 +78,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
8449
79
12
54