{"_id":"101-tomekwi","_rev":"6-f19c4e73600478063ba584ebeac51455","name":"101-tomekwi","description":"common javascript utils that can be required selectively that assume es5+","dist-tags":{"latest":"0.12.0"},"versions":{"0.1.0":{"name":"101-tomekwi","version":"0.1.0","description":"common javascript utils that can be required selectively that assume es5+","main":"index.js","scripts":{"test":"lab -c -t 100 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","keypather":"^1.8.1"},"gitHead":"363d8b05372329eb62f3fde14019a78b17bb2d56","_id":"101-tomekwi@0.1.0","_shasum":"a02e66f545fc6dbdabf3e2efa2f6369b57b05bba","_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":"a02e66f545fc6dbdabf3e2efa2f6369b57b05bba","tarball":"https://registry.npmjs.org/101-tomekwi/-/101-tomekwi-0.1.0.tgz","integrity":"sha512-B+mhnGaW8fEH5MzMFuIuGzbPJx/sBFkVK7ZUMrph4qBO56Se2Vbaishk6cO8YD2FOYUdQEkdfkYVMGrLjkcjQA==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIHTttcQ2zrgRsvhEgNtHwCvvZgtVOTG9Ab5fVuWPdgS8AiEAyRSvPci5ZTj8j9l3xlQFY+8MPANDNdd8g0VmqI7XJLU="}]}},"0.12.0":{"name":"101-tomekwi","version":"0.12.0","description":"common javascript utils that can be required selectively that assume es5+","main":"index.js","scripts":{"test":"lab -c -t 100 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","keypather":"^1.8.1"},"gitHead":"8e819045daedf2c7f6a40a797e6955aaab994f34","_id":"101-tomekwi@0.12.0","_shasum":"4cf553d9d638d5827f2f0a267b43b459ec8d80cc","_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":"4cf553d9d638d5827f2f0a267b43b459ec8d80cc","tarball":"https://registry.npmjs.org/101-tomekwi/-/101-tomekwi-0.12.0.tgz","integrity":"sha512-9pGN4eb1vr9Z3a7acLDgJCtH2XhSSq0gjKjz+RkkNSNv64PWV6yeziTP4/XveEJR9yQSwpHk7zmVFGdUNiluDw==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIFr2kSph6TxwhGby3xRYKqJgzudGl/DRXLl3q8+/5oYUAiB6c0G0koR2ADwnZ8PJ4FacX33emPNwRcjHzB1IRr1YhA=="}]}}},"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 usually 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 hundreds 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\nvar assign = require('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\nvar and = require('101/and');\n\nand(true, false); // false\nand(true, true);  // true\nand(true, \"foo\");  // \"foo\"\n```\n\n## apply\n\nFunctional version of `function.apply`.\nSupports partial functionality (great with array functions).\n\n```js\nvar apply = require('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\nvar clone = require('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\nvar compose = require('101/compose');\n\ncompose(isNaN, parseInt)('nope'); // isNaN(parseInt('nope')) // true\n```\n\n## converge\n\nConverges an array of functions into one. Works great with `compose`.\n\n```js\nvar converge = require('101/converge');\n\nconverge(mul, [add, sub])(6, 2); // mul(add(6, 2), sub(6, 2)) // (6+2) * (6-2) = 36\n\n[ {a: true, b: false}\n, {a: false, b: false}\n, {a: true, b: true}\n].filter(converge(and , [pluck(\"a\") , pluck(\"b\")])); // [{a: true, b: true}]\n\n[f, converge(g, [h, i]), j].reduce(compose); // f(g(h(j), i(j)))\n```\n\n## curry\n\nReturns a curried function.\n\n```js\nvar curry = require('101/curry');\n\nfunction add(a, b) { return a + b; }\n\nvar curriedAdd = curry(add);\nvar add2 = curriedAdd(2);\n\nadd2(6); // 8\nadd2(8); // 10\n\nfunction join() { return Array.prototype.slice.call(arguments).join(''); }\n\ncurry(join, 3)(1)(0)(1); // \"101\"\n```\n\n## envIs\n\nFunctional version of `str === process.env.NODE_ENV`.\nOr's multiple environments.\n\n```js\nvar envIs = require('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\nvar equals = require('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\nvar exists = require('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\nvar find = require('101/find');\nvar hasProps = require('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\nvar findIndex = require('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\nvar hasKeypaths = require('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).\nNOTE: I am considering deprecating this method, bc it is so similar to has-keypaths.\n\n```js\nvar hasProps = require('101/has-properties');\nvar obj = {\n  qux: 1\n};\nobj['foo.bar'] = 1\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\nvar instanceOf = require('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\nvar isBoolean = require('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\nvar isEmpty = require('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\nvar isFunction = require('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\nvar isNumber = require('101/is-number');\n\n['foo', 'bar', 1].map(isNumber); // [false, false, true]\n```\n\n## isObject\n\nFunctional *strict* version of val typeof 'object' (and not array or regexp)\n\n```js\nvar isObject = require('101/is-object');\n\n[{}, { foo: 1 }, 100].map(isObject); // [true, true, false]\n```\n\n## isRegExp\n\nCheck if a value is an instance of RegExp\n\n```js\nvar isRegExp = require('101/is-regexp');\n\n[new RegExp('.*'), /.*/, {}, 1].map(isRegExp); // [true, true, false, false]\n```\n\n## isString\n\nFunctional version of val typeof 'string'\n\n```js\nvar isString = require('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\nvar last = require('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\nvar not = require('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\nvar omit = require('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\nvar or = require('101/or');\n\nor(true, true);   // true\nor(true, false);  // true\nor(false, false); // false\nor(\"foo\", false); // \"foo\"\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\nvar passAll = require('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\nvar passAny = require('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 regular expressions and partial functionality (great with array functions, like map).\n\n```js\nvar pick = require('101/pick');\nvar obj = {\n  foo: 1,\n  bar: 2\n};\n\npick(obj, 'foo');          // { foo: 1 }\npick(obj, RegExp('oo$'));  // { 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\nvar pluck = require('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\nvar set = require('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## xor\n\nExclusive or\nWorks great with `array.reduce`.\n\n```js\nvar xor = require('101/xor');\n\nxor(true, true);   // false\nxor(true, false);  // true\nxor(false, true);  // true\nxor(false, false); // false\n```\n\n## License\n\nMIT\n","maintainers":[{"name":"tomekwi","email":"t.wiszniewski@gmail.com"}],"time":{"modified":"2022-06-12T14:05:27.770Z","created":"2015-02-17T11:52:19.995Z","0.1.0":"2015-02-17T11:52:19.995Z","0.12.0":"2015-02-17T11:53:00.535Z"},"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"}