pax_global_header00006660000000000000000000000064141376030460014516gustar00rootroot0000000000000052 comment=22974d6532a0aa359c150c732e62d176aa821f9f each-props-2.0.0/000077500000000000000000000000001413760304600135565ustar00rootroot00000000000000each-props-2.0.0/.editorconfig000066400000000000000000000003261413760304600162340ustar00rootroot00000000000000# http://editorconfig.org root = true [*] indent_style = space indent_size = 2 charset = utf-8 trim_trailing_whitespace = true insert_final_newline = true end_of_line = lf [*.md] trim_trailing_whitespace = false each-props-2.0.0/.eslintignore000066400000000000000000000001471413760304600162630ustar00rootroot00000000000000# Coverage directory used by tools like istanbul coverage # Browerify output directories web test/web each-props-2.0.0/.eslintrc000066400000000000000000000001021413760304600153730ustar00rootroot00000000000000{ "extends": "gulp", "rules": { "max-statements": 0 } } each-props-2.0.0/.gitattributes000066400000000000000000000000161413760304600164460ustar00rootroot00000000000000* text eol=lf each-props-2.0.0/.github/000077500000000000000000000000001413760304600151165ustar00rootroot00000000000000each-props-2.0.0/.github/workflows/000077500000000000000000000000001413760304600171535ustar00rootroot00000000000000each-props-2.0.0/.github/workflows/dev.yml000066400000000000000000000031071413760304600204550ustar00rootroot00000000000000name: dev on: pull_request: push: branches: - master - main env: CI: true jobs: prettier: name: Format code runs-on: ubuntu-latest if: ${{ github.event_name == 'push' }} steps: - name: Checkout uses: actions/checkout@v2 - name: Prettier uses: gulpjs/prettier_action@v3.0 with: commit_message: 'chore: Run prettier' prettier_options: '--write .' test: name: Tests for Node ${{ matrix.node }} on ${{ matrix.os }} runs-on: ${{ matrix.os }} strategy: fail-fast: false matrix: node: [10, 12, 14, 16] os: [ubuntu-latest, windows-latest, macos-latest] steps: - name: Clone repository uses: actions/checkout@v2 - name: Set Node.js version uses: actions/setup-node@v2 with: node-version: ${{ matrix.node }} - run: node --version - run: npm --version - name: Install npm dependencies run: npm install - name: Run lint run: npm run lint - name: Run tests run: npm test - name: Coveralls uses: coverallsapp/github-action@v1.1.2 with: github-token: ${{ secrets.GITHUB_TOKEN }} flag-name: ${{ matrix.os }}-node-${{ matrix.node }} parallel: true coveralls: needs: test name: Finish up runs-on: ubuntu-latest steps: - name: Coveralls Finished uses: coverallsapp/github-action@v1.1.2 with: github-token: ${{ secrets.GITHUB_TOKEN }} parallel-finished: true each-props-2.0.0/.github/workflows/release.yml000066400000000000000000000005511413760304600213170ustar00rootroot00000000000000name: release on: push: branches: - master - main jobs: release-please: runs-on: ubuntu-latest steps: - uses: GoogleCloudPlatform/release-please-action@v2 with: token: ${{ secrets.GITHUB_TOKEN }} release-type: node package-name: release-please-action bump-minor-pre-major: true each-props-2.0.0/.gitignore000066400000000000000000000017101413760304600155450ustar00rootroot00000000000000# Logs logs *.log npm-debug.log* yarn-debug.log* yarn-error.log* # Runtime data pids *.pid *.seed *.pid.lock # Directory for instrumented libs generated by jscoverage/JSCover lib-cov # Coverage directory used by tools like istanbul coverage # nyc test coverage .nyc_output # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) .grunt # Bower dependency directory (https://bower.io/) bower_components # node-waf configuration .lock-wscript # Compiled binary addons (https://nodejs.org/api/addons.html) build/Release # Dependency directories node_modules/ jspm_packages/ # TypeScript v1 declaration files typings/ # Optional npm cache directory .npm # Optional eslint cache .eslintcache # Optional REPL history .node_repl_history # Output of 'npm pack' *.tgz # Yarn Integrity file .yarn-integrity # dotenv environment variables file .env # next.js build output .next # Garbage files .DS_Store # Test results test.xunit each-props-2.0.0/.npmrc000066400000000000000000000000231413760304600146710ustar00rootroot00000000000000package-lock=false each-props-2.0.0/.pretterignore000066400000000000000000000000441413760304600164460ustar00rootroot00000000000000coverage/ .nyc_output/ CHANGELOG.md each-props-2.0.0/CHANGELOG.md000066400000000000000000000006551413760304600153750ustar00rootroot00000000000000# Changelog ## [2.0.0](https://www.github.com/gulpjs/each-props/compare/v1.3.2...v2.0.0) (2021-09-27) ### ⚠ BREAKING CHANGES * Normalize repository, dropping node <10.13 support (#5) ### Miscellaneous Chores * Normalize repository, dropping node <10.13 support ([#5](https://www.github.com/gulpjs/each-props/issues/5)) ([779fed2](https://www.github.com/gulpjs/each-props/commit/779fed265bb7c0b67d1030ad8c2b9b4136883601)) each-props-2.0.0/LICENSE000066400000000000000000000020601413760304600145610ustar00rootroot00000000000000MIT License Copyright (c) 2016-2021 Gulp Team. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. each-props-2.0.0/README.md000066400000000000000000000114161413760304600150400ustar00rootroot00000000000000

