{"_id":"101-es6","_rev":"18-3bfed5e80231e03eba8b57c196492bc8","name":"101-es6","time":{"modified":"2022-06-12T14:05:27.526Z","created":"2014-12-22T10:03:19.259Z","0.9.0":"2014-12-22T10:03:19.259Z","0.9.1":"2014-12-22T11:34:17.820Z","0.9.2":"2014-12-23T00:20:16.105Z","0.9.3":"2014-12-23T00:41:12.232Z","0.9.4":"2014-12-23T13:31:38.451Z","0.8.0":"2015-02-09T09:22:32.984Z"},"maintainers":[{"name":"tomekwi","email":"t.wiszniewski@gmail.com"}],"dist-tags":{"latest":"0.8.0"},"description":"common javascript utils that can be required selectively that assume es5+","readme":"![101](http://i.imgur.com/MFrmMt6.png)\n===\n[![NPM](https://nodei.co/npm/101.png?downloads=true&downloadRank=true&stars=true)](https://nodei.co/npm/101/)\n[![Build Status](https://travis-ci.org/tjmehta/101.svg?branch=master)](https://travis-ci.org/tjmehta/101)\n[![Coverage Status](https://coveralls.io/repos/tjmehta/101/badge.png)](https://coveralls.io/r/tjmehta/101)\n\n# Why another JS util library?\n### 1) 101 will be maintained to minimize overlap with vanilla JS.\n* 101 utils are made to work well with vanilla JS methods.\n* 101 will only duplicate vanilla JS to provide Functional Programming paradigms, or if\nthe method is not available in a widely supported JS version (currently ES5).\n* Other libraries often duplicate a lot of ES5: forEach, map, reduce, filter, sort, and more.\n\n### 2) No need for custom builds.\n* With 101, import naturally, and what you use will be bundled.\n* Each util method is a module that can be required `require('101/<util>')`.\n* Currently node/browserify is supported, I will add other module system support on request.\n* Other libraries can be large, and require manually creating custom builds when optimizing for size.\n\n### Why not release each as individual modules?\nI ussually agree with this philosophy; however, while in practice, adherence to the module-pattern  \ncan become quite annoying for micro-modules (like those in 101):\n* Micro-modules existance throughout a project can change very frequently, because of this one may find\nthemselves constantly updating their package.json (repeatedly adding and removing the same micro-modules).\n* Unbundling micro-modules can lead to projects with 100's of dependencies which can be tedious to maintain.\n\n\n\n# Installation\n\n`npm install 101`\n\n# Usage\n\n## assign (aka extend)\n\nJust like ES6's `Object.assign`. Extend an object with any number of objects (returns original).\n\n```js\nimport assign from '101/assign';\n\nvar target = { foo: 1 };\nvar source1 = { bar: 1 };\nvar source2 = { baz: 1 };\nassign(target, source1) // { foo: 1, bar: 1, baz: 1 } target extended with source objects\nassign(target, source1, source2) // { foo: 1, bar: 1, baz: 1 } target extended with source objects\n```\n\n## and\n\nFunctional version of `&&`. Works great with `array.reduce`.\n\n```js\nimport and from '101/and';\n\nand(true, false); // false\nand(true, true);  // true\n```\n\n## apply\n\nFunctional version of `function.apply`.\nSupports partial functionality (great with array functions).\n\n```js\nimport apply from '101/apply';\n[sum].map(apply(null, [1, 2, 3])); // [6] = [sum(1,2,3)] = [1+2+3]\nfunction sum () {  /* sums all arguments */ }\napply({ prop: 'val' })(function () { return this.prop; });  // 'val'\n```\n\n## clone\n\nIt's [clone](https://www.npmjs.org/package/clone) (Only exporting this bc it is used internal to 101)\n\n```js\nimport clone from '101/clone';\nvar obj = {\n  foo: 1,\n  bar: 2\n};\n\nclone(obj); // { foo: 1, bar: 2 }\n```\n\n## compose\n\nFunctional composition method. Works great with `array.reduce`.\n\n```js\nimport compose from '101/compose';\n\ncompose(isNaN, parseInt)('nope'); // isNaN(parseInt('nope')) // true\n```\n\n## envIs\n\nFunctional version of `str === process.env.NODE_ENV`.\nOr's multiple environments.\n\n```js\nimport envIs from '101/env-is';\n// process.env.NODE_ENV = development\nenvIs('development');     // true\nenvIs('production');      // false\nenvIs('staging', 'production');     // false\nenvIs('development', 'production'); // true\n```\n\n## equals\n\nFunctional version of `===`.\nSupports partial functionality (great with array functions).\n\n```js\nimport equals from '101/equals';\n\nequals(1, 1);            // true\n[1,2,3].some(equals(1)); // true\nequals(1, '1');          // false\n```\n\n## exists\n\nSimple exists function.\n\n```js\nimport exists from '101/exists';\n\nexists('foo');     // true\nexists(null);      // false\nexists(undefined); // false\n```\n\n## find\n\nJust like ES6's `array.find`.\n\nFinds the first value in the list that passes the given function (predicate) and returns it.\nIf list is not provided find will return a partial-function which accepts a list as the first argument.\n\n```js\nimport find from '101/find';\nimport hasProps from '101/has-properties';\nvar arr = [{ a: 1, b: 1 }, { b: 1 }, { c: 1 }];\n\nvar item = find(arr, hasProps({ a:1 }));\n// returns { a: 1, b: 1 }\n// returns null if not found\n```\n\n## findIndex\n\nJust like ES6's `array.findIndex`.\n\nFinds the first value in the list that passes the given function (predicate) and returns it's index.\nIf list is not provided findIndex will return a partial-function which accepts a list as the first argument.\n\n```js\nimport findIndex from '101/find-index';\nvar arr = [1, 2, 3];\n\nvar index = findIndex(arr, function (val, i, arr) {\n  return val === 2;\n});\n// returns 1\n// returns -1 if not found\n```\n\n## hasKeypaths\n\nDetermines whether the keypaths exist and have the specified values.\nSupports partial functionality (great with array functions, and 101/find).\n\n```js\nimport hasKeypaths from '101/has-keypaths';\nvar obj = {\n  foo: {\n    bar: {\n      qux: 1\n    }\n  }\n};\n\nhasKeypaths(obj, ['foo.bar.qux']);      // true\nhasKeypaths(obj, { 'foo.bar.qux': 1 }); // true\nhasKeypaths(obj, ['foo.qux']);          // false\nhasKeypaths(obj, { 'foo.bar': 2 });     // false\nhasKeypaths(obj, { 'foo.bar': 1, 'nope': 1 }); // false\n\n// optional 'deep' arg, defaults to true\nvar barObj = { bar: 1 };\nhasKeypaths(obj, { 'foo.bar': barObj });         // true\nhasKeypaths(obj, { 'foo.bar': barObj }, true);   // true\nhasKeypaths(obj, { 'foo.bar': barObj }, false);  // false\nhasKeypaths(obj, { 'foo.bar': obj.foo }, false); // true\nhasKeypaths(obj, ['foo.bar'], false);            // true, uses [hasOwnProperty vs in](http://stackoverflow.com/questions/13632999/if-key-in-object-or-ifobject-hasownpropertykey)\n// use it with find, findIndex, or filter!\nvar arr = [obj, { b: 1 }, { c: 1 }];\nfind(arr, hasProps({ 'foo.bar.qux':1 })); // { foo: { bar: { qux: 1 } } }\nfind(arr, hasProps(['foo.bar.qux']));     // { foo: { bar: { qux: 1 } } }\n```\n\n## hasProperties\n\nDetermines whether the keys exist and, if specified, has the values.\nSupports partial functionality (great with array functions, and 101/find).\n\n```js\nimport hasProps from '101/has-properties';\nvar obj = {\n  foo: {\n    bar: 1\n  },\n  qux: 1\n};\n\nhasProps(obj, ['foo', 'qux']); // true\nhasProps(obj, { qux: 1 }) // true\n\n// optional 'deep' arg, defaults to true\nvar barObj = { bar: 1 };\nhasProps(obj, { 'foo.bar': barObj });         // true\nhasProps(obj, { 'foo.bar': barObj }, true);   // true\nhasProps(obj, { 'foo.bar': barObj }, false);  // false\nhasProps(obj, ['foo.bar'], false);            // true, uses [hasOwnProperty vs in](http://stackoverflow.com/questions/13632999/if-key-in-object-or-ifobject-hasownpropertykey)\n// use it with find, findIndex, or filter!\nvar arr = [{ a: 1, b: 1 }, { b: 1 }, { c: 1 }];\nfind(arr, hasProps({ a:1 })); // { a: 1, b: 1 }\nfind(arr, hasProps(['a']));   // { a: 1, b: 1 }\n```\n\n## instanceOf\n\nFunctional version of JavaScript's instanceof.\nSupports partial functionality (great with array functions).\n\n```js\nimport instanceOf from '101/instance-of';\n\n['foo', 'bar', 1].map(instanceOf('string')); // [true, true, false]\n```\n\n## isBoolean\n\nFunctional version of `typeof val === 'boolean'`.\nSupports partial functionality (great with array functions).\n\n```js\nimport isBoolean from '101/is-boolean';\n\n[true, false, 1].map(isBoolean); // [true, true, false]\n```\n\n## isEmpty\n\nFunctional version of val empty object, array or object\n\n```js\nimport isEmpty from '101/is-empty';\n\nisEmpty([]); // true\nisEmpty({}); // true\nisEmpty(\"\"); // true\nisEmpty(\" \"); // false\n```\n\n## isFunction\n\nFunctional version of `typeof val === 'function'`\n\n```js\nimport isFunction from '101/is-function';\n\n[parseInt, function () {}, 'foo'].map(isFunction); // [true, true, false]\n```\n\n## isNumber\n\nFunctional version of val typeof 'number'\n\n```js\nimport isNumber from '101/is-number';\n\n['foo', 'bar', 1].map(isString); // [false, false, true]\n```\n\n## isObject\n\nFunctional *strict* version of val typeof 'object' (and not array or regexp)\n\n```js\nimport isObject from '101/is-object';\n\n[{}, { foo: 1 }, 100].map(isObject); // [true, true, false]\n```\n\n## isString\n\nFunctional version of val typeof 'string'\n\n```js\nimport isString from '101/is-string';\n\n['foo', 'bar', 1].map(isString); // [true, true, false]\n```\n\n## last\n\nReturns the last value of a list\n\n```js\nimport last from '101/last';\n\nlast([1, 2, 3]); // 3\nlast('hello');   // 'o'\n```\n\n## noop\n\nNo-op function\n\n```js\nrequire('101/noop'); // function () {}\n```\n\n## not\n\nFunctional version of `!`.\n\n```js\nimport not from '101/not';\n\nnot(isString)('hey'); // false\nnot(isString)(100);   // true\n```\n\n## omit\n\nReturns a new object without the specified keys.\nSupports partial functionality (great with array functions, like map).\n\n```js\nimport omit from '101/omit';\nvar obj = {\n  foo: 1,\n  bar: 2\n};\n\nomit(obj, 'foo');          // { bar: 1 }\nomit(obj, ['foo']);        // { bar: 1 }\nomit(obj, ['foo', 'bar']); // { }\n\n// use it with array.map\n[obj, obj, obj].map(omit('foo')); // [{ bar: 1 }, { bar: 1 }, { bar: 1 }];\n```\n\n## or\n\nFunctional version of `||`.\nWorks great with `array.reduce`.\n\n```js\nimport or from '101/or';\n\nor(true, true);   // true\nor(true, false);  // true\nor(false, false); // false\n```\n\n## passAll\n\nMuxes arguments across many functions and `&&`'s the results.\nSupports partial functionality (great with array functions, like map).\n\n```js\nimport passAll from '101/pass-all';\n\n['', 'foo', 'bar', 100].map(passAll(isString, isTruthy)); // [false, true, true, false]\n```\n\n## passAny\n\nMuxes arguments across many functions and `||`'s the results.\nSupports partial functionality (great with array functions, like map).\n\n```js\nimport passAny from '101/pass-any';\n\n['', 'foo', 'bar', 100].map(passAny(isString, isNumber)); // [true, true, true, true]\n```\n\n## pick\n\nReturns a new object with the specified keys (with key values from obj).\nSupports partial functionality (great with array functions, like map).\n\n```js\nimport pick from '101/pick';\nvar obj = {\n  foo: 1,\n  bar: 2\n};\n\npick(obj, 'foo');          // { foo: 1 }\npick(obj, ['foo']);        // { foo: 1 }\npick(obj, ['foo', 'bar']); // { foo: 1, bar: 2 }\n\n// use it with array.map\n[obj, obj, obj].map(pick('foo')); // [{ foo: 1 }, { foo: 1 }, { foo: 1 }];\n```\n\n## pluck\n\nFunctional version of obj[key], returns the value of the key from obj.\nSupports partial functionality (great with array functions, like map).\n\n```js\nimport pluck from '101/pluck';\nvar obj = {\n  foo: 1,\n  bar: 2\n};\n\npluck(obj, 'foo'); // 1\n\n// use it with array.map\n[obj, obj, obj].map(pluck('foo')); // [1, 1, 1]\n\n// supports keypaths by default\nvar obj = {\n  foo: {\n    bar: 1\n  },\n  'foo.bar': 2\n};\n\npluck(obj, 'foo.bar'); // 1, supports keypaths by default\npluck(obj, 'foo.bar', false); // 2, pass false to not use keypaths\n```\n\n## set\n\nFunctional version of obj[key] = val, returns a new obj with the key and value set.\nSupports partial functionality (great with array functions, like map).\n\n```js\nimport set from '101/set';\nvar obj = {\n  foo: 1,\n  bar: 2\n};\n\nset(obj, 'foo'); // 1\n\n// use it with array.map\n[obj, obj, obj].map(set('foo', 100)); // [{ foo: 100, bar: 2 }, {same}, {same}]\n\n// supports keypaths by default\nvar obj = {\n  foo: 1,\n  bar: 2\n};\n\nset(obj, 'foo', 100); // { foo: 100, bar:2 }\n```\n\n## License\n\nMIT\n","versions":{"0.8.0":{"name":"101-es6","version":"0.8.0","description":"common javascript utils that can be required selectively that assume es5+","main":"index.js","scripts":{"test":"lab -c test","test-watch":"nodemon --exec lab -c test"},"repository":{"type":"git","url":"https://github.com/tjmehta/101"},"keywords":["utils","js","helpers","functional","pick","pluck","map","array","object","string"],"author":{"name":"Tejesh Mehta"},"license":"MIT","bugs":{"url":"https://github.com/tjmehta/101/issues"},"homepage":"https://github.com/tjmehta/101","devDependencies":{"coveralls":"^2.11.2","lab":"^4.6.2"},"dependencies":{"clone":"^0.1.18","deep-eql":"^0.1.3","extend":"^1.3.0","keypather":"^1.7.5"},"gitHead":"e67510234bc0e5947dc93cdb255c2254de96a592","_id":"101-es6@0.8.0","_shasum":"be6426ece3b64c4c3f78a4071c7fabaf3548431d","_from":".","_npmVersion":"2.2.0","_nodeVersion":"0.10.33","_npmUser":{"name":"tomekwi","email":"t.wiszniewski@gmail.com"},"maintainers":[{"name":"tomekwi","email":"t.wiszniewski@gmail.com"}],"dist":{"shasum":"be6426ece3b64c4c3f78a4071c7fabaf3548431d","tarball":"https://registry.npmjs.org/101-es6/-/101-es6-0.8.0.tgz","integrity":"sha512-sxj7qTior79DauakUElao7yNtok2lGZILttx31WgXwxPftD7aC2hRNV9rA+WYafDWOaqnFbOUHFPEVobMyh7hA==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQD5lRBNft3lCST2FY12Tz/inhL8bU/Ok8ZWrOWBy794twIgSbFRg+EdIyb93zj2zL+vbVlnwJrHAjcSyY5fElPtR2c="}]}}},"homepage":"https://github.com/tjmehta/101","keywords":["utils","js","helpers","functional","pick","pluck","map","array","object","string"],"repository":{"type":"git","url":"https://github.com/tjmehta/101"},"author":{"name":"Tejesh Mehta"},"bugs":{"url":"https://github.com/tjmehta/101/issues"},"license":"MIT","readmeFilename":"README.md"}