{"id":13547845,"url":"https://github.com/robinweser/fast-loops","last_synced_at":"2025-04-10T20:23:09.692Z","repository":{"id":27000239,"uuid":"112118290","full_name":"robinweser/fast-loops","owner":"robinweser","description":"Tiny (0.6kb), performant \u0026 immutable iteration utilities for arrays and objects","archived":false,"fork":false,"pushed_at":"2024-07-04T07:40:15.000Z","size":334,"stargazers_count":26,"open_issues_count":4,"forks_count":3,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-24T18:04:26.727Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/robinweser.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-11-26T21:31:33.000Z","updated_at":"2024-11-01T07:55:02.000Z","dependencies_parsed_at":"2024-06-18T15:16:07.318Z","dependency_job_id":"b384466e-542e-4acf-af03-6cf122ac18aa","html_url":"https://github.com/robinweser/fast-loops","commit_stats":{"total_commits":16,"total_committers":3,"mean_commits":5.333333333333333,"dds":0.5,"last_synced_commit":"4ddfea3ae7416477ef8d83e75a92c9e9ab6e6a28"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/robinweser%2Ffast-loops","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/robinweser%2Ffast-loops/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/robinweser%2Ffast-loops/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/robinweser%2Ffast-loops/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/robinweser","download_url":"https://codeload.github.com/robinweser/fast-loops/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248289997,"owners_count":21078923,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-01T12:01:01.830Z","updated_at":"2025-04-10T20:23:09.667Z","avatar_url":"https://github.com/robinweser.png","language":"JavaScript","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"readme":"# Fast Loops\n\nA collection of small, performant \u0026 immutable iteration utilities for Arrays and Objects.\n\n\u003cimg alt=\"TravisCI\" src=\"https://travis-ci.org/rofrischmann/fast-loops.svg?branch=master\"\u003e \u003ca href=\"https://codeclimate.com/github/rofrischmann/fast-loops/coverage\"\u003e\u003cimg alt=\"Test Coverage\" src=\"https://codeclimate.com/github/rofrischmann/fast-loops/badges/coverage.svg\"\u003e\u003c/a\u003e \u003cimg alt=\"gzipped size\" src=\"https://img.shields.io/badge/gzipped+minified-0.47kb-brightgreen.svg\"\u003e \u003cimg alt=\"npm downloads\" src=\"https://img.shields.io/npm/dm/fast-loops.svg\"\u003e \u003cimg alt=\"npm version\" src=\"https://badge.fury.io/js/fast-loops.svg\"\u003e\n\n## Installation\n```sh\nyarn add fast-loops\n```\nAlternatively use `npm i --save fast-loops`.\n\n## Why?\nBecause JavaScript's native \"functional\" APIs such as `forEach`, `reduce`, `map` and `filter` are slow. There're many different utility packages out there already, e.g. lodash. But lodash's `reduce` method itself is 4.5kb gzipped which is way too much for a simple Array/Object reduce utility.\n\n## API\n\n\u003e All methods are immutable by defaults, yet they're not safe from mutating.\n\n* [arrayEach](#arrayeacharr-iterator)\n* [arrayFilter](#arrayfilterarr-filter)\n* [arrayMap](#arraymaparr-mapper)\n* [arrayReduce](#arrayreducearr-reducer-accumulator)\n* [objectEach](#objecteachobj-iterator)\n* [objectFilter](#objectfilterobj-filter)\n* [objectFind](#objectfindobj-query)\n* [objectMap](#objectmapobj-mapper)\n* [objectReduce](#objectreduceobj-reducer-accumulator)\n* [objectRenameKeys](#objectrenamekeysobj-keys)\n* [objectMergeDeep](#objectmergedeepbase-objs)\n\n### `arrayEach(arr, iterator)`\n\nIterates over each value in the array.\u003cbr\u003e\nSimilar to `Array.prototype.forEach`.\n\n1. `arr` (*Array*): The array to iterate over\n2. `iterator` (*Function*): The iterator method with the signature `(value, index, length, arr) =\u003e void`\n\n```javascript\nimport { arrayEach } from 'fast-loops'\n\narrayEach([1, 2, 3], console.log)\n// 1, 0, 3, [1, 2, 3]\n// 2, 1, 3, [1, 2, 3]\n// 3, 2, 3, [1, 2, 3]\n```\n\n\n### `arrayFilter(arr, filter)`\n\nFilters an array according to the filter criteria.\u003cbr\u003e\nSimilar to `Array.prototype.filter`.\n\n1. `arr` (*Array*): The array that gets filtered\n2. `filter` (*Function*): The filter method with the signature `(value, index, length, arr) =\u003e boolean`\n\n```javascript\nimport { arrayFilter } from 'fast-loops'\n\nconst biggerThan2 = arrayFilter([1, 2, 3, 4], value =\u003e value \u003e 2)\n\nconsole.log(biggerThan2)\n// =\u003e [3, 4]\n```\n\n### `arrayMap(arr, mapper)`\n\nMaps an array by running the mapper on each value.\u003cbr\u003e\nSimilar to `Array.prototype.map`.\n\n1. `arr` (*Array*): The array that gets mapped\n2. `mapper` (*Function*): The mapping method with the signature `(value, index, length, arr) =\u003e newValue`\n\n```javascript\nimport { arrayMap } from 'fast-loops'\n\nconst square = arrayMap([1, 2, 3, 4], value =\u003e value * value)\n\nconsole.log(square)\n// =\u003e [1, 4, 9, 16]\n```\n\n### `arrayReduce(arr, reducer, accumulator)`\n\nReduces an array based on the accumulator.\u003cbr\u003e\nSimilar to `Array.prototype.reduce`.\n\n1. `arr` (*Array*): The array that gets reduced\n2. `reducer` (*Function*): The reducer method with the signature `(accumulator, value, index, length, arr) =\u003e accumulator`\n3. `accumulator` (*any*): The initial accumulator value\n\n```javascript\nimport { arrayReduce } from 'fast-loops'\n\nconst sum = arrayReduce([1, 2, 3, 4], (out, value) =\u003e out + value, 0)\n\nconsole.log(sum)\n// =\u003e 10\n```\n\n### `objectEach(obj, iterator)`\n\nIterates over each key in the object.\n\n1. `obj` (*Object*): The object to iterate over\n2. `iterator` (*Function*): The iterator method with the signature `(value, key, obj) =\u003e void`\n\n```javascript\nimport { objectEach } from 'fast-loops'\n\nobjectEach({ 1: 10, 2: 20, 3: 30 }, console.log)\n// 10, 1, { 1: 10, 2: 20, 3: 30 }\n// 20, 2, { 1: 10, 2: 20, 3: 30 }\n// 30, 3, { 1: 10, 2: 20, 3: 30 }\n```\n\n### `objectFilter(obj, filter)`\n\nFilters an object's keys according to the filter criteria.\n\n1. `obj` (*Object*): The object that gets filtered\n2. `filter` (*Function*): The filter method with the signature `(value, key, obj) =\u003e boolean`\n\n```javascript\nimport { objectFilter } from 'fast-loops'\n\nconst filter = (value, key) =\u003e value \u003e 20 \u0026\u0026 parseInt(key) % 2 !== 0\nconst biggerThan20AndOddKey = objectFilter({ 1: 10, 2: 20, 3: 30, 4: 40 }, filter)\n\nconsole.log(biggerThan20AndOddKey)\n// =\u003e { 3: 30 }\n```\n\n### `objectFind(obj, query)`\n\nTries to find a key-value pair that matches the query.\u003cbr\u003e\nReturns the matching key or `undefined` if none matches.\u003cbr\u003e\nIt's like `Array.prototype.find` but for objects.\n\n1. `obj` (*Object*): The object that gets queried\n2. `query` (*Function*): The query method with the signature `(value, key, obj) =\u003e boolean`\n\n```javascript\nimport { objectFind } from 'fast-loops'\n\nconst query = (value, key) =\u003e value \u003e 20 \u0026\u0026 parseInt(key) % 2 === 0\nconst biggerThan20AndEvenKey = objectFind({ 1: 10, 2: 20, 3: 30, 4: 40 }, query)\n\nconsole.log(biggerThan20AndEvenKey)\n// =\u003e \"4\"\n```\n\n\n### `objectMap(obj, mapper)`\n\nMaps an object by running the `mapper` on each value.\u003cbr\u003e\nSimilar to `Object.keys(obj).map(mapper)`.\n\n\n1. `obj` (*Object*): The object that gets reduced\n2. `mapper` (*Function*): The mapper method with the signature `(value, key, obj) =\u003e newValue`\n\n```javascript\nimport { objectMap } from 'fast-loops'\n\nconst mapped = objectMap({ 1: 10, 2: 20, 3: 30 }, (value, key) =\u003e value + parseInt(key))\n\nconsole.log(mapped)\n// =\u003e { 1: 11, 2: 22, 3: 33 }\n```\n\n### `objectReduce(obj, reducer, accumulator)`\n\nReduces an object based on the accumulator.\n\n1. `obj` (*Object*): The object that gets reduced\n2. `reducer` (*Function*): The reducer method with the signature `(accumulator, value, key, obj) =\u003e accumulator`\n3. `accumulator` (*any*): The initial accumulator value\n\n```javascript\nimport { objectReduce } from 'fast-loops'\n\nconst sumOfValues = objectReduce({ 1: 10, 2: 20, 3: 30 }, (out, value) =\u003e out + value, 0)\n\nconsole.log(sumOfValues)\n// =\u003e 60\n```\n\n### `objectRenameKeys(obj, keys)`\n\nRenames object keys.\n\n\u003e Uses [objectReduce](#objectreduceobj-reducer-accumulator) under the hood.\n\n1. `obj` (*Object*): The object that gets reduced\n2. `keys` (*Object*): The keys mapping an old key to a new key\n\n```javascript\nimport { objectRenameKeys } from 'fast-loops'\n\nconst renamedObj = objectRenameKeys({ foo: 1, bar: 2 }, { foo: \"baz\" })\n\nconsole.log(sumOfValues)\n// =\u003e { baz: 1, bar: 2 }\n```\n\n\n### `objectMergeDeep(base, ...objs)`\n\nRecursively merges objects into a base object.\n\n1. `base` (*Object*): The base object which is changed\n2. `objs` (*Array\\\u003cObject\\\u003e*): A list of objects to be merged into the base object\n\n```javascript\nimport { objectMergeDeep } from 'fast-loops'\n\nconst base = {\n  foo: 1,\n  bar: {\n    foo: 2\n  }\n}\nconst mergedObj = objectMergeDeep(base, { baz: 3 }, { bar: { foo: 3 }})\n\nconsole.log(mergedObj)\n// =\u003e { foo: 1, bar: { foo: 3 }, baz: 3 }\n```\n\n## Direct Imports\nWhile we support the `module` key to support Tree Shaking, you might still want to import single methods without any overhead.\nYou can import every method using the full path to the method resource.\n\n```javascript\nimport objectReduce from 'fast-loops/lib/objectReduce'\n```\n\n## License\nfast-loops is licensed under the [MIT License](http://opensource.org/licenses/MIT).\u003cbr\u003e\nDocumentation is licensed under [Creative Common License](http://creativecommons.org/licenses/by/4.0/).\u003cbr\u003e\nCreated with ♥ by [@rofrischmann](http://rofrischmann.de).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frobinweser%2Ffast-loops","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frobinweser%2Ffast-loops","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frobinweser%2Ffast-loops/lists"}