# each-props [![NPM version][npm-image]][npm-url] [![Downloads][downloads-image]][npm-url] [![Build Status][ci-image]][ci-url] [![Coveralls Status][coveralls-image]][coveralls-url] Processes each properties of an object deeply. ## Install To install from npm: ```sh $ npm i each-props --save ``` ## Load this module For Node.js: ```js const eachProps = require('each-props'); ``` For Web browser: ```html ``` ## Usage Apply a function to all (non plain object) properties. ```js var obj = { a: 1, b: { c: 'CCC', d: { e: 'EEE' } } }; eachProps(obj, function (value, keyChain, nodeInfo) { if (keyChain === 'a') { nodeInfo.parent['a'] = value * 2; } else if (keyChain === 'b.c') { nodeInfo.parent['c'] = value.toLowerCase(); } else if (keyChain === 'b.d') { return true; // stop to dig } else if (keyChain === 'b.d.e') { nodeInfo.parent['e'] = value.toLowerCase(); } }); console.log(obj); // => { a: 2, b: { c: 'ccc', d: { e: 'EEE' } } }; ``` ## API ### eachProps(obj, fn [, opts]) : void Executes the _fn_ function for all properties. #### Parameters: | Parameter | Type | Description | | :-------- | :------: | :--------------------------------------------- | | _obj_ | object | A plain object to be treated. | | _fn_ | function | A function to operate each properties. | | _opts_ | object | An object to pass any data to each properties. | - **API of _fn_ function** #### fn(value, keyChain, nodeInfo) : boolean This function is applied to all properties in an object. ##### Parameters: | Parameter | Type | Description | | :--------- | :----: | :------------------------------------------------------------------- | | _value_ | any | A property value. | | _keyChain_ | string | A string concatenating the hierarchical keys with dots. | | _nodeInfo_ | object | An object which contains node informations (See [below](#nodeinfo)). | ##### Returns: True, if stops digging child properties. **Type:** boolean - **Properties of nodeInfo** | Properties | Type | Description | | :--------- | :------: | :---------------------------------------------------------------------------------------------------------- | | _name_ | string | The property name of this node. | | _index_ | number | The index of the property among the sibling properties. | | _count_ | number | The count of the sibling properties. | | _depth_ | number | The depth of the property. | | _parent_ | object | The parent node of the property. | | _sort_ | function | A sort function which orders the child properties. This function is inherited from _opts_, if be specified. | ... and any properties inherited from _opts_. - **Properties of opts** | Properties | Type | Description | | :--------- | :------: | :----------------------------------------------------------------- | | _sort_ | function | A sort function which orders the same level properties. (Optional) | ... and any properties you want to pass to each node. ## License Copyright (C) 2016-2021 Gulp Team. This program is free software under [MIT][mit-url] License. See the file LICENSE in this distribution for more details. [downloads-image]: https://img.shields.io/npm/dm/each-props.svg?style=flat-square [npm-url]: https://www.npmjs.org/package/each-props [npm-image]: https://img.shields.io/npm/v/each-props.svg?style=flat-square [ci-url]: https://github.com/gulpjs/each-props/actions?query=workflow:dev [ci-image]: https://img.shields.io/github/workflow/status/gulpjs/each-props/dev?style=flat-square [coveralls-url]: https://coveralls.io/r/gulpjs/each-props [coveralls-image]: https://img.shields.io/coveralls/gulpjs/each-props/master.svg [mit-url]: https://opensource.org/licenses/MIT each-props-2.0.0/index.js000066400000000000000000000022521413760304600152240ustar00rootroot00000000000000'use strict'; var isPlainObject = require('is-plain-object').isPlainObject; var defaults = require('object.defaults/immutable'); module.exports = function (obj, fn, opts) { if (!isObject(obj)) { return; } if (typeof fn !== 'function') { return; } if (!isPlainObject(opts)) { opts = {}; } forEachChild(obj, '', fn, 0, opts); }; function forEachChild(node, baseKey, fn, depth, opts) { var keys = Object.keys(node); if (typeof opts.sort === 'function') { var sortedKeys = opts.sort(keys); if (Array.isArray(sortedKeys)) { keys = sortedKeys; } } depth += 1; for (var i = 0, n = keys.length; i < n; i++) { var key = keys[i]; var keyChain = baseKey + '.' + key; var value = node[key]; var nodeInfo = defaults(opts); nodeInfo.name = key; nodeInfo.index = i; nodeInfo.count = n; nodeInfo.depth = depth; nodeInfo.parent = node; var notDigg = fn(value, keyChain.slice(1), nodeInfo); if (notDigg || !isPlainObject(value)) { continue; } forEachChild(value, keyChain, fn, depth, opts); } } function isObject(v) { return Object.prototype.toString.call(v) === '[object Object]'; } each-props-2.0.0/package.json000066400000000000000000000030411413760304600160420ustar00rootroot00000000000000{ "name": "each-props", "version": "2.0.0", "description": "Processes each properties of an object deeply.", "author": "Gulp Team (https://gulpjs.com/)", "main": "index.js", "files": [ "index.js" ], "scripts": { "lint": "eslint .", "pretest": "npm run lint", "test": "nyc mocha", "web:build": "browserify index.js --standalone eachProps -o web/each-props.js && cd web && uglifyjs each-props.js --compress --mangle -o each-props.min.js --source-map url=each-props.min.js.map", "chrome:install": "npm i --no-save mocha-chrome", "chrome:test": "mocha-chrome test/web/browser-test.html", "build": "npm run lint && npm run test && npm run web:build && node test/web/make.js" }, "repository": { "type": "git", "url": "git+https://github.com/gulpjs/each-props.git" }, "keywords": [ "deep", "each", "object", "property", "properties", "props" ], "license": "MIT", "engines": { "node": ">= 10.13.0" }, "bugs": { "url": "https://github.com/gulpjs/each-props/issues" }, "homepage": "https://github.com/gulpjs/each-props#readme", "nyc": { "reporter": [ "lcov", "text-summary" ] }, "prettier": { "singleQuote": true }, "dependencies": { "is-plain-object": "^5.0.0", "object.defaults": "^1.1.0" }, "devDependencies": { "browserify": "^17.0.0", "chai": "^4.3.4", "eslint": "^7.32.0", "eslint-config-gulp": "^5.0.1", "mocha": "^8.4.0", "nyc": "^15.1.0", "uglify-js": "^3.14.2" } } each-props-2.0.0/test/000077500000000000000000000000001413760304600145355ustar00rootroot00000000000000each-props-2.0.0/test/each-props-args.js000066400000000000000000000711041413760304600200710ustar00rootroot00000000000000'use strict'; var eachProps = require('..'); var chai = require('chai'); var expect = chai.expect; function logger(value, keyChain, nodeInfo) { this.push({ value: value, keyChain: keyChain, nodeInfo: nodeInfo, }); } var fnNoReturn = function () {}; var fnReturnNull = function () { return null; }; var fnReturnBool = function () { return true; }; var fnReturnNum = function () { return 123; }; var fnReturnStr = function () { return 'abc'; }; var fnReturnFunc = function () { return fnNoReturn; }; var fnReturnObj = function () { return {}; }; var fnSort = function (arr) { return arr.sort(sorter); function sorter(a, b) { return b < a ? -1 : 1; } }; /* eslint max-statements: "off", brace-style: "off" */ describe('Argument test', function () { it('Should process normally when args are normal', function (done) { var logs = []; var obj = { a: 1, b: { c: 2 } }; var opts = { xxx: true }; eachProps(obj, logger.bind(logs), opts); expect(obj).to.deep.equal({ a: 1, b: { c: 2 } }); expect(logs).to.deep.equal([ { value: 1, keyChain: 'a', nodeInfo: { index: 0, count: 2, depth: 1, parent: { a: 1, b: { c: 2 } }, xxx: true, name: 'a', }, }, { value: { c: 2 }, keyChain: 'b', nodeInfo: { index: 1, count: 2, depth: 1, parent: { a: 1, b: { c: 2 } }, xxx: true, name: 'b', }, }, { value: 2, keyChain: 'b.c', nodeInfo: { index: 0, count: 1, depth: 2, parent: { c: 2 }, xxx: true, name: 'c', }, }, ]); done(); }); it('Should process normally when args are normal (opts.sort is specified', function (done) { var logs = []; var obj = { a: 1, b: { c: 2 } }; var opts = { sort: fnSort }; eachProps(obj, logger.bind(logs), opts); expect(obj).to.deep.equal({ a: 1, b: { c: 2 } }); expect(logs).to.deep.equal([ { value: { c: 2 }, keyChain: 'b', nodeInfo: { index: 0, count: 2, depth: 1, parent: { a: 1, b: { c: 2 } }, sort: fnSort, name: 'b', }, }, { value: 2, keyChain: 'b.c', nodeInfo: { index: 0, count: 1, depth: 2, parent: { c: 2 }, sort: fnSort, name: 'c', }, }, { value: 1, keyChain: 'a', nodeInfo: { index: 1, count: 2, depth: 1, parent: { a: 1, b: { c: 2 } }, sort: fnSort, name: 'a', }, }, ]); done(); }); it('Should process nothing when 1st arg is undefined', function (done) { var logs = []; var obj = undefined; var opts = {}; eachProps(obj, logger.bind(logs), opts); expect(obj).to.equal(undefined); expect(logs).to.deep.equal([]); done(); }); it('Should process nothing when 1st arg is null', function (done) { var logs = []; var obj = null; var opts = {}; eachProps(obj, logger.bind(logs), opts); expect(obj).to.equal(null); expect(logs).to.deep.equal([]); done(); }); it('Should process nothing when 1st arg is not a boolean', function (done) { var logs = []; var obj = true; var opts = {}; eachProps(obj, logger.bind(logs), opts); expect(obj).to.equal(true); expect(logs).to.deep.equal([]); done(); }); it('Should process nothing when 1st arg is a number', function (done) { var logs = []; var obj = 9; var opts = {}; eachProps(obj, logger.bind(logs), opts); expect(obj).to.equal(9); expect(logs).to.deep.equal([]); done(); }); it('Should process nothing when 1st arg is a string', function (done) { var logs = []; var obj = 'ABC'; var opts = {}; eachProps(obj, logger.bind(logs), opts); expect(obj).to.equal('ABC'); expect(logs).to.deep.equal([]); done(); }); it('Should process nothing when 1st arg is an array', function (done) { var logs = []; var obj = [{ a: 1 }, { b: 2 }, { c: 3 }]; var opts = {}; eachProps(obj, logger.bind(logs), opts); expect(obj).to.deep.equal([{ a: 1 }, { b: 2 }, { c: 3 }]); expect(logs).to.deep.equal([]); done(); }); it('Should process nothing when 1st arg is a function', function (done) { var logs = []; var obj = fnNoReturn; var opts = {}; eachProps(obj, logger.bind(logs), opts); expect(logs).to.deep.equal([]); done(); }); it('Should process nothing when 1st arg is a typed object', function (done) { var logs = []; var obj = new Date(0); var opts = {}; eachProps(obj, logger.bind(logs), opts); expect(logs).to.deep.equal([]); done(); }); it('Should process nothing when 1st arg is an empty plain object', function (done) { var logs = []; var obj = {}; var opts = {}; eachProps(obj, logger.bind(logs), opts); expect(obj).to.deep.equal({}); expect(logs).to.deep.equal([]); done(); }); it('Should process nothing when 2nd arg is undefined', function (done) { var obj = { a: 1 }; var fn = undefined; eachProps(obj, fn); expect(obj).to.deep.equal({ a: 1 }); done(); }); it('Should process nothing when 2nd arg is null', function (done) { var obj = { a: 1 }; var fn = null; eachProps(obj, fn); expect(obj).to.deep.equal({ a: 1 }); done(); }); it('Should process nothing when 2nd arg is a boolean', function (done) { var obj = { a: 1 }; var fn = true; eachProps(obj, fn); expect(obj).to.deep.equal({ a: 1 }); done(); }); it('Should process nothing when 2nd arg is a number', function (done) { var obj = { a: 1 }; var fn = 123; eachProps(obj, fn); expect(obj).to.deep.equal({ a: 1 }); done(); }); it('Should process nothing when 2nd arg is a string', function (done) { var obj = { a: 1 }; var fn = 'ABC'; eachProps(obj, fn); expect(obj).to.deep.equal({ a: 1 }); done(); }); it('Should process nothing when 2nd arg is an array', function (done) { var obj = { a: 1 }; var fn = ['A', 'B', 'C']; eachProps(obj, fn); expect(obj).to.deep.equal({ a: 1 }); done(); }); it('Should process nothing when 2nd arg is an plain object', function (done) { var obj = { a: 1 }; var fn = { a: 'A', b: 'B', c: 'C' }; eachProps(obj, fn); expect(obj).to.deep.equal({ a: 1 }); done(); }); it('Should process nothing when 2nd arg is an typed object', function (done) { var obj = { a: 1 }; var fn = new Date(0); eachProps(obj, fn); expect(obj).to.deep.equal({ a: 1 }); done(); }); it('Should process nothing when 3rd arg is undefined', function (done) { var logs = []; var obj = { a: 1, b: { c: 2 } }; var opts = undefined; eachProps(obj, logger.bind(logs), opts); expect(logs).to.deep.equal([ { value: 1, keyChain: 'a', nodeInfo: { index: 0, count: 2, depth: 1, parent: { a: 1, b: { c: 2 } }, name: 'a', }, }, { value: { c: 2 }, keyChain: 'b', nodeInfo: { index: 1, count: 2, depth: 1, parent: { a: 1, b: { c: 2 } }, name: 'b', }, }, { value: 2, keyChain: 'b.c', nodeInfo: { index: 0, count: 1, depth: 2, parent: { c: 2 }, name: 'c' }, }, ]); done(); }); it('Should process nothing when 3rd arg is null', function (done) { var logs = []; var obj = { a: 1, b: { c: 2 } }; var opts = null; eachProps(obj, logger.bind(logs), opts); expect(logs).to.deep.equal([ { value: 1, keyChain: 'a', nodeInfo: { index: 0, count: 2, depth: 1, parent: { a: 1, b: { c: 2 } }, name: 'a', }, }, { value: { c: 2 }, keyChain: 'b', nodeInfo: { index: 1, count: 2, depth: 1, parent: { a: 1, b: { c: 2 } }, name: 'b', }, }, { value: 2, keyChain: 'b.c', nodeInfo: { index: 0, count: 1, depth: 2, parent: { c: 2 }, name: 'c' }, }, ]); done(); }); it('Should process nothing when 3rd arg is a boolean', function (done) { var logs = []; var obj = { a: 1, b: { c: 2 } }; var opts = true; eachProps(obj, logger.bind(logs), opts); expect(logs).to.deep.equal([ { value: 1, keyChain: 'a', nodeInfo: { index: 0, count: 2, depth: 1, parent: { a: 1, b: { c: 2 } }, name: 'a', }, }, { value: { c: 2 }, keyChain: 'b', nodeInfo: { index: 1, count: 2, depth: 1, parent: { a: 1, b: { c: 2 } }, name: 'b', }, }, { value: 2, keyChain: 'b.c', nodeInfo: { index: 0, count: 1, depth: 2, parent: { c: 2 }, name: 'c' }, }, ]); done(); }); it('Should process nothing when 3rd arg is a number', function (done) { var logs = []; var obj = { a: 1, b: { c: 2 } }; var opts = 123; eachProps(obj, logger.bind(logs), opts); expect(logs).to.deep.equal([ { value: 1, keyChain: 'a', nodeInfo: { index: 0, count: 2, depth: 1, parent: { a: 1, b: { c: 2 } }, name: 'a', }, }, { value: { c: 2 }, keyChain: 'b', nodeInfo: { index: 1, count: 2, depth: 1, parent: { a: 1, b: { c: 2 } }, name: 'b', }, }, { value: 2, keyChain: 'b.c', nodeInfo: { index: 0, count: 1, depth: 2, parent: { c: 2 }, name: 'c' }, }, ]); done(); }); it('Should process nothing when 3rd arg is a string', function (done) { var logs = []; var obj = { a: 1, b: { c: 2 } }; var opts = 'ABC'; eachProps(obj, logger.bind(logs), opts); expect(logs).to.deep.equal([ { value: 1, keyChain: 'a', nodeInfo: { index: 0, count: 2, depth: 1, parent: { a: 1, b: { c: 2 } }, name: 'a', }, }, { value: { c: 2 }, keyChain: 'b', nodeInfo: { index: 1, count: 2, depth: 1, parent: { a: 1, b: { c: 2 } }, name: 'b', }, }, { value: 2, keyChain: 'b.c', nodeInfo: { index: 0, count: 1, depth: 2, parent: { c: 2 }, name: 'c' }, }, ]); done(); }); it('Should process nothing when 3rd arg is an array', function (done) { var logs = []; var obj = { a: 1, b: { c: 2 } }; var opts = [1, 2, 3]; eachProps(obj, logger.bind(logs), opts); expect(logs).to.deep.equal([ { value: 1, keyChain: 'a', nodeInfo: { index: 0, count: 2, depth: 1, parent: { a: 1, b: { c: 2 } }, name: 'a', }, }, { value: { c: 2 }, keyChain: 'b', nodeInfo: { index: 1, count: 2, depth: 1, parent: { a: 1, b: { c: 2 } }, name: 'b', }, }, { value: 2, keyChain: 'b.c', nodeInfo: { index: 0, count: 1, depth: 2, parent: { c: 2 }, name: 'c' }, }, ]); done(); }); it('Should process nothing when 3rd arg is a function', function (done) { var logs = []; var obj = { a: 1, b: { c: 2 } }; var opts = fnNoReturn; eachProps(obj, logger.bind(logs), opts); expect(logs).to.deep.equal([ { value: 1, keyChain: 'a', nodeInfo: { index: 0, count: 2, depth: 1, parent: { a: 1, b: { c: 2 } }, name: 'a', }, }, { value: { c: 2 }, keyChain: 'b', nodeInfo: { index: 1, count: 2, depth: 1, parent: { a: 1, b: { c: 2 } }, name: 'b', }, }, { value: 2, keyChain: 'b.c', nodeInfo: { index: 0, count: 1, depth: 2, parent: { c: 2 }, name: 'c' }, }, ]); done(); }); it('Should process nothing when 3rd arg is a typed object', function (done) { var logs = []; var obj = { a: 1, b: { c: 2 } }; var opts = new Date(0); eachProps(obj, logger.bind(logs), opts); expect(logs).to.deep.equal([ { value: 1, keyChain: 'a', nodeInfo: { index: 0, count: 2, depth: 1, parent: { a: 1, b: { c: 2 } }, name: 'a', }, }, { value: { c: 2 }, keyChain: 'b', nodeInfo: { index: 1, count: 2, depth: 1, parent: { a: 1, b: { c: 2 } }, name: 'b', }, }, { value: 2, keyChain: 'b.c', nodeInfo: { index: 0, count: 1, depth: 2, parent: { c: 2 }, name: 'c' }, }, ]); done(); }); it('Should process nothing when 3rd arg is an empty plain object', function (done) { var logs = []; var obj = { a: 1, b: { c: 2 } }; var opts = {}; eachProps(obj, logger.bind(logs), opts); expect(logs).to.deep.equal([ { value: 1, keyChain: 'a', nodeInfo: { index: 0, count: 2, depth: 1, parent: { a: 1, b: { c: 2 } }, name: 'a', }, }, { value: { c: 2 }, keyChain: 'b', nodeInfo: { index: 1, count: 2, depth: 1, parent: { a: 1, b: { c: 2 } }, name: 'b', }, }, { value: 2, keyChain: 'b.c', nodeInfo: { index: 0, count: 1, depth: 2, parent: { c: 2 }, name: 'c' }, }, ]); done(); }); it('Should not sort keys when `.sort` of 3rd arg is undefined', function (done) { var logs = []; var obj = { a: 1, b: { c: 2 } }; var opts = { sort: undefined }; eachProps(obj, logger.bind(logs), opts); expect(logs).to.deep.equal([ { value: 1, keyChain: 'a', nodeInfo: { index: 0, count: 2, depth: 1, parent: { a: 1, b: { c: 2 } }, sort: undefined, name: 'a', }, }, { value: { c: 2 }, keyChain: 'b', nodeInfo: { index: 1, count: 2, depth: 1, parent: { a: 1, b: { c: 2 } }, sort: undefined, name: 'b', }, }, { value: 2, keyChain: 'b.c', nodeInfo: { index: 0, count: 1, depth: 2, parent: { c: 2 }, sort: undefined, name: 'c', }, }, ]); done(); }); it('Should not sort keys when `.sort` of 3rd arg is null', function (done) { var logs = []; var obj = { a: 1, b: { c: 2 } }; var opts = { sort: null }; eachProps(obj, logger.bind(logs), opts); expect(logs).to.deep.equal([ { value: 1, keyChain: 'a', nodeInfo: { index: 0, count: 2, depth: 1, parent: { a: 1, b: { c: 2 } }, sort: null, name: 'a', }, }, { value: { c: 2 }, keyChain: 'b', nodeInfo: { index: 1, count: 2, depth: 1, parent: { a: 1, b: { c: 2 } }, sort: null, name: 'b', }, }, { value: 2, keyChain: 'b.c', nodeInfo: { index: 0, count: 1, depth: 2, parent: { c: 2 }, sort: null, name: 'c', }, }, ]); done(); }); it('Should not sort keys when `.sort` of 3rd arg is a boolean', function (done) { var logs = []; var obj = { a: 1, b: { c: 2 } }; var opts = { sort: true }; eachProps(obj, logger.bind(logs), opts); expect(logs).to.deep.equal([ { value: 1, keyChain: 'a', nodeInfo: { index: 0, count: 2, depth: 1, parent: { a: 1, b: { c: 2 } }, sort: true, name: 'a', }, }, { value: { c: 2 }, keyChain: 'b', nodeInfo: { index: 1, count: 2, depth: 1, parent: { a: 1, b: { c: 2 } }, sort: true, name: 'b', }, }, { value: 2, keyChain: 'b.c', nodeInfo: { index: 0, count: 1, depth: 2, parent: { c: 2 }, sort: true, name: 'c', }, }, ]); done(); }); it('Should not sort keys when `.sort` of 3rd arg is a number', function (done) { var logs = []; var obj = { a: 1, b: { c: 2 } }; var opts = { sort: 123 }; eachProps(obj, logger.bind(logs), opts); expect(logs).to.deep.equal([ { value: 1, keyChain: 'a', nodeInfo: { index: 0, count: 2, depth: 1, parent: { a: 1, b: { c: 2 } }, sort: 123, name: 'a', }, }, { value: { c: 2 }, keyChain: 'b', nodeInfo: { index: 1, count: 2, depth: 1, parent: { a: 1, b: { c: 2 } }, sort: 123, name: 'b', }, }, { value: 2, keyChain: 'b.c', nodeInfo: { index: 0, count: 1, depth: 2, parent: { c: 2 }, sort: 123, name: 'c', }, }, ]); done(); }); it('Should not sort keys when `.sort` of 3rd arg is a string', function (done) { var logs = []; var obj = { a: 1, b: { c: 2 } }; var opts = { sort: 'ABC' }; eachProps(obj, logger.bind(logs), opts); expect(logs).to.deep.equal([ { value: 1, keyChain: 'a', nodeInfo: { index: 0, count: 2, depth: 1, parent: { a: 1, b: { c: 2 } }, sort: 'ABC', name: 'a', }, }, { value: { c: 2 }, keyChain: 'b', nodeInfo: { index: 1, count: 2, depth: 1, parent: { a: 1, b: { c: 2 } }, sort: 'ABC', name: 'b', }, }, { value: 2, keyChain: 'b.c', nodeInfo: { index: 0, count: 1, depth: 2, parent: { c: 2 }, sort: 'ABC', name: 'c', }, }, ]); done(); }); it('Should not sort keys when `.sort` of 3rd arg is an array', function (done) { var logs = []; var obj = { a: 1, b: { c: 2 } }; var opts = { sort: [1, 2, 3] }; eachProps(obj, logger.bind(logs), opts); expect(logs).to.deep.equal([ { value: 1, keyChain: 'a', nodeInfo: { index: 0, count: 2, depth: 1, parent: { a: 1, b: { c: 2 } }, sort: [1, 2, 3], name: 'a', }, }, { value: { c: 2 }, keyChain: 'b', nodeInfo: { index: 1, count: 2, depth: 1, parent: { a: 1, b: { c: 2 } }, sort: [1, 2, 3], name: 'b', }, }, { value: 2, keyChain: 'b.c', nodeInfo: { index: 0, count: 1, depth: 2, parent: { c: 2 }, sort: [1, 2, 3], name: 'c', }, }, ]); done(); }); it('Should not sort keys when `.sort` of 3rd arg is a object', function (done) { var logs = []; var obj = { a: 1, b: { c: 2 } }; var opts = { sort: { x: 1 } }; eachProps(obj, logger.bind(logs), opts); expect(logs).to.deep.equal([ { value: 1, keyChain: 'a', nodeInfo: { index: 0, count: 2, depth: 1, parent: { a: 1, b: { c: 2 } }, sort: { x: 1 }, name: 'a', }, }, { value: { c: 2 }, keyChain: 'b', nodeInfo: { index: 1, count: 2, depth: 1, parent: { a: 1, b: { c: 2 } }, sort: { x: 1 }, name: 'b', }, }, { value: 2, keyChain: 'b.c', nodeInfo: { index: 0, count: 1, depth: 2, parent: { c: 2 }, sort: { x: 1 }, name: 'c', }, }, ]); done(); }); it( 'Should not sort keys when `.sort` of 3rd arg is a function which' + '\n\treturns nothing', function (done) { var logs = []; var obj = { a: 1, b: { c: 2 } }; var opts = { sort: fnNoReturn }; eachProps(obj, logger.bind(logs), opts); expect(logs).to.deep.equal([ { value: 1, keyChain: 'a', nodeInfo: { index: 0, count: 2, depth: 1, parent: { a: 1, b: { c: 2 } }, sort: fnNoReturn, name: 'a', }, }, { value: { c: 2 }, keyChain: 'b', nodeInfo: { index: 1, count: 2, depth: 1, parent: { a: 1, b: { c: 2 } }, sort: fnNoReturn, name: 'b', }, }, { value: 2, keyChain: 'b.c', nodeInfo: { index: 0, count: 1, depth: 2, parent: { c: 2 }, sort: fnNoReturn, name: 'c', }, }, ]); done(); } ); it( 'Should not sort keys when `.sort` of 3rd arg is a function which' + '\n\treturns null', function (done) { var logs = []; var obj = { a: 1, b: { c: 2 } }; var opts = { sort: fnReturnNull }; eachProps(obj, logger.bind(logs), opts); expect(logs).to.deep.equal([ { value: 1, keyChain: 'a', nodeInfo: { index: 0, count: 2, depth: 1, parent: { a: 1, b: { c: 2 } }, sort: fnReturnNull, name: 'a', }, }, { value: { c: 2 }, keyChain: 'b', nodeInfo: { index: 1, count: 2, depth: 1, parent: { a: 1, b: { c: 2 } }, sort: fnReturnNull, name: 'b', }, }, { value: 2, keyChain: 'b.c', nodeInfo: { index: 0, count: 1, depth: 2, parent: { c: 2 }, sort: fnReturnNull, name: 'c', }, }, ]); done(); } ); it( 'Should not sort keys when `.sort` of 3rd arg is a function which' + '\n\treturns a boolean', function (done) { var logs = []; var obj = { a: 1, b: { c: 2 } }; var opts = { sort: fnReturnBool }; eachProps(obj, logger.bind(logs), opts); expect(logs).to.deep.equal([ { value: 1, keyChain: 'a', nodeInfo: { index: 0, count: 2, depth: 1, parent: { a: 1, b: { c: 2 } }, sort: fnReturnBool, name: 'a', }, }, { value: { c: 2 }, keyChain: 'b', nodeInfo: { index: 1, count: 2, depth: 1, parent: { a: 1, b: { c: 2 } }, sort: fnReturnBool, name: 'b', }, }, { value: 2, keyChain: 'b.c', nodeInfo: { index: 0, count: 1, depth: 2, parent: { c: 2 }, sort: fnReturnBool, name: 'c', }, }, ]); done(); } ); it( 'Should not sort keys when `.sort` of 3rd arg is a function which' + '\n\treturns a number', function (done) { var logs = []; var obj = { a: 1, b: { c: 2 } }; var opts = { sort: fnReturnNum }; eachProps(obj, logger.bind(logs), opts); expect(logs).to.deep.equal([ { value: 1, keyChain: 'a', nodeInfo: { index: 0, count: 2, depth: 1, parent: { a: 1, b: { c: 2 } }, sort: fnReturnNum, name: 'a', }, }, { value: { c: 2 }, keyChain: 'b', nodeInfo: { index: 1, count: 2, depth: 1, parent: { a: 1, b: { c: 2 } }, sort: fnReturnNum, name: 'b', }, }, { value: 2, keyChain: 'b.c', nodeInfo: { index: 0, count: 1, depth: 2, parent: { c: 2 }, sort: fnReturnNum, name: 'c', }, }, ]); done(); } ); it( 'Should not sort keys when `.sort` of 3rd arg is a function which' + '\n\treturns a string', function (done) { var logs = []; var obj = { a: 1, b: { c: 2 } }; var opts = { sort: fnReturnStr }; eachProps(obj, logger.bind(logs), opts); expect(logs).to.deep.equal([ { value: 1, keyChain: 'a', nodeInfo: { index: 0, count: 2, depth: 1, parent: { a: 1, b: { c: 2 } }, sort: fnReturnStr, name: 'a', }, }, { value: { c: 2 }, keyChain: 'b', nodeInfo: { index: 1, count: 2, depth: 1, parent: { a: 1, b: { c: 2 } }, sort: fnReturnStr, name: 'b', }, }, { value: 2, keyChain: 'b.c', nodeInfo: { index: 0, count: 1, depth: 2, parent: { c: 2 }, sort: fnReturnStr, name: 'c', }, }, ]); done(); } ); it( 'Should not sort keys when `.sort` of 3rd arg is a function which' + '\n\treturns a function', function (done) { var logs = []; var obj = { a: 1, b: { c: 2 } }; var opts = { sort: fnReturnFunc }; eachProps(obj, logger.bind(logs), opts); expect(logs).to.deep.equal([ { value: 1, keyChain: 'a', nodeInfo: { index: 0, count: 2, depth: 1, parent: { a: 1, b: { c: 2 } }, sort: fnReturnFunc, name: 'a', }, }, { value: { c: 2 }, keyChain: 'b', nodeInfo: { index: 1, count: 2, depth: 1, parent: { a: 1, b: { c: 2 } }, sort: fnReturnFunc, name: 'b', }, }, { value: 2, keyChain: 'b.c', nodeInfo: { index: 0, count: 1, depth: 2, parent: { c: 2 }, sort: fnReturnFunc, name: 'c', }, }, ]); done(); } ); it( 'Should not sort keys when `.sort` of 3rd arg is a function which' + '\n\treturns an object', function (done) { var logs = []; var obj = { a: 1, b: { c: 2 } }; var opts = { sort: fnReturnObj }; eachProps(obj, logger.bind(logs), opts); expect(logs).to.deep.equal([ { value: 1, keyChain: 'a', nodeInfo: { index: 0, count: 2, depth: 1, parent: { a: 1, b: { c: 2 } }, sort: fnReturnObj, name: 'a', }, }, { value: { c: 2 }, keyChain: 'b', nodeInfo: { index: 1, count: 2, depth: 1, parent: { a: 1, b: { c: 2 } }, sort: fnReturnObj, name: 'b', }, }, { value: 2, keyChain: 'b.c', nodeInfo: { index: 0, count: 1, depth: 2, parent: { c: 2 }, sort: fnReturnObj, name: 'c', }, }, ]); done(); } ); }); each-props-2.0.0/test/each-props-proc.js000066400000000000000000000130361413760304600201000ustar00rootroot00000000000000'use strict'; var eachProps = require('..'); var chai = require('chai'); var expect = chai.expect; function logger(value, keyChain, nodeInfo) { var log = {}; Object.keys(nodeInfo).forEach(function (key) { log[key] = nodeInfo[key]; }); delete log.parent; delete log.sort; delete log.return; log.keyChain = keyChain; this.push(log); if (nodeInfo.return) { return nodeInfo.return(keyChain); } } /* eslint max-statements: "off", brace-style: "off" */ describe('Processing test', function () { it('Should succeed when an input object is single depth', function (done) { var logs = []; var obj = { a: 1, b: 2, c: 3 }; eachProps(obj, logger.bind(logs)); expect(logs).to.deep.equal([ { keyChain: 'a', index: 0, count: 3, depth: 1, name: 'a' }, { keyChain: 'b', index: 1, count: 3, depth: 1, name: 'b' }, { keyChain: 'c', index: 2, count: 3, depth: 1, name: 'c' }, ]); done(); }); it('Should succeed when an input object is multiple depth', function (done) { var logs = []; var obj = { a: 1, b: { c: 'C', d: 'D', e: { f: 'F', g: 'G' } } }; eachProps(obj, logger.bind(logs)); expect(logs).to.deep.equal([ { keyChain: 'a', index: 0, count: 2, depth: 1, name: 'a' }, { keyChain: 'b', index: 1, count: 2, depth: 1, name: 'b' }, { keyChain: 'b.c', index: 0, count: 3, depth: 2, name: 'c' }, { keyChain: 'b.d', index: 1, count: 3, depth: 2, name: 'd' }, { keyChain: 'b.e', index: 2, count: 3, depth: 2, name: 'e' }, { keyChain: 'b.e.f', index: 0, count: 2, depth: 3, name: 'f' }, { keyChain: 'b.e.g', index: 1, count: 2, depth: 3, name: 'g' }, ]); done(); }); it('Should sort properties when a sort function is specified', function (done) { var logs = []; var obj = { q: 1, w: 2, e: 3, r: 4, t: 5, y: 6 }; var opts = { sort: function (arr) { return arr.sort(); }, }; eachProps(obj, logger.bind(logs), opts); expect(logs).to.deep.equal([ { keyChain: 'e', name: 'e', index: 0, count: 6, depth: 1 }, { keyChain: 'q', name: 'q', index: 1, count: 6, depth: 1 }, { keyChain: 'r', name: 'r', index: 2, count: 6, depth: 1 }, { keyChain: 't', name: 't', index: 3, count: 6, depth: 1 }, { keyChain: 'w', name: 'w', index: 4, count: 6, depth: 1 }, { keyChain: 'y', name: 'y', index: 5, count: 6, depth: 1 }, ]); done(); }); it( 'Should sort properties when an input object is multiple depth and' + '\n\ta sort function is specified', function (done) { var logs = []; var obj = { z: 1, x: { c: 'C', v: 'D', b: { n: 'F', m: 'G' } } }; var opts = { sort: function (arr) { return arr.sort(); }, }; eachProps(obj, logger.bind(logs), opts); expect(logs).to.deep.equal([ { name: 'x', keyChain: 'x', index: 0, count: 2, depth: 1 }, { name: 'b', keyChain: 'x.b', index: 0, count: 3, depth: 2 }, { name: 'm', keyChain: 'x.b.m', index: 0, count: 2, depth: 3 }, { name: 'n', keyChain: 'x.b.n', index: 1, count: 2, depth: 3 }, { name: 'c', keyChain: 'x.c', index: 1, count: 3, depth: 2 }, { name: 'v', keyChain: 'x.v', index: 2, count: 3, depth: 2 }, { name: 'z', keyChain: 'z', index: 1, count: 2, depth: 1 }, ]); done(); } ); it('Should Stop digging when the return value is true', function (done) { var logs = []; var obj = { z: 1, x: { c: 'C', v: 'D', b: { n: 'F', m: 'G' }, a: 'H' } }; var opts = { sort: function (arr) { return arr.sort(); }, return: function (keyChain) { return keyChain === 'x.b'; }, }; eachProps(obj, logger.bind(logs), opts); expect(logs).to.deep.equal([ { name: 'x', keyChain: 'x', index: 0, count: 2, depth: 1 }, { name: 'a', keyChain: 'x.a', index: 0, count: 4, depth: 2 }, { name: 'b', keyChain: 'x.b', index: 1, count: 4, depth: 2 }, { name: 'c', keyChain: 'x.c', index: 2, count: 4, depth: 2 }, { name: 'v', keyChain: 'x.v', index: 3, count: 4, depth: 2 }, { name: 'z', keyChain: 'z', index: 1, count: 2, depth: 1 }, ]); done(); }); it('Should pass properties in opts to all nodes', function (done) { var logs = []; var obj = { z: 1, x: { c: 'C', v: 'D', b: { n: 'F', m: 'G' } } }; var opts = { sort: function (arr) { return arr.sort(); }, m: 'ABC', n: 9, }; eachProps(obj, logger.bind(logs), opts); expect(logs).to.deep.equal([ { name: 'x', keyChain: 'x', index: 0, count: 2, depth: 1, m: 'ABC', n: 9, }, { name: 'b', keyChain: 'x.b', index: 0, count: 3, depth: 2, m: 'ABC', n: 9, }, { name: 'm', keyChain: 'x.b.m', index: 0, count: 2, depth: 3, m: 'ABC', n: 9, }, { name: 'n', keyChain: 'x.b.n', index: 1, count: 2, depth: 3, m: 'ABC', n: 9, }, { name: 'c', keyChain: 'x.c', index: 1, count: 3, depth: 2, m: 'ABC', n: 9, }, { name: 'v', keyChain: 'x.v', index: 2, count: 3, depth: 2, m: 'ABC', n: 9, }, { name: 'z', keyChain: 'z', index: 1, count: 2, depth: 1, m: 'ABC', n: 9, }, ]); done(); }); }); each-props-2.0.0/test/web/000077500000000000000000000000001413760304600153125ustar00rootroot00000000000000each-props-2.0.0/test/web/browser-test.html000066400000000000000000000011741413760304600206430ustar00rootroot00000000000000 each-props test on browser
each-props-2.0.0/test/web/each-props-args.js000066400000000000000000000771311413760304600206540ustar00rootroot00000000000000(function () { 'use strict'; var expect = chai.expect; function logger(value, keyChain, nodeInfo) { this.push({ value: value, keyChain: keyChain, nodeInfo: nodeInfo, }); } var fnNoReturn = function () {}; var fnReturnNull = function () { return null; }; var fnReturnBool = function () { return true; }; var fnReturnNum = function () { return 123; }; var fnReturnStr = function () { return 'abc'; }; var fnReturnFunc = function () { return fnNoReturn; }; var fnReturnObj = function () { return {}; }; var fnSort = function (arr) { return arr.sort(sorter); function sorter(a, b) { return b < a ? -1 : 1; } }; /* eslint max-statements: "off", brace-style: "off" */ describe('Argument test', function () { it('Should process normally when args are normal', function (done) { var logs = []; var obj = { a: 1, b: { c: 2 } }; var opts = { xxx: true }; eachProps(obj, logger.bind(logs), opts); expect(obj).to.deep.equal({ a: 1, b: { c: 2 } }); expect(logs).to.deep.equal([ { value: 1, keyChain: 'a', nodeInfo: { index: 0, count: 2, depth: 1, parent: { a: 1, b: { c: 2 } }, xxx: true, name: 'a', }, }, { value: { c: 2 }, keyChain: 'b', nodeInfo: { index: 1, count: 2, depth: 1, parent: { a: 1, b: { c: 2 } }, xxx: true, name: 'b', }, }, { value: 2, keyChain: 'b.c', nodeInfo: { index: 0, count: 1, depth: 2, parent: { c: 2 }, xxx: true, name: 'c', }, }, ]); done(); }); it('Should process normally when args are normal (opts.sort is specified', function (done) { var logs = []; var obj = { a: 1, b: { c: 2 } }; var opts = { sort: fnSort }; eachProps(obj, logger.bind(logs), opts); expect(obj).to.deep.equal({ a: 1, b: { c: 2 } }); expect(logs).to.deep.equal([ { value: { c: 2 }, keyChain: 'b', nodeInfo: { index: 0, count: 2, depth: 1, parent: { a: 1, b: { c: 2 } }, sort: fnSort, name: 'b', }, }, { value: 2, keyChain: 'b.c', nodeInfo: { index: 0, count: 1, depth: 2, parent: { c: 2 }, sort: fnSort, name: 'c', }, }, { value: 1, keyChain: 'a', nodeInfo: { index: 1, count: 2, depth: 1, parent: { a: 1, b: { c: 2 } }, sort: fnSort, name: 'a', }, }, ]); done(); }); it('Should process nothing when 1st arg is undefined', function (done) { var logs = []; var obj = undefined; var opts = {}; eachProps(obj, logger.bind(logs), opts); expect(obj).to.equal(undefined); expect(logs).to.deep.equal([]); done(); }); it('Should process nothing when 1st arg is null', function (done) { var logs = []; var obj = null; var opts = {}; eachProps(obj, logger.bind(logs), opts); expect(obj).to.equal(null); expect(logs).to.deep.equal([]); done(); }); it('Should process nothing when 1st arg is not a boolean', function (done) { var logs = []; var obj = true; var opts = {}; eachProps(obj, logger.bind(logs), opts); expect(obj).to.equal(true); expect(logs).to.deep.equal([]); done(); }); it('Should process nothing when 1st arg is a number', function (done) { var logs = []; var obj = 9; var opts = {}; eachProps(obj, logger.bind(logs), opts); expect(obj).to.equal(9); expect(logs).to.deep.equal([]); done(); }); it('Should process nothing when 1st arg is a string', function (done) { var logs = []; var obj = 'ABC'; var opts = {}; eachProps(obj, logger.bind(logs), opts); expect(obj).to.equal('ABC'); expect(logs).to.deep.equal([]); done(); }); it('Should process nothing when 1st arg is an array', function (done) { var logs = []; var obj = [{ a: 1 }, { b: 2 }, { c: 3 }]; var opts = {}; eachProps(obj, logger.bind(logs), opts); expect(obj).to.deep.equal([{ a: 1 }, { b: 2 }, { c: 3 }]); expect(logs).to.deep.equal([]); done(); }); it('Should process nothing when 1st arg is a function', function (done) { var logs = []; var obj = fnNoReturn; var opts = {}; eachProps(obj, logger.bind(logs), opts); expect(logs).to.deep.equal([]); done(); }); it('Should process nothing when 1st arg is a typed object', function (done) { var logs = []; var obj = new Date(0); var opts = {}; eachProps(obj, logger.bind(logs), opts); expect(logs).to.deep.equal([]); done(); }); it('Should process nothing when 1st arg is an empty plain object', function (done) { var logs = []; var obj = {}; var opts = {}; eachProps(obj, logger.bind(logs), opts); expect(obj).to.deep.equal({}); expect(logs).to.deep.equal([]); done(); }); it('Should process nothing when 2nd arg is undefined', function (done) { var obj = { a: 1 }; var fn = undefined; eachProps(obj, fn); expect(obj).to.deep.equal({ a: 1 }); done(); }); it('Should process nothing when 2nd arg is null', function (done) { var obj = { a: 1 }; var fn = null; eachProps(obj, fn); expect(obj).to.deep.equal({ a: 1 }); done(); }); it('Should process nothing when 2nd arg is a boolean', function (done) { var obj = { a: 1 }; var fn = true; eachProps(obj, fn); expect(obj).to.deep.equal({ a: 1 }); done(); }); it('Should process nothing when 2nd arg is a number', function (done) { var obj = { a: 1 }; var fn = 123; eachProps(obj, fn); expect(obj).to.deep.equal({ a: 1 }); done(); }); it('Should process nothing when 2nd arg is a string', function (done) { var obj = { a: 1 }; var fn = 'ABC'; eachProps(obj, fn); expect(obj).to.deep.equal({ a: 1 }); done(); }); it('Should process nothing when 2nd arg is an array', function (done) { var obj = { a: 1 }; var fn = ['A', 'B', 'C']; eachProps(obj, fn); expect(obj).to.deep.equal({ a: 1 }); done(); }); it('Should process nothing when 2nd arg is an plain object', function (done) { var obj = { a: 1 }; var fn = { a: 'A', b: 'B', c: 'C' }; eachProps(obj, fn); expect(obj).to.deep.equal({ a: 1 }); done(); }); it('Should process nothing when 2nd arg is an typed object', function (done) { var obj = { a: 1 }; var fn = new Date(0); eachProps(obj, fn); expect(obj).to.deep.equal({ a: 1 }); done(); }); it('Should process nothing when 3rd arg is undefined', function (done) { var logs = []; var obj = { a: 1, b: { c: 2 } }; var opts = undefined; eachProps(obj, logger.bind(logs), opts); expect(logs).to.deep.equal([ { value: 1, keyChain: 'a', nodeInfo: { index: 0, count: 2, depth: 1, parent: { a: 1, b: { c: 2 } }, name: 'a', }, }, { value: { c: 2 }, keyChain: 'b', nodeInfo: { index: 1, count: 2, depth: 1, parent: { a: 1, b: { c: 2 } }, name: 'b', }, }, { value: 2, keyChain: 'b.c', nodeInfo: { index: 0, count: 1, depth: 2, parent: { c: 2 }, name: 'c', }, }, ]); done(); }); it('Should process nothing when 3rd arg is null', function (done) { var logs = []; var obj = { a: 1, b: { c: 2 } }; var opts = null; eachProps(obj, logger.bind(logs), opts); expect(logs).to.deep.equal([ { value: 1, keyChain: 'a', nodeInfo: { index: 0, count: 2, depth: 1, parent: { a: 1, b: { c: 2 } }, name: 'a', }, }, { value: { c: 2 }, keyChain: 'b', nodeInfo: { index: 1, count: 2, depth: 1, parent: { a: 1, b: { c: 2 } }, name: 'b', }, }, { value: 2, keyChain: 'b.c', nodeInfo: { index: 0, count: 1, depth: 2, parent: { c: 2 }, name: 'c', }, }, ]); done(); }); it('Should process nothing when 3rd arg is a boolean', function (done) { var logs = []; var obj = { a: 1, b: { c: 2 } }; var opts = true; eachProps(obj, logger.bind(logs), opts); expect(logs).to.deep.equal([ { value: 1, keyChain: 'a', nodeInfo: { index: 0, count: 2, depth: 1, parent: { a: 1, b: { c: 2 } }, name: 'a', }, }, { value: { c: 2 }, keyChain: 'b', nodeInfo: { index: 1, count: 2, depth: 1, parent: { a: 1, b: { c: 2 } }, name: 'b', }, }, { value: 2, keyChain: 'b.c', nodeInfo: { index: 0, count: 1, depth: 2, parent: { c: 2 }, name: 'c', }, }, ]); done(); }); it('Should process nothing when 3rd arg is a number', function (done) { var logs = []; var obj = { a: 1, b: { c: 2 } }; var opts = 123; eachProps(obj, logger.bind(logs), opts); expect(logs).to.deep.equal([ { value: 1, keyChain: 'a', nodeInfo: { index: 0, count: 2, depth: 1, parent: { a: 1, b: { c: 2 } }, name: 'a', }, }, { value: { c: 2 }, keyChain: 'b', nodeInfo: { index: 1, count: 2, depth: 1, parent: { a: 1, b: { c: 2 } }, name: 'b', }, }, { value: 2, keyChain: 'b.c', nodeInfo: { index: 0, count: 1, depth: 2, parent: { c: 2 }, name: 'c', }, }, ]); done(); }); it('Should process nothing when 3rd arg is a string', function (done) { var logs = []; var obj = { a: 1, b: { c: 2 } }; var opts = 'ABC'; eachProps(obj, logger.bind(logs), opts); expect(logs).to.deep.equal([ { value: 1, keyChain: 'a', nodeInfo: { index: 0, count: 2, depth: 1, parent: { a: 1, b: { c: 2 } }, name: 'a', }, }, { value: { c: 2 }, keyChain: 'b', nodeInfo: { index: 1, count: 2, depth: 1, parent: { a: 1, b: { c: 2 } }, name: 'b', }, }, { value: 2, keyChain: 'b.c', nodeInfo: { index: 0, count: 1, depth: 2, parent: { c: 2 }, name: 'c', }, }, ]); done(); }); it('Should process nothing when 3rd arg is an array', function (done) { var logs = []; var obj = { a: 1, b: { c: 2 } }; var opts = [1, 2, 3]; eachProps(obj, logger.bind(logs), opts); expect(logs).to.deep.equal([ { value: 1, keyChain: 'a', nodeInfo: { index: 0, count: 2, depth: 1, parent: { a: 1, b: { c: 2 } }, name: 'a', }, }, { value: { c: 2 }, keyChain: 'b', nodeInfo: { index: 1, count: 2, depth: 1, parent: { a: 1, b: { c: 2 } }, name: 'b', }, }, { value: 2, keyChain: 'b.c', nodeInfo: { index: 0, count: 1, depth: 2, parent: { c: 2 }, name: 'c', }, }, ]); done(); }); it('Should process nothing when 3rd arg is a function', function (done) { var logs = []; var obj = { a: 1, b: { c: 2 } }; var opts = fnNoReturn; eachProps(obj, logger.bind(logs), opts); expect(logs).to.deep.equal([ { value: 1, keyChain: 'a', nodeInfo: { index: 0, count: 2, depth: 1, parent: { a: 1, b: { c: 2 } }, name: 'a', }, }, { value: { c: 2 }, keyChain: 'b', nodeInfo: { index: 1, count: 2, depth: 1, parent: { a: 1, b: { c: 2 } }, name: 'b', }, }, { value: 2, keyChain: 'b.c', nodeInfo: { index: 0, count: 1, depth: 2, parent: { c: 2 }, name: 'c', }, }, ]); done(); }); it('Should process nothing when 3rd arg is a typed object', function (done) { var logs = []; var obj = { a: 1, b: { c: 2 } }; var opts = new Date(0); eachProps(obj, logger.bind(logs), opts); expect(logs).to.deep.equal([ { value: 1, keyChain: 'a', nodeInfo: { index: 0, count: 2, depth: 1, parent: { a: 1, b: { c: 2 } }, name: 'a', }, }, { value: { c: 2 }, keyChain: 'b', nodeInfo: { index: 1, count: 2, depth: 1, parent: { a: 1, b: { c: 2 } }, name: 'b', }, }, { value: 2, keyChain: 'b.c', nodeInfo: { index: 0, count: 1, depth: 2, parent: { c: 2 }, name: 'c', }, }, ]); done(); }); it('Should process nothing when 3rd arg is an empty plain object', function (done) { var logs = []; var obj = { a: 1, b: { c: 2 } }; var opts = {}; eachProps(obj, logger.bind(logs), opts); expect(logs).to.deep.equal([ { value: 1, keyChain: 'a', nodeInfo: { index: 0, count: 2, depth: 1, parent: { a: 1, b: { c: 2 } }, name: 'a', }, }, { value: { c: 2 }, keyChain: 'b', nodeInfo: { index: 1, count: 2, depth: 1, parent: { a: 1, b: { c: 2 } }, name: 'b', }, }, { value: 2, keyChain: 'b.c', nodeInfo: { index: 0, count: 1, depth: 2, parent: { c: 2 }, name: 'c', }, }, ]); done(); }); it('Should not sort keys when `.sort` of 3rd arg is undefined', function (done) { var logs = []; var obj = { a: 1, b: { c: 2 } }; var opts = { sort: undefined }; eachProps(obj, logger.bind(logs), opts); expect(logs).to.deep.equal([ { value: 1, keyChain: 'a', nodeInfo: { index: 0, count: 2, depth: 1, parent: { a: 1, b: { c: 2 } }, sort: undefined, name: 'a', }, }, { value: { c: 2 }, keyChain: 'b', nodeInfo: { index: 1, count: 2, depth: 1, parent: { a: 1, b: { c: 2 } }, sort: undefined, name: 'b', }, }, { value: 2, keyChain: 'b.c', nodeInfo: { index: 0, count: 1, depth: 2, parent: { c: 2 }, sort: undefined, name: 'c', }, }, ]); done(); }); it('Should not sort keys when `.sort` of 3rd arg is null', function (done) { var logs = []; var obj = { a: 1, b: { c: 2 } }; var opts = { sort: null }; eachProps(obj, logger.bind(logs), opts); expect(logs).to.deep.equal([ { value: 1, keyChain: 'a', nodeInfo: { index: 0, count: 2, depth: 1, parent: { a: 1, b: { c: 2 } }, sort: null, name: 'a', }, }, { value: { c: 2 }, keyChain: 'b', nodeInfo: { index: 1, count: 2, depth: 1, parent: { a: 1, b: { c: 2 } }, sort: null, name: 'b', }, }, { value: 2, keyChain: 'b.c', nodeInfo: { index: 0, count: 1, depth: 2, parent: { c: 2 }, sort: null, name: 'c', }, }, ]); done(); }); it('Should not sort keys when `.sort` of 3rd arg is a boolean', function (done) { var logs = []; var obj = { a: 1, b: { c: 2 } }; var opts = { sort: true }; eachProps(obj, logger.bind(logs), opts); expect(logs).to.deep.equal([ { value: 1, keyChain: 'a', nodeInfo: { index: 0, count: 2, depth: 1, parent: { a: 1, b: { c: 2 } }, sort: true, name: 'a', }, }, { value: { c: 2 }, keyChain: 'b', nodeInfo: { index: 1, count: 2, depth: 1, parent: { a: 1, b: { c: 2 } }, sort: true, name: 'b', }, }, { value: 2, keyChain: 'b.c', nodeInfo: { index: 0, count: 1, depth: 2, parent: { c: 2 }, sort: true, name: 'c', }, }, ]); done(); }); it('Should not sort keys when `.sort` of 3rd arg is a number', function (done) { var logs = []; var obj = { a: 1, b: { c: 2 } }; var opts = { sort: 123 }; eachProps(obj, logger.bind(logs), opts); expect(logs).to.deep.equal([ { value: 1, keyChain: 'a', nodeInfo: { index: 0, count: 2, depth: 1, parent: { a: 1, b: { c: 2 } }, sort: 123, name: 'a', }, }, { value: { c: 2 }, keyChain: 'b', nodeInfo: { index: 1, count: 2, depth: 1, parent: { a: 1, b: { c: 2 } }, sort: 123, name: 'b', }, }, { value: 2, keyChain: 'b.c', nodeInfo: { index: 0, count: 1, depth: 2, parent: { c: 2 }, sort: 123, name: 'c', }, }, ]); done(); }); it('Should not sort keys when `.sort` of 3rd arg is a string', function (done) { var logs = []; var obj = { a: 1, b: { c: 2 } }; var opts = { sort: 'ABC' }; eachProps(obj, logger.bind(logs), opts); expect(logs).to.deep.equal([ { value: 1, keyChain: 'a', nodeInfo: { index: 0, count: 2, depth: 1, parent: { a: 1, b: { c: 2 } }, sort: 'ABC', name: 'a', }, }, { value: { c: 2 }, keyChain: 'b', nodeInfo: { index: 1, count: 2, depth: 1, parent: { a: 1, b: { c: 2 } }, sort: 'ABC', name: 'b', }, }, { value: 2, keyChain: 'b.c', nodeInfo: { index: 0, count: 1, depth: 2, parent: { c: 2 }, sort: 'ABC', name: 'c', }, }, ]); done(); }); it('Should not sort keys when `.sort` of 3rd arg is an array', function (done) { var logs = []; var obj = { a: 1, b: { c: 2 } }; var opts = { sort: [1, 2, 3] }; eachProps(obj, logger.bind(logs), opts); expect(logs).to.deep.equal([ { value: 1, keyChain: 'a', nodeInfo: { index: 0, count: 2, depth: 1, parent: { a: 1, b: { c: 2 } }, sort: [1, 2, 3], name: 'a', }, }, { value: { c: 2 }, keyChain: 'b', nodeInfo: { index: 1, count: 2, depth: 1, parent: { a: 1, b: { c: 2 } }, sort: [1, 2, 3], name: 'b', }, }, { value: 2, keyChain: 'b.c', nodeInfo: { index: 0, count: 1, depth: 2, parent: { c: 2 }, sort: [1, 2, 3], name: 'c', }, }, ]); done(); }); it('Should not sort keys when `.sort` of 3rd arg is a object', function (done) { var logs = []; var obj = { a: 1, b: { c: 2 } }; var opts = { sort: { x: 1 } }; eachProps(obj, logger.bind(logs), opts); expect(logs).to.deep.equal([ { value: 1, keyChain: 'a', nodeInfo: { index: 0, count: 2, depth: 1, parent: { a: 1, b: { c: 2 } }, sort: { x: 1 }, name: 'a', }, }, { value: { c: 2 }, keyChain: 'b', nodeInfo: { index: 1, count: 2, depth: 1, parent: { a: 1, b: { c: 2 } }, sort: { x: 1 }, name: 'b', }, }, { value: 2, keyChain: 'b.c', nodeInfo: { index: 0, count: 1, depth: 2, parent: { c: 2 }, sort: { x: 1 }, name: 'c', }, }, ]); done(); }); it( 'Should not sort keys when `.sort` of 3rd arg is a function which' + '\n\treturns nothing', function (done) { var logs = []; var obj = { a: 1, b: { c: 2 } }; var opts = { sort: fnNoReturn }; eachProps(obj, logger.bind(logs), opts); expect(logs).to.deep.equal([ { value: 1, keyChain: 'a', nodeInfo: { index: 0, count: 2, depth: 1, parent: { a: 1, b: { c: 2 } }, sort: fnNoReturn, name: 'a', }, }, { value: { c: 2 }, keyChain: 'b', nodeInfo: { index: 1, count: 2, depth: 1, parent: { a: 1, b: { c: 2 } }, sort: fnNoReturn, name: 'b', }, }, { value: 2, keyChain: 'b.c', nodeInfo: { index: 0, count: 1, depth: 2, parent: { c: 2 }, sort: fnNoReturn, name: 'c', }, }, ]); done(); } ); it( 'Should not sort keys when `.sort` of 3rd arg is a function which' + '\n\treturns null', function (done) { var logs = []; var obj = { a: 1, b: { c: 2 } }; var opts = { sort: fnReturnNull }; eachProps(obj, logger.bind(logs), opts); expect(logs).to.deep.equal([ { value: 1, keyChain: 'a', nodeInfo: { index: 0, count: 2, depth: 1, parent: { a: 1, b: { c: 2 } }, sort: fnReturnNull, name: 'a', }, }, { value: { c: 2 }, keyChain: 'b', nodeInfo: { index: 1, count: 2, depth: 1, parent: { a: 1, b: { c: 2 } }, sort: fnReturnNull, name: 'b', }, }, { value: 2, keyChain: 'b.c', nodeInfo: { index: 0, count: 1, depth: 2, parent: { c: 2 }, sort: fnReturnNull, name: 'c', }, }, ]); done(); } ); it( 'Should not sort keys when `.sort` of 3rd arg is a function which' + '\n\treturns a boolean', function (done) { var logs = []; var obj = { a: 1, b: { c: 2 } }; var opts = { sort: fnReturnBool }; eachProps(obj, logger.bind(logs), opts); expect(logs).to.deep.equal([ { value: 1, keyChain: 'a', nodeInfo: { index: 0, count: 2, depth: 1, parent: { a: 1, b: { c: 2 } }, sort: fnReturnBool, name: 'a', }, }, { value: { c: 2 }, keyChain: 'b', nodeInfo: { index: 1, count: 2, depth: 1, parent: { a: 1, b: { c: 2 } }, sort: fnReturnBool, name: 'b', }, }, { value: 2, keyChain: 'b.c', nodeInfo: { index: 0, count: 1, depth: 2, parent: { c: 2 }, sort: fnReturnBool, name: 'c', }, }, ]); done(); } ); it( 'Should not sort keys when `.sort` of 3rd arg is a function which' + '\n\treturns a number', function (done) { var logs = []; var obj = { a: 1, b: { c: 2 } }; var opts = { sort: fnReturnNum }; eachProps(obj, logger.bind(logs), opts); expect(logs).to.deep.equal([ { value: 1, keyChain: 'a', nodeInfo: { index: 0, count: 2, depth: 1, parent: { a: 1, b: { c: 2 } }, sort: fnReturnNum, name: 'a', }, }, { value: { c: 2 }, keyChain: 'b', nodeInfo: { index: 1, count: 2, depth: 1, parent: { a: 1, b: { c: 2 } }, sort: fnReturnNum, name: 'b', }, }, { value: 2, keyChain: 'b.c', nodeInfo: { index: 0, count: 1, depth: 2, parent: { c: 2 }, sort: fnReturnNum, name: 'c', }, }, ]); done(); } ); it( 'Should not sort keys when `.sort` of 3rd arg is a function which' + '\n\treturns a string', function (done) { var logs = []; var obj = { a: 1, b: { c: 2 } }; var opts = { sort: fnReturnStr }; eachProps(obj, logger.bind(logs), opts); expect(logs).to.deep.equal([ { value: 1, keyChain: 'a', nodeInfo: { index: 0, count: 2, depth: 1, parent: { a: 1, b: { c: 2 } }, sort: fnReturnStr, name: 'a', }, }, { value: { c: 2 }, keyChain: 'b', nodeInfo: { index: 1, count: 2, depth: 1, parent: { a: 1, b: { c: 2 } }, sort: fnReturnStr, name: 'b', }, }, { value: 2, keyChain: 'b.c', nodeInfo: { index: 0, count: 1, depth: 2, parent: { c: 2 }, sort: fnReturnStr, name: 'c', }, }, ]); done(); } ); it( 'Should not sort keys when `.sort` of 3rd arg is a function which' + '\n\treturns a function', function (done) { var logs = []; var obj = { a: 1, b: { c: 2 } }; var opts = { sort: fnReturnFunc }; eachProps(obj, logger.bind(logs), opts); expect(logs).to.deep.equal([ { value: 1, keyChain: 'a', nodeInfo: { index: 0, count: 2, depth: 1, parent: { a: 1, b: { c: 2 } }, sort: fnReturnFunc, name: 'a', }, }, { value: { c: 2 }, keyChain: 'b', nodeInfo: { index: 1, count: 2, depth: 1, parent: { a: 1, b: { c: 2 } }, sort: fnReturnFunc, name: 'b', }, }, { value: 2, keyChain: 'b.c', nodeInfo: { index: 0, count: 1, depth: 2, parent: { c: 2 }, sort: fnReturnFunc, name: 'c', }, }, ]); done(); } ); it( 'Should not sort keys when `.sort` of 3rd arg is a function which' + '\n\treturns an object', function (done) { var logs = []; var obj = { a: 1, b: { c: 2 } }; var opts = { sort: fnReturnObj }; eachProps(obj, logger.bind(logs), opts); expect(logs).to.deep.equal([ { value: 1, keyChain: 'a', nodeInfo: { index: 0, count: 2, depth: 1, parent: { a: 1, b: { c: 2 } }, sort: fnReturnObj, name: 'a', }, }, { value: { c: 2 }, keyChain: 'b', nodeInfo: { index: 1, count: 2, depth: 1, parent: { a: 1, b: { c: 2 } }, sort: fnReturnObj, name: 'b', }, }, { value: 2, keyChain: 'b.c', nodeInfo: { index: 0, count: 1, depth: 2, parent: { c: 2 }, sort: fnReturnObj, name: 'c', }, }, ]); done(); } ); }); })(); each-props-2.0.0/test/web/each-props-proc.js000066400000000000000000000135601413760304600206570ustar00rootroot00000000000000(function () { 'use strict'; var expect = chai.expect; function logger(value, keyChain, nodeInfo) { var log = {}; Object.keys(nodeInfo).forEach(function (key) { log[key] = nodeInfo[key]; }); delete log.parent; delete log.sort; delete log.return; log.keyChain = keyChain; this.push(log); if (nodeInfo.return) { return nodeInfo.return(keyChain); } } /* eslint max-statements: "off", brace-style: "off" */ describe('Processing test', function () { it('Should succeed when an input object is single depth', function (done) { var logs = []; var obj = { a: 1, b: 2, c: 3 }; eachProps(obj, logger.bind(logs)); expect(logs).to.deep.equal([ { keyChain: 'a', index: 0, count: 3, depth: 1, name: 'a' }, { keyChain: 'b', index: 1, count: 3, depth: 1, name: 'b' }, { keyChain: 'c', index: 2, count: 3, depth: 1, name: 'c' }, ]); done(); }); it('Should succeed when an input object is multiple depth', function (done) { var logs = []; var obj = { a: 1, b: { c: 'C', d: 'D', e: { f: 'F', g: 'G' } } }; eachProps(obj, logger.bind(logs)); expect(logs).to.deep.equal([ { keyChain: 'a', index: 0, count: 2, depth: 1, name: 'a' }, { keyChain: 'b', index: 1, count: 2, depth: 1, name: 'b' }, { keyChain: 'b.c', index: 0, count: 3, depth: 2, name: 'c' }, { keyChain: 'b.d', index: 1, count: 3, depth: 2, name: 'd' }, { keyChain: 'b.e', index: 2, count: 3, depth: 2, name: 'e' }, { keyChain: 'b.e.f', index: 0, count: 2, depth: 3, name: 'f' }, { keyChain: 'b.e.g', index: 1, count: 2, depth: 3, name: 'g' }, ]); done(); }); it('Should sort properties when a sort function is specified', function (done) { var logs = []; var obj = { q: 1, w: 2, e: 3, r: 4, t: 5, y: 6 }; var opts = { sort: function (arr) { return arr.sort(); }, }; eachProps(obj, logger.bind(logs), opts); expect(logs).to.deep.equal([ { keyChain: 'e', name: 'e', index: 0, count: 6, depth: 1 }, { keyChain: 'q', name: 'q', index: 1, count: 6, depth: 1 }, { keyChain: 'r', name: 'r', index: 2, count: 6, depth: 1 }, { keyChain: 't', name: 't', index: 3, count: 6, depth: 1 }, { keyChain: 'w', name: 'w', index: 4, count: 6, depth: 1 }, { keyChain: 'y', name: 'y', index: 5, count: 6, depth: 1 }, ]); done(); }); it( 'Should sort properties when an input object is multiple depth and' + '\n\ta sort function is specified', function (done) { var logs = []; var obj = { z: 1, x: { c: 'C', v: 'D', b: { n: 'F', m: 'G' } } }; var opts = { sort: function (arr) { return arr.sort(); }, }; eachProps(obj, logger.bind(logs), opts); expect(logs).to.deep.equal([ { name: 'x', keyChain: 'x', index: 0, count: 2, depth: 1 }, { name: 'b', keyChain: 'x.b', index: 0, count: 3, depth: 2 }, { name: 'm', keyChain: 'x.b.m', index: 0, count: 2, depth: 3 }, { name: 'n', keyChain: 'x.b.n', index: 1, count: 2, depth: 3 }, { name: 'c', keyChain: 'x.c', index: 1, count: 3, depth: 2 }, { name: 'v', keyChain: 'x.v', index: 2, count: 3, depth: 2 }, { name: 'z', keyChain: 'z', index: 1, count: 2, depth: 1 }, ]); done(); } ); it('Should Stop digging when the return value is true', function (done) { var logs = []; var obj = { z: 1, x: { c: 'C', v: 'D', b: { n: 'F', m: 'G' }, a: 'H' } }; var opts = { sort: function (arr) { return arr.sort(); }, return: function (keyChain) { return keyChain === 'x.b'; }, }; eachProps(obj, logger.bind(logs), opts); expect(logs).to.deep.equal([ { name: 'x', keyChain: 'x', index: 0, count: 2, depth: 1 }, { name: 'a', keyChain: 'x.a', index: 0, count: 4, depth: 2 }, { name: 'b', keyChain: 'x.b', index: 1, count: 4, depth: 2 }, { name: 'c', keyChain: 'x.c', index: 2, count: 4, depth: 2 }, { name: 'v', keyChain: 'x.v', index: 3, count: 4, depth: 2 }, { name: 'z', keyChain: 'z', index: 1, count: 2, depth: 1 }, ]); done(); }); it('Should pass properties in opts to all nodes', function (done) { var logs = []; var obj = { z: 1, x: { c: 'C', v: 'D', b: { n: 'F', m: 'G' } } }; var opts = { sort: function (arr) { return arr.sort(); }, m: 'ABC', n: 9, }; eachProps(obj, logger.bind(logs), opts); expect(logs).to.deep.equal([ { name: 'x', keyChain: 'x', index: 0, count: 2, depth: 1, m: 'ABC', n: 9, }, { name: 'b', keyChain: 'x.b', index: 0, count: 3, depth: 2, m: 'ABC', n: 9, }, { name: 'm', keyChain: 'x.b.m', index: 0, count: 2, depth: 3, m: 'ABC', n: 9, }, { name: 'n', keyChain: 'x.b.n', index: 1, count: 2, depth: 3, m: 'ABC', n: 9, }, { name: 'c', keyChain: 'x.c', index: 1, count: 3, depth: 2, m: 'ABC', n: 9, }, { name: 'v', keyChain: 'x.v', index: 2, count: 3, depth: 2, m: 'ABC', n: 9, }, { name: 'z', keyChain: 'z', index: 1, count: 2, depth: 1, m: 'ABC', n: 9, }, ]); done(); }); }); })(); each-props-2.0.0/test/web/make.js000066400000000000000000000010411413760304600165610ustar00rootroot00000000000000'use strict'; var fs = require('fs'); var path = require('path'); var opts = { encoding: 'utf-8' }; function make(filename) { fs.readFile(path.join(__dirname, '..', filename), opts, function (err, data) { throwIfError(err); data = data.replace(/[^\r\n]*require[^\r|\n]*/g, ''); data = '(function() {\n' + data + '}());\n'; fs.writeFile(path.join(__dirname, filename), data, opts, throwIfError); }); } function throwIfError(err) { if (err) { throw err; } } make('each-props-args.js'); make('each-props-proc.js'); each-props-2.0.0/web/000077500000000000000000000000001413760304600143335ustar00rootroot00000000000000each-props-2.0.0/web/each-props.js000066400000000000000000000244551413760304600167440ustar00rootroot00000000000000(function (f) { if (typeof exports === 'object' && typeof module !== 'undefined') { module.exports = f(); } else if (typeof define === 'function' && define.amd) { define([], f); } else { var g; if (typeof window !== 'undefined') { g = window; } else if (typeof global !== 'undefined') { g = global; } else if (typeof self !== 'undefined') { g = self; } else { g = this; } g.eachProps = f(); } })(function () { var define, module, exports; return (function () { function r(e, n, t) { function o(i, f) { if (!n[i]) { if (!e[i]) { var c = 'function' == typeof require && require; if (!f && c) return c(i, !0); if (u) return u(i, !0); var a = new Error("Cannot find module '" + i + "'"); throw ((a.code = 'MODULE_NOT_FOUND'), a); } var p = (n[i] = { exports: {} }); e[i][0].call( p.exports, function (r) { var n = e[i][1][r]; return o(n || r); }, p, p.exports, r, e, n, t ); } return n[i].exports; } for ( var u = 'function' == typeof require && require, i = 0; i < t.length; i++ ) o(t[i]); return o; } return r; })()( { 1: [ function (require, module, exports) { 'use strict'; var isPlainObject = require('is-plain-object').isPlainObject; var defaults = require('object.defaults/immutable'); module.exports = function (obj, fn, opts) { if (!isObject(obj)) { return; } if (typeof fn !== 'function') { return; } if (!isPlainObject(opts)) { opts = {}; } forEachChild(obj, '', fn, 0, opts); }; function forEachChild(node, baseKey, fn, depth, opts) { var keys = Object.keys(node); if (typeof opts.sort === 'function') { var sortedKeys = opts.sort(keys); if (Array.isArray(sortedKeys)) { keys = sortedKeys; } } depth += 1; for (var i = 0, n = keys.length; i < n; i++) { var key = keys[i]; var keyChain = baseKey + '.' + key; var value = node[key]; var nodeInfo = defaults(opts); nodeInfo.name = key; nodeInfo.index = i; nodeInfo.count = n; nodeInfo.depth = depth; nodeInfo.parent = node; var notDigg = fn(value, keyChain.slice(1), nodeInfo); if (notDigg || !isPlainObject(value)) { continue; } forEachChild(value, keyChain, fn, depth, opts); } } function isObject(v) { return Object.prototype.toString.call(v) === '[object Object]'; } }, { 'is-plain-object': 6, 'object.defaults/immutable': 8 }, ], 2: [ function (require, module, exports) { /*! * array-each * * Copyright (c) 2015, 2017, Jon Schlinkert. * Released under the MIT License. */ 'use strict'; /** * Loop over each item in an array and call the given function on every element. * * ```js * each(['a', 'b', 'c'], function(ele) { * return ele + ele; * }); * //=> ['aa', 'bb', 'cc'] * * each(['a', 'b', 'c'], function(ele, i) { * return i + ele; * }); * //=> ['0a', '1b', '2c'] * ``` * * @name each * @alias forEach * @param {Array} `array` * @param {Function} `fn` * @param {Object} `thisArg` (optional) pass a `thisArg` to be used as the context in which to call the function. * @return {undefined} * @api public */ module.exports = function each(arr, cb, thisArg) { if (arr == null) return; var len = arr.length; var idx = -1; while (++idx < len) { var ele = arr[idx]; if (cb.call(thisArg, ele, idx, arr) === false) { break; } } }; }, {}, ], 3: [ function (require, module, exports) { /*! * array-slice * * Copyright (c) 2014-2017, Jon Schlinkert. * Released under the MIT License. */ 'use strict'; module.exports = function slice(arr, start, end) { var len = arr.length; var range = []; start = idx(len, start); end = idx(len, end, len); while (start < end) { range.push(arr[start++]); } return range; }; function idx(len, pos, end) { if (pos == null) { pos = end || 0; } else if (pos < 0) { pos = Math.max(len + pos, 0); } else { pos = Math.min(pos, len); } return pos; } }, {}, ], 4: [ function (require, module, exports) { /*! * for-in * * Copyright (c) 2014-2017, Jon Schlinkert. * Released under the MIT License. */ 'use strict'; module.exports = function forIn(obj, fn, thisArg) { for (var key in obj) { if (fn.call(thisArg, obj[key], key, obj) === false) { break; } } }; }, {}, ], 5: [ function (require, module, exports) { /*! * for-own * * Copyright (c) 2014-2017, Jon Schlinkert. * Released under the MIT License. */ 'use strict'; var forIn = require('for-in'); var hasOwn = Object.prototype.hasOwnProperty; module.exports = function forOwn(obj, fn, thisArg) { forIn(obj, function (val, key) { if (hasOwn.call(obj, key)) { return fn.call(thisArg, obj[key], key, obj); } }); }; }, { 'for-in': 4 }, ], 6: [ function (require, module, exports) { 'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); /*! * is-plain-object * * Copyright (c) 2014-2017, Jon Schlinkert. * Released under the MIT License. */ function isObject(o) { return Object.prototype.toString.call(o) === '[object Object]'; } function isPlainObject(o) { var ctor, prot; if (isObject(o) === false) return false; // If has modified constructor ctor = o.constructor; if (ctor === undefined) return true; // If has modified prototype prot = ctor.prototype; if (isObject(prot) === false) return false; // If constructor does not have an Object-specific method if (prot.hasOwnProperty('isPrototypeOf') === false) { return false; } // Most likely a plain Object return true; } exports.isPlainObject = isPlainObject; }, {}, ], 7: [ function (require, module, exports) { /*! * isobject * * Copyright (c) 2014-2017, Jon Schlinkert. * Released under the MIT License. */ 'use strict'; module.exports = function isObject(val) { return ( val != null && typeof val === 'object' && Array.isArray(val) === false ); }; }, {}, ], 8: [ function (require, module, exports) { 'use strict'; var slice = require('array-slice'); var defaults = require('./mutable'); /** * Extends an empty object with properties of one or * more additional `objects` * * @name .defaults.immutable * @param {Object} `objects` * @return {Object} * @api public */ module.exports = function immutableDefaults() { var args = slice(arguments); return defaults.apply(null, [{}].concat(args)); }; }, { './mutable': 9, 'array-slice': 3 }, ], 9: [ function (require, module, exports) { 'use strict'; var each = require('array-each'); var slice = require('array-slice'); var forOwn = require('for-own'); var isObject = require('isobject'); /** * Extends the `target` object with properties of one or * more additional `objects` * * @name .defaults * @param {Object} `target` The target object. Pass an empty object to shallow clone. * @param {Object} `objects` * @return {Object} * @api public */ module.exports = function defaults(target, objects) { if (target == null) { return {}; } each(slice(arguments, 1), function (obj) { if (isObject(obj)) { forOwn(obj, function (val, key) { if (target[key] == null) { target[key] = val; } }); } }); return target; }; }, { 'array-each': 2, 'array-slice': 3, 'for-own': 5, isobject: 7 }, ], }, {}, [1] )(1); }); each-props-2.0.0/web/each-props.min.js000066400000000000000000000131331413760304600175150ustar00rootroot00000000000000!(function (t) { 'object' == typeof exports && 'undefined' != typeof module ? (module.exports = t()) : 'function' == typeof define && define.amd ? define([], t) : (('undefined' != typeof window ? window : 'undefined' != typeof global ? global : 'undefined' != typeof self ? self : this ).eachProps = t()); })(function () { return (function r(o, i, u) { function c(e, t) { if (!i[e]) { if (!o[e]) { var n = 'function' == typeof require && require; if (!t && n) return n(e, !0); if (f) return f(e, !0); throw ( (((n = new Error("Cannot find module '" + e + "'")).code = 'MODULE_NOT_FOUND'), n) ); } (n = i[e] = { exports: {} }), o[e][0].call( n.exports, function (t) { return c(o[e][1][t] || t); }, n, n.exports, r, o, i, u ); } return i[e].exports; } for ( var f = 'function' == typeof require && require, t = 0; t < u.length; t++ ) c(u[t]); return c; })( { 1: [ function (t, e, n) { 'use strict'; var b = t('is-plain-object').isPlainObject, d = t('object.defaults/immutable'); e.exports = function (t, e, n) { '[object Object]' !== Object.prototype.toString.call(t) || ('function' == typeof e && (function t(e, n, r, o, i) { var u = Object.keys(e); { var c; 'function' == typeof i.sort && ((c = i.sort(u)), Array.isArray(c) && (u = c)); } o += 1; for (var f = 0, a = u.length; f < a; f++) { var s = u[f], l = n + '.' + s, p = e[s], y = d(i); (y.name = s), (y.index = f), (y.count = a), (y.depth = o), (y.parent = e); y = r(p, l.slice(1), y); !y && b(p) && t(p, l, r, o, i); } })(t, '', e, 0, (n = !b(n) ? {} : n))); }; }, { 'is-plain-object': 6, 'object.defaults/immutable': 8 }, ], 2: [ function (t, e, n) { 'use strict'; e.exports = function (t, e, n) { if (null != t) for (var r = t.length, o = -1; ++o < r; ) { var i = t[o]; if (!1 === e.call(n, i, o, t)) break; } }; }, {}, ], 3: [ function (t, e, n) { 'use strict'; function i(t, e, n) { return (e = null == e ? n || 0 : e < 0 ? Math.max(t + e, 0) : Math.min(e, t)); } e.exports = function (t, e, n) { var r = t.length, o = []; for (e = i(r, e), n = i(r, n, r); e < n; ) o.push(t[e++]); return o; }; }, {}, ], 4: [ function (t, e, n) { 'use strict'; e.exports = function (t, e, n) { for (var r in t) if (!1 === e.call(n, t[r], r, t)) break; }; }, {}, ], 5: [ function (t, e, n) { 'use strict'; var i = t('for-in'), u = Object.prototype.hasOwnProperty; e.exports = function (n, r, o) { i(n, function (t, e) { if (u.call(n, e)) return r.call(o, n[e], e, n); }); }; }, { 'for-in': 4 }, ], 6: [ function (t, e, n) { 'use strict'; function r(t) { return '[object Object]' === Object.prototype.toString.call(t); } Object.defineProperty(n, '__esModule', { value: !0 }), (n.isPlainObject = function (t) { return ( !1 !== r(t) && (void 0 === (t = t.constructor) || (!1 !== r((t = t.prototype)) && !1 !== t.hasOwnProperty('isPrototypeOf'))) ); }); }, {}, ], 7: [ function (t, e, n) { 'use strict'; e.exports = function (t) { return null != t && 'object' == typeof t && !1 === Array.isArray(t); }; }, {}, ], 8: [ function (t, e, n) { 'use strict'; var r = t('array-slice'), o = t('./mutable'); e.exports = function () { var t = r(arguments); return o.apply(null, [{}].concat(t)); }; }, { './mutable': 9, 'array-slice': 3 }, ], 9: [ function (t, e, n) { 'use strict'; var r = t('array-each'), o = t('array-slice'), i = t('for-own'), u = t('isobject'); e.exports = function (n, t) { return null == n ? {} : (r(o(arguments, 1), function (t) { u(t) && i(t, function (t, e) { null == n[e] && (n[e] = t); }); }), n); }; }, { 'array-each': 2, 'array-slice': 3, 'for-own': 5, isobject: 7 }, ], }, {}, [1] )(1); }); //# sourceMappingURL=each-props.min.js.map each-props-2.0.0/web/each-props.min.js.map000066400000000000000000000105671413760304600203010ustar00rootroot00000000000000{"version":3,"sources":["each-props.js"],"names":["f","exports","module","define","amd","window","global","self","this","eachProps","r","e","n","t","o","i","c","require","u","a","Error","code","p","call","length","1","isPlainObject","defaults","obj","fn","opts","Object","prototype","toString","forEachChild","node","baseKey","depth","keys","sortedKeys","sort","Array","isArray","key","keyChain","value","nodeInfo","name","index","count","parent","notDigg","slice","is-plain-object","object.defaults/immutable","2","arr","cb","thisArg","len","idx","ele","3","pos","end","Math","max","min","start","range","push","4","5","forIn","hasOwn","hasOwnProperty","val","for-in","6","isObject","defineProperty","undefined","ctor","constructor","prot","7","8","args","arguments","apply","concat","./mutable","array-slice","9","each","forOwn","target","objects","array-each","for-own","isobject"],"mappings":"CAAA,SAAUA,GAAuB,iBAAVC,SAAoC,oBAATC,OAAsBA,OAAOD,QAAQD,IAA4B,mBAATG,QAAqBA,OAAOC,IAAKD,OAAO,GAAGH,IAAiC,oBAATK,OAAwBA,OAA+B,oBAATC,OAAwBA,OAA6B,oBAAPC,KAAsBA,KAAYC,MAAOC,UAAYT,IAA9T,CAAqU,WAAqC,OAAmB,SAASU,EAAEC,EAAEC,EAAEC,GAAG,SAASC,EAAEC,EAAEf,GAAG,IAAIY,EAAEG,GAAG,CAAC,IAAIJ,EAAEI,GAAG,CAAC,IAAIC,EAAE,mBAAmBC,SAASA,QAAQ,IAAIjB,GAAGgB,EAAE,OAAOA,EAAED,GAAE,GAAI,GAAGG,EAAE,OAAOA,EAAEH,GAAE,GAAkD,MAA1CI,EAAE,IAAIC,MAAM,uBAAuBL,EAAE,MAAaM,KAAK,mBAAmBF,EAAMG,EAAEV,EAAEG,GAAG,CAACd,QAAQ,IAAIU,EAAEI,GAAG,GAAGQ,KAAKD,EAAErB,QAAQ,SAASS,GAAoB,OAAOI,EAAlBH,EAAEI,GAAG,GAAGL,IAAeA,IAAIY,EAAEA,EAAErB,QAAQS,EAAEC,EAAEC,EAAEC,GAAG,OAAOD,EAAEG,GAAGd,QAAQ,IAAI,IAAIiB,EAAE,mBAAmBD,SAASA,QAAQF,EAAE,EAAEA,EAAEF,EAAEW,OAAOT,IAAID,EAAED,EAAEE,IAAI,OAAOD,EAA7b,CAA4c,CAACW,EAAE,CAAC,SAASR,EAAQf,EAAOD,gBAGz1B,IAAIyB,EAAgBT,EAAQ,mBAAmBS,cAC3CC,EAAWV,EAAQ,6BAEvBf,EAAOD,QAAU,SAAS2B,EAAKC,EAAIC,GAiDY,oBAAtCC,OAAOC,UAAUC,SAASV,KAhDnBK,IAII,mBAAPC,GAWb,SAASK,EAAaC,EAAMC,EAASP,EAAIQ,EAAOP,GAC9C,IAAIQ,EAAOP,OAAOO,KAAKH,GACvB,CAAA,IACMI,EADmB,mBAAdT,EAAKU,OACVD,EAAaT,EAAKU,KAAKF,GACvBG,MAAMC,QAAQH,KAChBD,EAAOC,IAIXF,GAAS,EAET,IAAK,IAAItB,EAAI,EAAGH,EAAI0B,EAAKd,OAAQT,EAAIH,EAAGG,IAAK,CAC3C,IAAI4B,EAAML,EAAKvB,GACX6B,EAAWR,EAAU,IAAMO,EAC3BE,EAAQV,EAAKQ,GAEbG,EAAWnB,EAASG,GACxBgB,EAASC,KAAOJ,EAChBG,EAASE,MAAQjC,EACjB+B,EAASG,MAAQrC,EACjBkC,EAAST,MAAQA,EACjBS,EAASI,OAASf,EAEdgB,EAAUtB,EAAGgB,EAAOD,EAASQ,MAAM,GAAIN,IACvCK,GAAYzB,EAAcmB,IAI9BX,EAAaW,EAAOD,EAAUf,EAAIQ,EAAOP,IA/B3CI,CAAaN,EAAK,GAAIC,EAAI,EAHxBC,GADGJ,EAAcI,GACV,GAGoBA,KAwC7B,CAACuB,kBAAkB,EAAEC,4BAA4B,IAAIC,EAAE,CAAC,SAAStC,EAAQf,EAAOD,gBAkClFC,EAAOD,QAAU,SAAcuD,EAAKC,EAAIC,GACtC,GAAW,MAAPF,EAKJ,IAHA,IAAIG,EAAMH,EAAIhC,OACVoC,GAAO,IAEFA,EAAMD,GAAK,CAClB,IAAIE,EAAML,EAAII,GACd,IAAwC,IAApCH,EAAGlC,KAAKmC,EAASG,EAAKD,EAAKJ,GAC7B,SAKJ,IAAIM,EAAE,CAAC,SAAS7C,EAAQf,EAAOD,gBAuBjC,SAAS2D,EAAID,EAAKI,EAAKC,GASrB,OAPED,EADS,MAAPA,EACIC,GAAO,EACJD,EAAM,EACTE,KAAKC,IAAIP,EAAMI,EAAK,GAEpBE,KAAKE,IAAIJ,EAAKJ,GAnBxBzD,EAAOD,QAAU,SAAeuD,EAAKY,EAAOJ,GAC1C,IAAIL,EAAMH,EAAIhC,OACV6C,EAAQ,GAKZ,IAHAD,EAAQR,EAAID,EAAKS,GACjBJ,EAAMJ,EAAID,EAAKK,EAAKL,GAEbS,EAAQJ,GACbK,EAAMC,KAAKd,EAAIY,MAEjB,OAAOC,IAeP,IAAIE,EAAE,CAAC,SAAStD,EAAQf,EAAOD,gBAUjCC,EAAOD,QAAU,SAAe2B,EAAKC,EAAI6B,GACvC,IAAK,IAAIf,KAAOf,EACd,IAA6C,IAAzCC,EAAGN,KAAKmC,EAAS9B,EAAIe,GAAMA,EAAKf,GAClC,QAKJ,IAAI4C,EAAE,CAAC,SAASvD,EAAQf,EAAOD,gBAUjC,IAAIwE,EAAQxD,EAAQ,UAChByD,EAAS3C,OAAOC,UAAU2C,eAE9BzE,EAAOD,QAAU,SAAgB2B,EAAKC,EAAI6B,GACxCe,EAAM7C,EAAK,SAASgD,EAAKjC,GACvB,GAAI+B,EAAOnD,KAAKK,EAAKe,GACnB,OAAOd,EAAGN,KAAKmC,EAAS9B,EAAIe,GAAMA,EAAKf,OAK3C,CAACiD,SAAS,IAAIC,EAAE,CAAC,SAAS7D,EAAQf,EAAOD,gBAY3C,SAAS8E,EAASjE,GAChB,MAA6C,oBAAtCiB,OAAOC,UAAUC,SAASV,KAAKT,GAVxCiB,OAAOiD,eAAe/E,EAAS,aAAc,CAAE4C,OAAO,IAmCtD5C,EAAQyB,cAtBR,SAAuBZ,GAGrB,OAAoB,IAAhBiE,EAASjE,UAIAmE,KADbC,EAAOpE,EAAEqE,eAKc,IAAnBJ,EADJK,EAAOF,EAAKlD,aAIiC,IAAzCoD,EAAKT,eAAe,oBAUxB,IAAIU,EAAE,CAAC,SAASpE,EAAQf,EAAOD,gBAUjCC,EAAOD,QAAU,SAAkB2E,GACjC,OAAc,MAAPA,GAA8B,iBAARA,IAA2C,IAAvBnC,MAAMC,QAAQkC,KAG/D,IAAIU,EAAE,CAAC,SAASrE,EAAQf,EAAOD,gBAGjC,IAAImD,EAAQnC,EAAQ,eAEhBU,EAAWV,EAAQ,aAYvBf,EAAOD,QAAU,WACf,IAAIsF,EAAOnC,EAAMoC,WACjB,OAAO7D,EAAS8D,MAAM,KAAM,CAAC,IAAIC,OAAOH,MAGxC,CAACI,YAAY,EAAEC,cAAc,IAAIC,EAAE,CAAC,SAAS5E,EAAQf,EAAOD,gBAG9D,IAAI6F,EAAO7E,EAAQ,cACfmC,EAAQnC,EAAQ,eAChB8E,EAAS9E,EAAQ,WACjB8D,EAAW9D,EAAQ,YAavBf,EAAOD,QAAU,SAAkB+F,EAAQC,GACzC,OAAc,MAAVD,EACK,IAGTF,EAAK1C,EAAMoC,UAAW,GAAI,SAAS5D,GAC7BmD,EAASnD,IACXmE,EAAOnE,EAAK,SAASgD,EAAKjC,GACL,MAAfqD,EAAOrD,KACTqD,EAAOrD,GAAOiC,OAMfoB,KAGP,CAACE,aAAa,EAAEN,cAAc,EAAEO,UAAU,EAAEC,SAAW,KAAK,GAAG,CAAC,GAtS+S,CAsS3S"}