package/package.json000644 0000002467 3560116604 011557 0ustar00000000 000000 { "name": "make-iterator", "description": "Convert an argument into a valid iterator. Based on the `.makeIterator()` implementation in mout https://github.com/mout/mout.", "version": "1.0.1", "homepage": "https://github.com/jonschlinkert/make-iterator", "author": "Jon Schlinkert (https://github.com/jonschlinkert)", "repository": "jonschlinkert/make-iterator", "bugs": { "url": "https://github.com/jonschlinkert/make-iterator/issues" }, "license": "MIT", "files": [ "index.js" ], "main": "index.js", "engines": { "node": ">=0.10.0" }, "scripts": { "test": "mocha" }, "dependencies": { "kind-of": "^6.0.2" }, "devDependencies": { "gulp-format-md": "^1.0.0", "mocha": "^3.5.3" }, "keywords": [ "arr", "array", "contains", "for-own", "forown", "forOwn", "function", "iterate", "iterator", "make" ], "verb": { "related": { "list": [ "any", "arr-filter", "arr-map", "array-every", "collection-map", "utils" ] }, "toc": false, "layout": "default", "tasks": [ "readme" ], "plugins": [ "gulp-format-md" ], "lint": { "reflinks": true }, "reflinks": [ "verb", "verb-readme-generator" ] } } package/index.js000644 0000003660 3560116604 010732 0ustar00000000 000000 /*! * make-iterator * * Copyright (c) 2014-2018, Jon Schlinkert. * Released under the MIT License. */ 'use strict'; var typeOf = require('kind-of'); module.exports = function makeIterator(target, thisArg) { switch (typeOf(target)) { case 'undefined': case 'null': return noop; case 'function': // function is the first to improve perf (most common case) // also avoid using `Function#call` if not needed, which boosts // perf a lot in some cases return (typeof thisArg !== 'undefined') ? function(val, i, arr) { return target.call(thisArg, val, i, arr); } : target; case 'object': return function(val) { return deepMatches(val, target); }; case 'regexp': return function(str) { return target.test(str); }; case 'string': case 'number': default: { return prop(target); } } }; function containsMatch(array, value) { var len = array.length; var i = -1; while (++i < len) { if (deepMatches(array[i], value)) { return true; } } return false; } function matchArray(arr, value) { var len = value.length; var i = -1; while (++i < len) { if (!containsMatch(arr, value[i])) { return false; } } return true; } function matchObject(obj, value) { for (var key in value) { if (value.hasOwnProperty(key)) { if (deepMatches(obj[key], value[key]) === false) { return false; } } } return true; } /** * Recursively compare objects */ function deepMatches(val, value) { if (typeOf(val) === 'object') { if (Array.isArray(val) && Array.isArray(value)) { return matchArray(val, value); } else { return matchObject(val, value); } } else { return val === value; } } function prop(name) { return function(obj) { return obj[name]; }; } function noop(val) { return val; } package/LICENSE000644 0000002100 3560116604 010256 0ustar00000000 000000 The MIT License (MIT) Copyright (c) 2014-2018, Jon Schlinkert. 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. package/README.md000644 0000010325 3560116604 010540 0ustar00000000 000000 # make-iterator [![NPM version](https://img.shields.io/npm/v/make-iterator.svg?style=flat)](https://www.npmjs.com/package/make-iterator) [![NPM monthly downloads](https://img.shields.io/npm/dm/make-iterator.svg?style=flat)](https://npmjs.org/package/make-iterator) [![NPM total downloads](https://img.shields.io/npm/dt/make-iterator.svg?style=flat)](https://npmjs.org/package/make-iterator) [![Linux Build Status](https://img.shields.io/travis/jonschlinkert/make-iterator.svg?style=flat&label=Travis)](https://travis-ci.org/jonschlinkert/make-iterator) > Convert an argument into a valid iterator. Based on the `.makeIterator()` implementation in mout https://github.com/mout/mout. Please consider following this project's author, [Jon Schlinkert](https://github.com/jonschlinkert), and consider starring the project to show your :heart: and support. ## Install Install with [npm](https://www.npmjs.com/): ```sh $ npm install --save make-iterator ``` Copyright (c) 2012, 2013 moutjs team and contributors (http://moutjs.com) ## Usage ```js var iterator = require('make-iterator'); ``` **Regex** ```js var arr = ['a', 'b', 'c', 'd', 'e', 'f']; var fn = iterator(/[a-c]/); console.log(arr.filter(fn)); //=> ['a', 'b', 'c']; ``` **Objects** ```js var fn = iterator({ a: 1, b: { c: 2 } }); console.log(fn({ a: 1, b: { c: 2, d: 3 } })); //=> true console.log(fn({ a: 1, b: { c: 3 } })); //=> false ``` ## About
Contributing Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](../../issues/new).
Running Tests Running and reviewing unit tests is a great way to get familiarized with a library and its API. You can install dependencies and run tests with the following command: ```sh $ npm install && npm test ```
Building docs _(This project's readme.md is generated by [verb](https://github.com/verbose/verb-generate-readme), please don't edit the readme directly. Any changes to the readme must be made in the [.verb.md](.verb.md) readme template.)_ To generate the readme, run the following command: ```sh $ npm install -g verbose/verb#dev verb-generate-readme && verb ```
### Related projects You might also be interested in these projects: * [any](https://www.npmjs.com/package/any): Returns `true` if a value exists in the given string, array or object. | [homepage](https://github.com/jonschlinkert/any "Returns `true` if a value exists in the given string, array or object.") * [arr-filter](https://www.npmjs.com/package/arr-filter): Faster alternative to javascript's native filter method. | [homepage](https://github.com/jonschlinkert/arr-filter "Faster alternative to javascript's native filter method.") * [arr-map](https://www.npmjs.com/package/arr-map): Faster, node.js focused alternative to JavaScript's native array map. | [homepage](https://github.com/jonschlinkert/arr-map "Faster, node.js focused alternative to JavaScript's native array map.") * [array-every](https://www.npmjs.com/package/array-every): Returns true if the callback returns truthy for all elements in the given array. | [homepage](https://github.com/jonschlinkert/array-every "Returns true if the callback returns truthy for all elements in the given array.") * [collection-map](https://www.npmjs.com/package/collection-map): Returns an array of mapped values from an array or object. | [homepage](https://github.com/jonschlinkert/collection-map "Returns an array of mapped values from an array or object.") * [utils](https://www.npmjs.com/package/utils): Fast, generic JavaScript/node.js utility functions. | [homepage](https://github.com/jonschlinkert/utils "Fast, generic JavaScript/node.js utility functions.") ### Author **Jon Schlinkert** * [LinkedIn Profile](https://linkedin.com/in/jonschlinkert) * [GitHub Profile](https://github.com/jonschlinkert) * [Twitter Profile](https://twitter.com/jonschlinkert) ### License Copyright © 2018, [Jon Schlinkert](https://github.com/jonschlinkert). Released under the [MIT License](LICENSE). *** _This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.6.0, on April 08, 2018._