Skip to content

Commit ffdaa83

Browse files
committed
chore: update project to use new tooling
BREAKING CHANGE: the UMD build was replaced by a cjs and es builds located in lib/ and es/ respectively
1 parent 2914265 commit ffdaa83

File tree

17 files changed

+8641
-452
lines changed

17 files changed

+8641
-452
lines changed

.babelrc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"presets": ["moxy"]
3+
}

.eslintignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
coverage/
2+
lib/
3+
es/

.eslintrc.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
{
22
"root": true,
33
"extends": [
4-
"@satazor/eslint-config/es5",
5-
"@satazor/eslint-config/addons/node"
4+
"eslint-config-moxy/es6",
5+
"eslint-config-moxy/addons/es6-modules",
6+
"eslint-config-moxy/addons/jest"
67
]
78
}

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
1-
node_modules
1+
node_modules/
22
npm-debug.*
3+
coverage/
4+
test/tmp/

.travis.yml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
language: node_js
22
node_js:
3-
- "0.12"
4-
- "4"
5-
- "5"
3+
- "node"
4+
- "lts/*"
5+
# Report coverage
6+
after_success:
7+
- "npm i codecov"
8+
- "node_modules/.bin/codecov"

LICENSE

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
1-
Copyright (c) 2015 IndigoUnited
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2018 Made With MOXY Lda <hello@moxy.studio>
24

35
Permission is hereby granted, free of charge, to any person obtaining a copy
46
of this software and associated documentation files (the "Software"), to deal
57
in the Software without restriction, including without limitation the rights
68
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7-
copies of the Software, and to permit persons to whom the Software is furnished
8-
to do so, subject to the following conditions:
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
911

10-
The above copyright notice and this permission notice shall be included in all
11-
copies or substantial portions of the Software.
12+
The above copyright notice and this permission notice shall be included in
13+
all copies or substantial portions of the Software.
1214

1315
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1416
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,

README.md

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,33 @@
11
# deep-for-each
22

