{"id":16009790,"url":"https://github.com/muratcatal/group-array-items","last_synced_at":"2025-04-05T02:24:47.531Z","repository":{"id":57254385,"uuid":"114290255","full_name":"muratcatal/group-array-items","owner":"muratcatal","description":"Group json items in array","archived":false,"fork":false,"pushed_at":"2017-12-26T06:07:57.000Z","size":48,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-24T09:54:08.732Z","etag":null,"topics":["array","array-group","array-json-group","grouping","json-group"],"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/muratcatal.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}},"created_at":"2017-12-14T19:48:51.000Z","updated_at":"2025-01-19T12:04:42.000Z","dependencies_parsed_at":"2022-08-31T09:00:15.096Z","dependency_job_id":null,"html_url":"https://github.com/muratcatal/group-array-items","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/muratcatal%2Fgroup-array-items","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/muratcatal%2Fgroup-array-items/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/muratcatal%2Fgroup-array-items/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/muratcatal%2Fgroup-array-items/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/muratcatal","download_url":"https://codeload.github.com/muratcatal/group-array-items/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247277615,"owners_count":20912559,"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","array-group","array-json-group","grouping","json-group"],"created_at":"2024-10-08T13:04:15.105Z","updated_at":"2025-04-05T02:24:47.103Z","avatar_url":"https://github.com/muratcatal.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Group Array Items\n----\nThis library helps you group json items in array. It has zero-dependency.\n\n# How to install\n----\n##### Using npm\n---\n```\n$ npm i --save group-array-items\n```\n\n##### Using yarn\n---\n```\n $ yarn add group-array-items\n```\n\n##### Compiling source code\n---\n- Download src code from github\n- Open your cli and type\n```\n$ npm run build\n```\nor \n```\n$ yarn run build\n```\n- Get file in dist folder and referance it in your application\n# How to use\n----\nThis helper function is configurable with a configuration parameter. However, if you want to use with default configuration, your json model must have a `type` property for grouping and `children` property is you have child objects needed to be grouped. But dont worry, each of them can be configured easily.\n#### With default configuration file\n```javascript\nimport groupBy from 'group-array-items'\n\nlet data = [\n  {\n    name: \"My item 1\",\n    type: \"group-1\",\n    children: [\n      {\n        name: \"My item 1.1\",\n        type: \"group-1\"\n      }, {\n        name: \"My item 1.2\",\n        type: \"group-2\"\n      }, {\n        name: \"My item 1.3\",\n        type: \"group-1\"\n      }\n    ]\n  }, {\n    name: \"My item 2\",\n    type: \"group-2\"\n  }, {\n    name: \"My item 3\",\n    type: \"group-1\",\n    children: [\n      {\n        name: \"My item 3.1\",\n        type: \"group-1\",\n        children: [\n          {\n            name: \"My item 3.1.1\",\n            type: \"group-3\"\n          }, {\n            name: \"My item 3.1.2\",\n            type: \"group-3\"\n          }, {\n            name: \"My item 3.1.3\",\n            type: \"group-4\"\n          }\n        ]\n      }, {\n        name: \"My item 3.2\",\n        type: \"group-2\"\n      }, {\n        name: \"My item 3.3\",\n        type: \"group-1\"\n      }\n    ]\n  }\n]\n\nconst result = groupBy(data);\n```\n#### With configuration file\nTo configure groupBy function, send a second json object as parameter.\n```javascript\nconst config = {\n    aliases: [\n        {\n            alias: \"Group Name 1 Alias\",\n            name: \"group_name_1\"\n        },\n        {\n            alias: \"Group Name 2 Alias\",\n            name: \"group_name_2\"\n        }\n    ],\n    groupBy: \"type\",\n    childElement: \"children\",\n    prefix: \"\",\n    generateId: true\n}\nconst result = groupBy(data,config);\n```\n\u003e When you grouped items, `groupBy` function generates a new item which has a boolean property `groupItem` to indicate that item is an grouping-header-item. By default, that element's name is given to its group name however you can override that behaviour by giving to alias by configuration file.\n#### Output of groupBy\nYou will have an output as below format\n```javascript\n[\n  {\n    \"name\": \"type-name-alias\",\n    \"groupItem\": true, // shows that this json is an header generated by groupBy function\n    \"type\": \"type-name\",\n    \"children\": [\n      {\n        \"name\": \"My item 1\", // grouped item\n        \"type\": \"group-1\"\n      },\n      {\n        \"name\": \"My item 1\", // second grouped item\n        \"type\": \"group-1\"\n      }\n    ]\n  }\n]\n```\n# Configuration Description\n----\n\u003e You can configure groupBy function by sending any of configuration parameter to fit your needs.\n\n|   Property   \t|  Type  \t| Default Value \t| Description                                                                                                                                                                                                                                                                                                                                                                       \t|\n|:------------:\t|:------:\t|:-------------:\t|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------\t|\n| aliases      \t|  array \t|     empty     \t| an array which holds alias for grouped headers. Format of that array item is:  {   alias: \"A title which will be used for instead of group-type\",   name: \"group-type\" } Assume that you have group types `gold`,`silver` and `rock` in your json type and you want to see in your group-header titles as `My Gold`, `My Silver`,`My Rock`. {   alias: \"My Gold\",   name: \"gold } \t|\n| groupBy      \t| string \t|     \"type\"    \t| property which will be looked for grouping in json object                                                                                                                                                                                                                                                                                                                         \t|\n| childElement \t| string \t|    children   \t| property which will be looked for child elements in json object for deep grouping                                                                                                                                                                                                                                                                                                 \t|\n| prefix       \t| string \t|     empty     \t| string which will be appended to generated grouped header's groupBy propery                                                                                                                                                                                                                                                                                                       \t|\n| generateId       \t| boolean \t|     true     \t| unique id generate for each group header                                                                                                                                                                                                                                                                                                       \t|\n\n# Change log\n----\nTo access CHANGELOG.md file [click here](./CHANGELOG.md)\n# Contributing\n----\nI'd be very happy if you feedback any issue\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmuratcatal%2Fgroup-array-items","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmuratcatal%2Fgroup-array-items","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmuratcatal%2Fgroup-array-items/lists"}