{"id":25627389,"url":"https://github.com/codex-central/grouping","last_synced_at":"2026-04-29T01:02:24.163Z","repository":{"id":238728486,"uuid":"797322070","full_name":"Codex-Central/grouping","owner":"Codex-Central","description":"Functions to group data by a key or multiple keys.","archived":false,"fork":false,"pushed_at":"2024-05-07T18:08:05.000Z","size":25,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-06-09T15:58:18.013Z","etag":null,"topics":["array","group","javascript","object","typescript"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/@codexcentral/grouping","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Codex-Central.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":"2024-05-07T16:01:55.000Z","updated_at":"2024-05-07T21:28:10.000Z","dependencies_parsed_at":"2024-05-07T19:25:54.755Z","dependency_job_id":null,"html_url":"https://github.com/Codex-Central/grouping","commit_stats":null,"previous_names":["codex-central/grouping"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/Codex-Central/grouping","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Codex-Central%2Fgrouping","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Codex-Central%2Fgrouping/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Codex-Central%2Fgrouping/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Codex-Central%2Fgrouping/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Codex-Central","download_url":"https://codeload.github.com/Codex-Central/grouping/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Codex-Central%2Fgrouping/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32405904,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-28T19:38:08.556Z","status":"ssl_error","status_checked_at":"2026-04-28T19:37:55.688Z","response_time":56,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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","group","javascript","object","typescript"],"created_at":"2025-02-22T17:48:39.358Z","updated_at":"2026-04-29T01:02:24.139Z","avatar_url":"https://github.com/Codex-Central.png","language":"TypeScript","funding_links":["https://www.buymeacoffee.com/robertosilva"],"categories":[],"sub_categories":[],"readme":"# grouping\n\nFunctions to group data by a key or multiple keys.\n\n## Installation\n\n\u003e `npm install @codexcentral/grouping`\n\n## Importing\n\n### Javascript\n\n```javascript\nconst { groupBy } = require(\"@codexcentral/grouping\");\n```\n\n### Typescript\n\n```typescript\nimport { groupBy } from \"@codexcentral/grouping\";\n```\n\n## Functions\n\n- \u003cdetails\u003e\n  \u003csummary\u003egroupBy\u003c/summary\u003e\n    \n    Groups an array of objects by a key.\n\n  | Parameter | Type   | Description               |\n  | --------- | ------ | ------------------------- |\n  | data      | Array  | Array of objects to group |\n  | key       | String | Key to group by           |\n\n  #### Example\n\n  #### Javascript\n\n  ```javascript\n  const { groupBy } = require('@codexcentral/grouping');\n  ...\n  const people = [\n    { name: \"Alice\", age: 25 },\n    { name: \"Bob\", age: 30 },\n    { name: \"Charlie\", age: 25 }\n  ];\n\n  console.log(groupBy(people, 'age'));\n\n  // Output:\n  // {\n  //   '25': [\n  //     { name: 'Alice', age: 25 },\n  //     { name: 'Charlie', age: 25 }\n  //   ],\n  //   '30': [\n  //     { name: 'Bob', age: 30 }\n  //   ]\n  // }\n  ```\n\n  #### Typescript\n\n  ```typescript\n  import { groupBy } from '@codexcentral/grouping';\n  ...\n    interface Person {\n      name: string;\n      age: number;\n    }\n\n    const people: Person[] = [\n      { name: \"Alice\", age: 25 },\n      { name: \"Bob\", age: 30 },\n      { name: \"Charlie\", age: 25 }\n    ];\n\n    console.log(groupBy(people, 'age'));\n    // Output:\n    // {\n    //   '25': [\n    //     { name: 'Alice', age: 25 },\n    //     { name: 'Charlie', age: 25 }\n    //   ],\n    //   '30': [\n    //     { name: 'Bob', age: 30 }\n    //   ]\n    // }\n  ```\n\n  \u003c/details\u003e\n\n- \u003cdetails\u003e\n  \u003csummary\u003epartition\u003c/summary\u003e\n\n  Partitions an array of objects into two arrays based on a predicate function.\n\n  | Parameter | Type     | Description               |\n  | --------- | -------- | ------------------------- |\n  | data      | Array    | Array of objects to group |\n  | predicate | Function | Predicate function        |\n\n  #### Examples\n\n  ```javascript\n  const numbers = [1, 2, 3, 4, 5];\n  const [even, odd] = partition(numbers, (n) =\u003e n % 2 === 0);\n  console.log(even); // [2, 4]\n  console.log(odd); // [1, 3, 5]\n  ```\n\n  ```javascript\n  const people = [\n    { name: \"Alice\", age: 25 },\n    { name: \"Bob\", age: 30 },\n    { name: \"Charlie\", age: 25 },\n  ];\n  const [young, old] = partition(people, (person) =\u003e person.age \u003c 30);\n  console.log(young); // [{ name: 'Alice', age: 25 }, { name: 'Charlie', age: 25 }]\n  console.log(old); // [{ name: 'Bob', age: 30 }]\n  ```\n\n  ```javascript\n  const words = [\"apple\", \"banana\", \"cherry\", \"date\"];\n  const [short, long] = partition(words, (word) =\u003e word.length \u003c= 5);\n  console.log(short); // ['apple', 'date']\n  console.log(long); // ['banana', 'cherry' ]\n  ```\n\n  \u003c/details\u003e\n\n- \u003cdetails\u003e\n  \u003csummary\u003egroupItems\u003c/summary\u003e\n\n  Groups a complex array into arrays of a specified size.\n\n  | Parameter | Type   | Description               |\n  | --------- | ------ | ------------------------- |\n  | data      | Array  | Array of objects to group |\n  | size      | Number | Size of each group        |\n\n  #### Example\n\n  ```typescript\n  interface IProduct {\n    name: string;\n    price: number;\n  }\n\n  const products: IProduct[] = [\n    { name: \"Laptop\", price: 1000 },\n    { name: \"Mouse\", price: 20 },\n    { name: \"Keyboard\", price: 50 },\n    { name: \"Monitor\", price: 300 },\n    { name: \"USB cable\", price: 5 },\n  ];\n\n  const groupedProducts = groupItems(products, 2);\n  console.log(groupedProducts);\n\n  // Output:\n  // [\n  //   [\n  //     { name: \"Laptop\", price: 1000 },\n  //     { name: \"Mouse\", price: 20 },\n  //   ],\n  //   [\n  //     { name: \"Keyboard\", price: 50 },\n  //     { name: \"Monitor\", price: 300 },\n  //   ],\n  //   [{ name: \"USB cable\", price: 5 }],\n  // ];\n  ```\n\n  \u003c/details\u003e\n\n- \u003cdetails\u003e\n  \u003csummary\u003echunk\u003c/summary\u003e\n\n  Groups a simple array into arrays of a specified size.\n\n  | Parameter | Type   | Description               |\n  | --------- | ------ | ------------------------- |\n  | data      | Array  | Array of objects to group |\n  | size      | Number | Size of each group        |\n\n  #### Example\n\n  ```typescript\n  const numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];\n  const chunkedNumbers = chunk(numbers, 3);\n  console.log(chunkedNumbers);\n\n  // Output:\n  // [\n  //   [ 1, 2, 3 ],\n  //   [ 4, 5, 6 ],\n  //   [ 7, 8, 9 ],\n  //   [ 10 ]\n  // ]\n  ```\n\n  #### Example\n\n  ```typescript\n  const letters = [\"a\", \"b\", \"c\", \"d\", \"e\", \"f\", \"g\", \"h\"];\n  const groupedLetters = chunk(letters, 4);\n  console.log(groupedLetters);\n\n  // Output:\n  // [\n  //   ['a', 'b', 'c', 'd'],\n  //   ['e', 'f', 'g', 'h']\n  // ]\n  ```\n\n  \u003c/details\u003e\n\n# Credits\n\nThis code was written by [Roberto Silva Z.](https://www.linkedin.com/in/robertosilvazuniga/)\n\n[\u003cimg src=\"https://cdn.buymeacoffee.com/buttons/default-orange.png\" alt=\"BuyMeACoffee\" width=\"200\" /\u003e](https://www.buymeacoffee.com/robertosilva)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcodex-central%2Fgrouping","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcodex-central%2Fgrouping","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcodex-central%2Fgrouping/lists"}