{"id":17256143,"url":"https://github.com/jalal246/packagesorter","last_synced_at":"2025-04-14T05:42:23.305Z","repository":{"id":37009243,"uuid":"235583052","full_name":"jalal246/packageSorter","owner":"jalal246","description":"🔄 Dependencies sorting algorithm. It sorts, retrieves unsortable, and returns sorting history for each package","archived":false,"fork":false,"pushed_at":"2022-08-28T13:55:46.000Z","size":206,"stargazers_count":10,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-27T19:40:12.402Z","etag":null,"topics":["array-sort","devops","extracts","helper","json","json-sort","json-sorting","monorepo","move-position","package-manager","package-sorter","position","recursive","recursive-functions","sort","sort-algorithm","sort-algorithms","sort-array","sort-array-js","utility"],"latest_commit_sha":null,"homepage":"https://jalal246.github.io/packageSorter/","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jalal246.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}},"created_at":"2020-01-22T13:48:26.000Z","updated_at":"2023-11-05T10:48:28.000Z","dependencies_parsed_at":"2022-08-18T00:20:38.221Z","dependency_job_id":null,"html_url":"https://github.com/jalal246/packageSorter","commit_stats":null,"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jalal246%2FpackageSorter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jalal246%2FpackageSorter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jalal246%2FpackageSorter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jalal246%2FpackageSorter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jalal246","download_url":"https://codeload.github.com/jalal246/packageSorter/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248830420,"owners_count":21168272,"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-sort","devops","extracts","helper","json","json-sort","json-sorting","monorepo","move-position","package-manager","package-sorter","position","recursive","recursive-functions","sort","sort-algorithm","sort-algorithms","sort-array","sort-array-js","utility"],"created_at":"2024-10-15T07:13:43.391Z","updated_at":"2025-04-14T05:42:23.274Z","avatar_url":"https://github.com/jalal246.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Package Sorter\n\n\u003e Sorting a group of packages that depends on each other\n\nHaving multiple projects in workspace depending on each other is a headache. You\nhave to build core first, then the project depends on it, and so on. You\nprobably want this step to be automated so you can use: `package-sorter`\n\n```bash\nnpm install package-sorter\n```\n\n## API\n\n```js\npackageSorter(packages? Array, coreDependency? string)\n```\n\nReturns result object:\n\n- `sorted: Array \u003csortedPkgJson\u003e` - all sorted packages in order.\n- `sortingMap: Array \u003csortingMap\u003e`- map of package sorting contains:\n  - `form: number` - original package index before sorting.\n  - `to: number` - current package index after sorting.\n- `unSorted: Array \u003cunsortedPkgJson\u003e` - unsortable package that's missing dependency.\n\n```js\nconst { sorted, sortingMap, unSorted } = packageSorter(\n  packages,\n  coreDependency\n);\n```\n\nIf `coreDependency` is not passed, `package-sorter` will extract it following\nmonorepo naming pattern as: `@coreDep/`\n\n### Example (1) - All Sorted\n\n```js\nimport packageSorter from \"package-sorter\";\n\n// input packages\n\nconst pkg1 = {\n  name: \"@pkg/first\",\n  dependencies: {},\n};\n\nconst pkg2 = {\n  name: \"@pkg/second\",\n  dependencies: {\n    \"@pkg/first\": \"^0.1.5\",\n  },\n};\n\nconst pkg3 = {\n  name: \"@pkg/third\",\n  dependencies: {\n    \"@pkg/second\": \"^0.1.5\",\n  },\n};\n\nconst packages = [pkg3, pkg2, pkg1];\n\n// our core dependency in this case is: @pkg.\nconst { sorted, sortingMap, unSorted } = packageSorter(packages, \"@pkg\");\n\n// sorted = [pkg1, pkg2, pkg3];\n\n// sortingMap = [\n//   { from: 2, to: 0 },\n//   { from: 1, to: 1 },\n//   { from: 0, to: 2 },\n// ];\n\n// unSorted = [];\n```\n\n### Example (2) - Mixed Packages\n\n```js\nimport packageSorter from \"package-sorter\";\n\n// input packages\n\nconst pkg1 = {\n  name: \"@pkg/first\",\n  dependencies: {},\n};\n\nconst pkg2 = {\n  name: \"@pkg/second\",\n  dependencies: {\n    \"@pkg/first\": \"^0.1.5\",\n  },\n};\n\nconst pkg3 = {\n  name: \"unrelated\",\n  dependencies: {},\n};\n\nconst packages = [pkg3, pkg2, pkg1];\n\n// let the function gets core dependency (@pkg) by itself\nconst { sorted, sortingMap, unSorted } = packageSorter(packages);\n\n// sorted = [pkg3, pkg1, pkg2];\n\n// sortingMap = [\n//   { from: 0, to: 0 },\n//   { from: 2, to: 1 },\n//   { from: 1, to: 2 },\n// ];\n\n// unSorted = [];\n```\n\n### Example (3) - Some Unsorted\n\n```js\nimport packageSorter from \"package-sorter\";\n\n// input packages\n\nconst pkg1 = {\n  name: \"@pkg/first\",\n  dependencies: {},\n};\n\nconst pkg2 = {\n  name: \"@pkg/second\",\n  dependencies: {\n    \"@pkg/first\": \"^0.1.5\",\n  },\n};\n\nconst pkg3 = {\n  name: \"@pkg/unsortable\",\n  dependencies: {\n    \"@pkg/missing\": \"^0.1.5\",\n  },\n};\n\nconst packages = [pkg3, pkg2, pkg1];\n\nconst { sorted, sortingMap, unSorted } = packageSorter(packages);\n\n// sorted = [pkg1, pkg2];\n\n// sortingMap = [\n//   { from: 2, to: 0 },\n//   { from: 1, to: 1 },\n// ];\n\n// unSorted = [pkg3];\n```\n\n## Test\n\n```sh\nnpm test\n```\n\n## License\n\nThis project is licensed under the [GPL-3.0 License](https://github.com/jalal246/packageSorter/blob/master/LICENSE)\n\n### Related projects\n\n- [move-position](https://github.com/jalal246/move-position) - Moves element\n  index in given array from position A to B.\n\n- [builderz](https://github.com/jalal246/builderz) - Zero Configuration JS bundler.\n\n- [corename](https://github.com/jalal246/corename) - Extracts package name.\n\n- [get-info](https://github.com/jalal246/get-info) - Utility functions for\n  projects production.\n\n- [textics](https://github.com/jalal246/textics) \u0026\n  [textics-stream](https://github.com/jalal246/textics-stream) - Counts lines,\n  words, chars and spaces for a given string.\n\n- [folo](https://github.com/jalal246/folo) - Form \u0026 Layout Components Built with React.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjalal246%2Fpackagesorter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjalal246%2Fpackagesorter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjalal246%2Fpackagesorter/lists"}