{"versions":{"0.0.4":{"name":"get-closest","description":"Compare your item to items in an array and get the closest one.","version":"0.0.4","homepage":"https://github.com/cosmosio/get-closest","licenses":[{"type":"MIT","url":"https://raw.github.com/cosmosio/get-closest/master/LICENSE"}],"files":["LICENSE","index.js"],"author":{"name":"Olivier Scherrer","email":"pode.fr@gmail.com"},"keywords":["get","closest","item","array","compare"],"repository":{"type":"git","url":"git+ssh://git@github.com/cosmosio/get-closest.git"},"bugs":{"url":"https://github.com/cosmosio/get-closest/issues"},"scripts":{"test":"mocha"},"main":"index.js","devDependencies":{"chai":"~1.9.1","mocha":"~1.18.2","levenshtein":"~1.0.4"},"gitHead":"6ab29a0f47c56116e78ce47a4f31b0e47a0be246","_id":"get-closest@0.0.4","_shasum":"269ac776d1e6022aa0fd586dd708e8a7d32269af","_from":".","_npmVersion":"4.1.2","_nodeVersion":"7.7.2","_npmUser":{"name":"anonymous","email":"pode.fr@gmail.com"},"maintainers":[{"name":"anonymous","email":"pode.fr@gmail.com"}],"dist":{"shasum":"269ac776d1e6022aa0fd586dd708e8a7d32269af","size":2914,"noattachment":false,"tarball":"http://123.232.10.234:8212/nexus/content/groups/npm-public/get-closest/-/get-closest-0.0.4.tgz"},"_npmOperationalInternal":{"host":"packages-12-west.internal.npmjs.com","tmp":"tmp/get-closest-0.0.4.tgz_1489376236255_0.8894808292388916"},"directories":{},"publish_time":1489376238254,"_cnpm_publish_time":1489376238254,"_hasShrinkwrap":false,"contributors":[]},"0.0.3":{"name":"get-closest","description":"Compare your item to items in an array and get the closest one.","version":"0.0.3","homepage":"https://github.com/cosmosio/get-closest","licenses":[{"type":"MIT","url":"https://raw.github.com/cosmosio/get-closest/master/LICENSE"}],"files":["LICENSE","index.js"],"author":{"name":"Olivier Scherrer","email":"pode.fr@gmail.com"},"keywords":["get","closest","item","array","compare"],"repository":{"type":"git","url":"git+ssh://git@github.com/cosmosio/get-closest.git"},"bugs":{"url":"https://github.com/cosmosio/get-closest/issues"},"scripts":{"test":"mocha"},"main":"index.js","devDependencies":{"chai":"~1.9.1","mocha":"~1.18.2","levenshtein":"~1.0.4"},"gitHead":"84fd9984dc6a073fa6dac728d7321fe3fb6df836","_id":"get-closest@0.0.3","_shasum":"9fa5a030a87a069399e6ed440090cac8f7647777","_from":".","_npmVersion":"3.7.3","_nodeVersion":"5.8.0","_npmUser":{"name":"anonymous","email":"pode.fr@gmail.com"},"maintainers":[{"name":"anonymous","email":"pode.fr@gmail.com"}],"dist":{"shasum":"9fa5a030a87a069399e6ed440090cac8f7647777","size":2861,"noattachment":false,"tarball":"http://123.232.10.234:8212/nexus/content/groups/npm-public/get-closest/-/get-closest-0.0.3.tgz"},"_npmOperationalInternal":{"host":"packages-16-east.internal.npmjs.com","tmp":"tmp/get-closest-0.0.3.tgz_1473639380698_0.7846251477021724"},"directories":{},"publish_time":1473639382407,"_cnpm_publish_time":1473639382407,"_hasShrinkwrap":false,"contributors":[]},"0.0.2":{"name":"get-closest","description":"Compare your item to items in an array and get the closest one.","version":"0.0.2","homepage":"https://github.com/cosmosio/get-closest","licenses":[{"type":"MIT","url":"https://raw.github.com/cosmosio/get-closest/master/LICENSE"}],"files":["LICENSE","index.js"],"author":{"name":"Olivier Scherrer","email":"pode.fr@gmail.com"},"keywords":["get","closest","item","array","compare"],"repository":{"type":"git","url":"git@github.com:cosmosio/get-closest.git"},"bugs":{"url":"https://github.com/cosmosio/get-closest/issues"},"scripts":{"test":"mocha"},"main":"index.js","devDependencies":{"chai":"~1.9.1","mocha":"~1.18.2","levenshtein":"~1.0.4"},"_id":"get-closest@0.0.2","dist":{"shasum":"62554026fb883354f4c753ee4152a034a6e76744","size":2859,"noattachment":false,"tarball":"http://123.232.10.234:8212/nexus/content/groups/npm-public/get-closest/-/get-closest-0.0.2.tgz"},"_from":".","_npmVersion":"1.3.24","_npmUser":{"name":"anonymous","email":"pode.fr@gmail.com"},"maintainers":[{"name":"anonymous","email":"pode.fr@gmail.com"}],"directories":{},"publish_time":1398654773690,"_cnpm_publish_time":1398654773690,"_hasShrinkwrap":false,"contributors":[]},"0.0.1":{"name":"get-closest","description":"Compare your item to items in an array and get the closest one.","version":"0.0.1","homepage":"https://github.com/cosmosio/get-closest","licenses":[{"type":"MIT","url":"https://raw.github.com/cosmosio/get-closest/master/LICENSE"}],"files":["LICENSE","index.js"],"author":{"name":"Olivier Scherrer","email":"pode.fr@gmail.com"},"keywords":["get","closest","item","array","compare"],"repository":{"type":"git","url":"git@github.com:cosmosio/get-closest.git"},"bugs":{"url":"https://github.com/cosmosio/get-closest/issues"},"scripts":{"test":"mocha"},"main":"index.js","devDependencies":{"chai":"~1.9.1","mocha":"~1.18.2","levenshtein":"~1.0.4"},"_id":"get-closest@0.0.1","dist":{"shasum":"0ca295d90b3c3ffbc9bef2a44e514c9fde66d6d5","size":2855,"noattachment":false,"tarball":"http://123.232.10.234:8212/nexus/content/groups/npm-public/get-closest/-/get-closest-0.0.1.tgz"},"_from":".","_npmVersion":"1.3.24","_npmUser":{"name":"anonymous","email":"pode.fr@gmail.com"},"maintainers":[{"name":"anonymous","email":"pode.fr@gmail.com"}],"directories":{},"publish_time":1396653168781,"_cnpm_publish_time":1396653168781,"_hasShrinkwrap":false,"contributors":[]}},"dist-tags":{"latest":"0.0.4"},"name":"get-closest","time":{"modified":"2022-01-26T22:21:54.344Z","created":"2022-01-26T22:21:54.344Z","0.0.4":"2017-03-13T03:37:18.254Z","0.0.3":"2016-09-12T00:16:22.407Z","0.0.2":"2014-04-28T03:12:53.690Z","0.0.1":"2014-04-04T23:12:48.781Z"},"readme":"Get closest\n=============\n\nCompare your item to items in an array and get the closest one. It comes by default with number comparison tools but it can also be used with strings, or anything else that you want to compare.\n\nInstallation\n============\n\n```bash\nnpm install get-closest\n```\n\nHow to use\n==========\n\nRequire get-closest:\n\n```bash\nvar getClosest = require(\"get-closest\");\n```\n\nLet's say that you have an array of items such as:\n\n```js\nvar items = [0, 10, 15, 20, 50];\n```\n\nAnd that you want to get the item that's the closest to the number 18, which would be 20 in our case:\n\n```js\ngetClosest.number(18, items); // 3, as items[3] === 20;\n```\n\nIf you want to find the closest to 17.5, as it's exactly between 15 and 20, `number` will return the last number in the array that matches, which is 20 in our case.\n\n```js\ngetClosest.number(17.5, items); // 3, as items[3] === 20\ngetClosest.number(35, items); // 4, as items[4] === 50\n```\n\nIf you're interested in getting the closest item that is greater, you can use `greaterNumber`:\n\n```js\ntools.greaterNumber(1, items); // 1, as items[1] === 10\n```\n\nIf there's an exact match, it's returned. The last exact match will be returned too, to be consistent .number.\n\n```js\ngetClosest.greaterNumber(0, items); // 0, as items[0] === 0 is an exact match.\n```\n\nFinally, you can get the closest item that is lower, using `lowerNumber`:\n\n```js\ngetClosest.lowerNumber(9, items); // 0, as items[0] === 0;\n\ngetClosest.lowerNumber(10, items); // 1, as items[1] === 10;\n```\n\nBut you can also compare custom types by giving a custom comparison function, like string comparison with the levensthein distance:\n\n```js\n/**\n * Returns the distance between the two strings using the Levenshtein method\n * @param {String} compareTo the string to test, it comes from the array\n * @param {String} baseItem the item that you want to test against the array\n * @returns {Number} it needs to return a distance as a number, whatever the type\n * of the current items is.\n */  \nfunction compareLevenshteinDistance(compareTo, baseItem) {\n  return new Levenshtein(compareTo, baseItem).distance;\n}\n\nvar days = [\"lundi\", \"mardi\", \"mercredi\", \"jeudi\", \"vendredi\", \"samedi\", \"dimanche\"];\n\ngetClosest.custom(\"mercure\", days, compareLevenshteinDistance); // 2 (mercredi)\n```\n\nCHANGELOG\n=====\n\n0.0.4 - MARCH 12 2017\n---\n\n* Remove dependency on assert\n\nLICENSE\n=======\n\nMIT","users":{}}