3-
[![NPM version][npm-image]][npm-url] [![Downloads][downloads-image]][npm-url] [![Build Status][travis-image]][travis-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]
3+
[![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]
44

55
[npm-url]:https://npmjs.org/package/deep-for-each
66
[downloads-image]:http://img.shields.io/npm/dm/deep-for-each.svg
77
[npm-image]:http://img.shields.io/npm/v/deep-for-each.svg
8-
[travis-url]:https://travis-ci.org/IndigoUnited/js-deep-for-each
9-
[travis-image]:http://img.shields.io/travis/IndigoUnited/js-deep-for-each/master.svg
10-
[david-dm-url]:https://david-dm.org/IndigoUnited/js-deep-for-each
11-
[david-dm-image]:https://img.shields.io/david/IndigoUnited/js-deep-for-each.svg
12-
[david-dm-dev-url]:https://david-dm.org/IndigoUnited/js-deep-for-each?type=dev
13-
[david-dm-dev-image]:https://img.shields.io/david/dev/IndigoUnited/js-deep-for-each.svg
14-
[greenkeeper-image]:https://badges.greenkeeper.io/IndigoUnited/js-deep-for-each.svg
8+
[travis-url]:https://travis-ci.org/moxystudio/js-deep-for-each
9+
[travis-image]:http://img.shields.io/travis/moxystudio/js-deep-for-each/master.svg
10+
[codecov-url]:https://codecov.io/gh/moxystudio/node-is-regular-file
11+
[codecov-image]:https://img.shields.io/codecov/c/github/moxystudio/node-is-regular-file/master.svg
12+
[david-dm-url]:https://david-dm.org/moxystudio/js-deep-for-each
13+
[david-dm-image]:https://img.shields.io/david/moxystudio/js-deep-for-each.svg
14+
[david-dm-dev-url]:https://david-dm.org/moxystudio/js-deep-for-each?type=dev
15+
[david-dm-dev-image]:https://img.shields.io/david/dev/moxystudio/js-deep-for-each.svg
16+
[greenkeeper-image]:https://badges.greenkeeper.io/moxystudio/js-deep-for-each.svg
1517
[greenkeeper-url]:https://greenkeeper.io/
1618

17-
Recursively iterates over collections (arrays and objects). The iteration is made using a [deep-first](https://en.wikipedia.org/wiki/Depth-first_search) algorithm.
19+
Recursively iterates over arrays and objects. The iteration is made using a [deep-first](https://en.wikipedia.org/wiki/Depth-first_search) algorithm.
1820

1921

2022
## Installation
2123

22-
`$ npm install deep-for-each` - `NPM`
23-
`$ bower install deep-for-each` - `bower`
24-
25-
The browser file is named `index.umd.js` which supports CommonJS, AMD and globals (`deepForEach`).
26-
If you want to run this module on old browsers, you must include [es5-shim](https://github.com/es-shims/es5-shim).
24+
`$ npm install deep-for-each`
2725

2826

2927
## Usage
3028

31-
The example bellow is based on `nodejs`.
32-
3329
```js
34-
var deepForEach = require('deep-for-each');
30+
const deepForEach = require('deep-for-each');
3531

3632
deepForEach({
3733
prop1: 'foo',
@@ -41,12 +37,13 @@ deepForEach({
4137
prop5: 'foo',
4238
prop6: 'bar'
4339
}
44-
}, function (value, prop, subject, path) {
45-
// prop is an array index or an object key
46-
// subject is either an array or an object
47-
// path is the iteration path, e.g.: 'prop2[0]' and 'prop4.prop5'
40+
}, (value, prop, subject, path) => {
41+
// `value` is the current property value
42+
// `prop` is the current property name
43+
// `subject` is either an array or an object
44+
// `path` is the iteration path, e.g.: 'prop2[0]' and 'prop4.prop5'
4845

49-
console.log(path + ':', value);
46+
console.log(`${path}: ${value}`);
5047
});
5148
```
5249

@@ -68,7 +65,8 @@ prop4.prop6: bar
6865

6966
## Tests
7067

71-
`$ npm test`
68+
`$ npm test`
69+
`$ npm test -- --watch` during development
7270

7371

7472
## License

bower.json

Lines changed: 0 additions & 30 deletions
This file was deleted.

index.js renamed to es/index.js

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,35 @@
1-
'use strict';
2-
3-
var isPlainObject = require('is-plain-object');
4-
5-
function forEach(value, fn, path) {
6-
path = path || '';
7-
8-
if (Array.isArray(value)) {
9-
forEachArray(value, fn, path);
10-
} else if (isPlainObject(value)) {
11-
forEachObject(value, fn, path);
12-
}
13-
}
1+
import { isPlainObject } from 'lodash';
142

153
function forEachObject(obj, fn, path) {
16-
var key;
17-
var deepPath;
4+
for (var key in obj) {
5+
var deepPath = path ? path + '.' + key : key;
186

19-
for (key in obj) {
20-
deepPath = path ? path + '.' + key : key;
217
// Note that we always use obj[key] because it might be mutated by forEach
228
fn.call(obj, obj[key], key, obj, deepPath);
9+
2310
forEach(obj[key], fn, deepPath);
2411
}
2512
}
2613

2714
function forEachArray(array, fn, path) {
28-
var deepPath = '';
29-
3015
array.forEach(function (value, index, arr) {
31-
deepPath = path + '[' + index + ']';
16+
var deepPath = path + '[' + index + ']';
17+
3218
fn.call(arr, value, index, arr, deepPath);
19+
3320
// Note that we use arr[index] because it might be mutated by forEach
3421
forEach(arr[index], fn, deepPath);
3522
});
3623
}
3724

38-
module.exports = forEach;
25+
function forEach(value, fn, path) {
26+
path = path || '';
27+
28+
if (Array.isArray(value)) {
29+
forEachArray(value, fn, path);
30+
} else if (isPlainObject(value)) {
31+
forEachObject(value, fn, path);
32+
}
33+
}
34+
35+
export default forEach;

index.umd.js

Lines changed: 0 additions & 96 deletions
This file was deleted.

0 commit comments

Comments
 (0)