{"id":13447072,"url":"https://github.com/supercharge/collections","last_synced_at":"2025-04-27T12:33:02.546Z","repository":{"id":43637501,"uuid":"195112786","full_name":"supercharge/collections","owner":"supercharge","description":"async/await-ready, chainable Array \u0026 Collection utilities","archived":false,"fork":false,"pushed_at":"2023-11-06T04:22:36.000Z","size":534,"stargazers_count":34,"open_issues_count":0,"forks_count":24,"subscribers_count":3,"default_branch":"main","last_synced_at":"2024-10-30T03:02:09.694Z","etag":null,"topics":["array","async-await","async-functions","asynchronous","chainable-methods","collections","filter","hacktoberfest","iteration","map","promise","promises","reduce","supercharge"],"latest_commit_sha":null,"homepage":"https://superchargejs.com/docs/collections","language":"TypeScript","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/supercharge.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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}},"created_at":"2019-07-03T19:08:47.000Z","updated_at":"2024-07-09T09:50:36.000Z","dependencies_parsed_at":"2024-01-18T15:58:07.921Z","dependency_job_id":"32a9ca14-55ab-4d9b-a85e-b16dac39a822","html_url":"https://github.com/supercharge/collections","commit_stats":{"total_commits":446,"total_committers":20,"mean_commits":22.3,"dds":"0.23318385650224216","last_synced_commit":"dc5763c63e4993950a0336741d3e965b9d7bc637"},"previous_names":["superchargejs/collections"],"tags_count":41,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/supercharge%2Fcollections","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/supercharge%2Fcollections/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/supercharge%2Fcollections/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/supercharge%2Fcollections/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/supercharge","download_url":"https://codeload.github.com/supercharge/collections/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223183562,"owners_count":17101841,"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":["array","async-await","async-functions","asynchronous","chainable-methods","collections","filter","hacktoberfest","iteration","map","promise","promises","reduce","supercharge"],"created_at":"2024-07-31T05:01:07.431Z","updated_at":"2024-11-11T08:20:37.507Z","avatar_url":"https://github.com/supercharge.png","language":"TypeScript","readme":"\u003cdiv align=\"center\"\u003e\r\n  \u003ca href=\"https://superchargejs.com\"\u003e\r\n    \u003cimg width=\"471\" style=\"max-width:100%;\" src=\"https://superchargejs.com/images/supercharge-text.svg\" /\u003e\r\n  \u003c/a\u003e\r\n  \u003cbr/\u003e\r\n  \u003cbr/\u003e\r\n  \u003cp\u003e\r\n    \u003ch3\u003eCollections\u003c/h3\u003e\r\n  \u003c/p\u003e\r\n  \u003cp\u003e\r\n    \u003cstrong\u003e\u003ccode\u003easync/await-ready\u003c/code\u003e\u003c/strong\u003e array methods for Node.js\r\n  \u003c/p\u003e\r\n  \u003cbr/\u003e\r\n  \u003cp\u003e\r\n    \u003ca href=\"#installation\"\u003e\u003cstrong\u003eInstallation\u003c/strong\u003e\u003c/a\u003e ·\r\n    \u003ca href=\"#Docs\"\u003e\u003cstrong\u003eDocs\u003c/strong\u003e\u003c/a\u003e ·\r\n    \u003ca href=\"#usage\"\u003e\u003cstrong\u003eUsage\u003c/strong\u003e\u003c/a\u003e\r\n  \u003c/p\u003e\r\n  \u003cbr/\u003e\r\n  \u003cbr/\u003e\r\n  \u003cp\u003e\r\n    \u003ca href=\"https://www.npmjs.com/package/@supercharge/collections\"\u003e\u003cimg src=\"https://img.shields.io/npm/v/@supercharge/collections.svg\" alt=\"Latest Version\"\u003e\u003c/a\u003e\r\n    \u003ca href=\"https://www.npmjs.com/package/@supercharge/collections\"\u003e\u003cimg src=\"https://img.shields.io/npm/dm/@supercharge/collections.svg\" alt=\"Monthly downloads\"\u003e\u003c/a\u003e\r\n  \u003c/p\u003e\r\n  \u003cp\u003e\r\n    \u003cem\u003eFollow \u003ca href=\"http://twitter.com/marcuspoehls\"\u003e@marcuspoehls\u003c/a\u003e and \u003ca href=\"http://twitter.com/superchargejs\"\u003e@superchargejs\u003c/a\u003e for updates!\u003c/em\u003e\r\n  \u003c/p\u003e\r\n\u003c/div\u003e\r\n\r\n---\r\n\r\n## Notice\r\nThis package is ESM-only.\r\n\r\n\r\n## Introduction\r\nThe `@supercharge/collections` package provides a convenient, fully-async wrapper to work with arrays.\r\n\r\n\r\n## Installation\r\n\r\n```\r\nnpm i @supercharge/collections\r\n```\r\n\r\n\r\n## Docs\r\nFind all the [details and available methods in the extensive Supercharge docs](https://superchargejs.com/docs/collections).\r\n\r\n\r\n## Usage\r\nThe package exports a function accepting an array as a parameter. From there, you can chain all collection methods.\r\n\r\n\r\n### SyncCollections by default\r\n### Collections are Asynchronous\r\nCollections are asynchronous by default. You can use `async` callback functions in all methods and need to `await` the result.\r\n\r\nIn contrast to JavaScript’s array methods, collections have a lot more methods available making your code a lot simpler. Here are basic examples using a collection:\r\n\r\n```js\r\nimport User from '../models/user'\r\nimport Collect from '@supercharge/collections'\r\n\r\nconst users = await User.findAll()\r\n\r\nconst notSubscribedUsers = await Collect(users).filter(user =\u003e {\r\n  return user.notSubscribedToNewsletter\r\n})\r\n\r\n// notSubscribedUsers = [ \u003clist of not-yet-subscribed users\u003e ]\r\n\r\n// you can also chain further methods to the collection\r\nconst users = await User.findAll()\r\n\r\nconst subscribedUsers = await Collect(users)\r\n  .filter(user =\u003e {\r\n    return user.notSubscribedToNewsletter\r\n  })\r\n  .map(async user =\u003e { // \u003c-- providing an async callback creates an async collection that you need to `await`\r\n    await user.subscribeToNewsletter()\r\n\r\n    return user\r\n  })\r\n\r\n// subscribedUsers = [ \u003clist of newly-subscribed users\u003e ]\r\n```\r\n\r\nHere’s another example outlining how to determine whether the array “has” an item:\r\n\r\n```js\r\n// “has” in JS Arrays\r\nconst hasNotSubscribedUsers = !![].concat(users).find(user =\u003e {\r\n  return user.notSubscribedToNewsletter\r\n})\r\n\r\n// “has” in Collections\r\nconst hasNotSubscribedUsers = Collect(users).has(async user =\u003e {\r\n  return await User.isSubcribedToNewsletter(user)\r\n})\r\n```\r\n\r\nAll available methods are outlined in the [docs](https://superchargejs.com/docs/collections).\r\n\r\n\r\n## Contributing\r\nDo you miss a collection function? We very much appreciate your contribution! Please send in a pull request 😊\r\n\r\n1.  Create a fork\r\n2.  Create your feature branch: `git checkout -b my-feature`\r\n3.  Commit your changes: `git commit -am 'Add some feature'`\r\n4.  Push to the branch: `git push origin my-new-feature`\r\n5.  Submit a pull request 🚀\r\n\r\n\r\n## License\r\nMIT © [Supercharge](https://superchargejs.com)\r\n\r\n---\r\n\r\n\u003e [superchargejs.com](https://superchargejs.com) \u0026nbsp;\u0026middot;\u0026nbsp;\r\n\u003e GitHub [@supercharge](https://github.com/supercharge) \u0026nbsp;\u0026middot;\u0026nbsp;\r\n\u003e Twitter [@superchargejs](https://twitter.com/superchargejs)\r\n","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsupercharge%2Fcollections","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsupercharge%2Fcollections","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsupercharge%2Fcollections/lists"}