{"id":15652380,"url":"https://github.com/jvandenaardweg/sort-by-property","last_synced_at":"2025-07-04T01:34:20.686Z","repository":{"id":62894002,"uuid":"563307432","full_name":"jvandenaardweg/sort-by-property","owner":"jvandenaardweg","description":"Type-safe array sorting method with support for deeply nested properties and Typescript autocompletion.","archived":false,"fork":false,"pushed_at":"2023-12-01T08:30:58.000Z","size":3252,"stargazers_count":4,"open_issues_count":6,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-30T20:08:22.444Z","etag":null,"topics":["array","array-manipulations","array-methods","array-sort","array-sorting","arrays","browser","javascript","javascript-library","javascript-tools","json","nodejs","sort","sortby","sortbyvalue","sorting","typesafe","typescript","typescript-library","typescript4"],"latest_commit_sha":null,"homepage":"","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/jvandenaardweg.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,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-11-08T10:45:28.000Z","updated_at":"2024-09-23T23:54:53.000Z","dependencies_parsed_at":"2024-10-03T12:42:42.822Z","dependency_job_id":"f7634782-9f78-4c92-80ad-94524d48a1df","html_url":"https://github.com/jvandenaardweg/sort-by-property","commit_stats":{"total_commits":211,"total_committers":2,"mean_commits":105.5,"dds":"0.41706161137440756","last_synced_commit":"d43662c7a2519c61c7478a9660f6d51f1cd1ff3c"},"previous_names":[],"tags_count":27,"template":false,"template_full_name":null,"purl":"pkg:github/jvandenaardweg/sort-by-property","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jvandenaardweg%2Fsort-by-property","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jvandenaardweg%2Fsort-by-property/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jvandenaardweg%2Fsort-by-property/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jvandenaardweg%2Fsort-by-property/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jvandenaardweg","download_url":"https://codeload.github.com/jvandenaardweg/sort-by-property/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jvandenaardweg%2Fsort-by-property/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":263431245,"owners_count":23465503,"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-manipulations","array-methods","array-sort","array-sorting","arrays","browser","javascript","javascript-library","javascript-tools","json","nodejs","sort","sortby","sortbyvalue","sorting","typesafe","typescript","typescript-library","typescript4"],"created_at":"2024-10-03T12:42:13.396Z","updated_at":"2025-07-04T01:34:20.655Z","avatar_url":"https://github.com/jvandenaardweg.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# sort-by-property [![npm version](https://badge.fury.io/js/sort-by-property.svg)](https://badge.fury.io/js/sort-by-property) [![mit license](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/jvandenaardweg/sort-by-property/blob/main/LICENSE)\n\nType-safe array sorting method with support for deeply nested properties and Typescript autocompletion.\n\n```typescript\nblogPosts.sort(sortByProperty('author.name', 'asc'));\n```\n\n## Features\n\n- Type-safety and Typescript autocompletion on the properties you try to sort\n- Define nested property to sort on using a path string like: `\"author.name\"`\n- Supports sorting by `string`, `number`, `boolean`, `Date`, `Symbol` and `BigInt` values\n- Use a specific locale when sorting by `string`\n- Handles `null` and `undefined` values gracefully by moving the object to the end of the array\n- Small file size, only 0.6kb gzipped\n- High performance, up to 3 times faster than lodash orderBy and sortBy \\*\n\nTry it out: https://codesandbox.io/s/sort-by-property-example-hin358\n\n## Requirements\n\nRequires Typescript 4.1+ because of the internal use of [template literals](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-4-1.html) for the autocompletion.\n\n## Installation\n\nInstall with your favorite package manager:\n\n```bash\nnpm install sort-by-property\n```\n\nor\n\n```bash\nyarn add sort-by-property\n```\n\n## Usage\n\n```typescript\n// For an array of objects\nimport { sortByProperty } from 'sort-by-property';\n\n// For one-dimensional arrays\nimport { sortBy } from 'sort-by-property';\n```\n\n## Example: Sorting an array of objects\n\n```typescript\nimport { sortByProperty } from 'sort-by-property';\n\ninterface BlogPost {\n  id: number;\n  title: string;\n  author: {\n    id: number;\n    name: string;\n  };\n}\n\nconst blogPosts: BlogPost[] = [\n  {\n    id: 1,\n    title: 'Never gonna run around and desert you',\n    author: {\n      id: 10,\n      name: 'Joe',\n    },\n  },\n  {\n    id: 2,\n    title: 'Never gonna let you down',\n    author: {\n      id: 20,\n      name: 'Ben',\n    },\n  },\n  {\n    id: 3,\n    title: 'Never gonna give you up',\n    author: {\n      id: 30,\n      name: 'Alice',\n    },\n  },\n];\n\n// Sort the blog posts by author name\nblogPosts.sort(sortByProperty('author.name', 'asc'));\n\n// If you need to use a custom locale for sorting strings, you can do\nblogPosts.sort(sortByProperty('author.name', 'asc', {locale: 'nb-no'}))\n```\n\nWill sort the array `ascending` by `author.name`:\n\n```typescript\n[\n  { id: 3, title: 'Never gonna give you up', author: { id: 30, name: 'Alice' } },\n  { id: 2, title: 'Never gonna let you down', author: { id: 20, name: 'Ben' } },\n  { id: 1, title: 'Never gonna run around and desert you', author: { id: 10, name: 'Joe' } },\n];\n```\n\nWill show a type error when you try to sort on properties that do not exist:\n\n![type-error-example](https://github.com/jvandenaardweg/typed-sort-by/blob/main/src/examples/type-error-example.png?raw=true)\n\nWill show an autocomplete of the available properties to sort on:\n\n![autocomplete](https://github.com/jvandenaardweg/typed-sort-by/blob/main/src/examples/autocomplete.png?raw=true)\n\n## Example: Sorting one-dimensional arrays\n\nThis package exports 2 methods. Use `sortBy` to sort one-dimensional arrays. This sorting method supports all the same types as `sortByProperty`.\n\n```typescript\nimport { sortBy } from 'sort-by-property';\n\nconst array = ['c', 'b', 'a'];\n\narray.sort(sortBy('asc'));\n\n// Result: ['a', 'b', 'c']\n```\n\n\u003csub\u003e\\* on an array with 10 million items: ~450ms vs ~1350ms. See the /src/examples directory.\u003c/sub\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjvandenaardweg%2Fsort-by-property","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjvandenaardweg%2Fsort-by-property","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjvandenaardweg%2Fsort-by-property/lists"}