{"id":13520462,"url":"https://github.com/cosimochellini/sort-es","last_synced_at":"2025-04-05T16:03:22.119Z","repository":{"id":42234519,"uuid":"240910335","full_name":"cosimochellini/sort-es","owner":"cosimochellini","description":"Blazing fast, tree-shakeable, type-safe, modern utility library to sort any type of array","archived":false,"fork":false,"pushed_at":"2025-01-28T09:18:17.000Z","size":2197,"stargazers_count":46,"open_issues_count":5,"forks_count":5,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-03-29T15:05:07.480Z","etag":null,"topics":["javascript","javascript-library","js","sort","sort-es","sorting-algorithms","tree-shakeable","ts","typescript"],"latest_commit_sha":null,"homepage":"http://sort-es.netlify.app","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/cosimochellini.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":".github/FUNDING.yml","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},"funding":{"github":["cosimochellini"],"patreon":null,"open_collective":null,"ko_fi":null,"tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"otechie":null,"custom":null}},"created_at":"2020-02-16T14:58:28.000Z","updated_at":"2025-01-28T09:18:15.000Z","dependencies_parsed_at":"2022-09-18T04:21:59.706Z","dependency_job_id":"84369cbe-6686-4397-872f-f03a8b3a102d","html_url":"https://github.com/cosimochellini/sort-es","commit_stats":{"total_commits":213,"total_committers":3,"mean_commits":71.0,"dds":0.136150234741784,"last_synced_commit":"7536b712922f7c994f7eb92ea0e255cff27cb12c"},"previous_names":[],"tags_count":67,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cosimochellini%2Fsort-es","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cosimochellini%2Fsort-es/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cosimochellini%2Fsort-es/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cosimochellini%2Fsort-es/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cosimochellini","download_url":"https://codeload.github.com/cosimochellini/sort-es/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247361598,"owners_count":20926641,"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":["javascript","javascript-library","js","sort","sort-es","sorting-algorithms","tree-shakeable","ts","typescript"],"created_at":"2024-08-01T05:02:21.500Z","updated_at":"2025-04-05T16:03:22.086Z","avatar_url":"https://github.com/cosimochellini.png","language":"TypeScript","readme":"# sort-es\n\n[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)\n![Build](https://github.com/cosimochellini/sort-es/workflows/Npm%20deploy/badge.svg)\n![Version](https://img.shields.io/npm/v/sort-es.svg)\n[![Known Vulnerabilities](https://snyk.io/test/npm/sort-es/badge.svg)](https://snyk.io/test/npm/sort-es)\n![GitHub last commit (branch)](https://img.shields.io/github/last-commit/cosimochellini/sort-es)\n![npm](https://img.shields.io/npm/dw/sort-es)\n![npm total](https://img.shields.io/npm/dt/sort-es.svg)\n[![codecov](https://codecov.io/gh/cosimochellini/sort-es/branch/master/graph/badge.svg)](https://codecov.io/gh/cosimochellini/sort-es)\n\n## Blazing fast, tree-shakeable, type-safe, modern utility library to sort any type of array\n\n## Docs : https://sort-es.netlify.app/\n\n# Getting started\n\n## installation\n\nThe library is available as a [npm package](https://www.npmjs.com/package/sort-es).\nTo install the package, run:\n\n```\nnpm install sort-es\n# or\nyarn add sort-es\n```\n\nStart using:\n\n```typescript\nimport {byString} from 'sort-es'\n\nconst unsorted = [\"xxx\", \"bbbb\", \"zzz\", \"cccc\", \"aaa\"];\nconst sorted = unsorted.sort(byString());\n\nconsole.log(sorted); //(5) [\"aaa\", \"bbbb\", \"cccc\", \"xxx\", \"zzz\"]\n```\n\nUse directly in the browser\n\n```html\n\n\u003cscript src='https://cdn.jsdelivr.net/npm/sort-es/dist/index.umd.js'\u003e\u003c/script\u003e\n\u003cscript\u003e\n  const unsorted = [\"xxx\", \"bbbb\", \"zzz\", \"cccc\", \"aaa\"];\n  const sorted = unsorted.sort(sort.byString());\n\n  console.log(sorted); //(5) [\"aaa\", \"bbbb\", \"cccc\", \"xxx\", \"zzz\"]\n\u003c/script\u003e\n\n//or via browser modules\n\n\u003cscript type='module'\u003e\n  import {byString} from 'https://cdn.jsdelivr.net/npm/sort-es/dist/index.mjs'\n\n  const unsorted = [\"xxx\", \"bbbb\", \"zzz\", \"cccc\", \"aaa\"];\n  const sorted = unsorted.sort(byString());\n\n  console.log(sorted); //(5) [\"aaa\", \"bbbb\", \"cccc\", \"xxx\", \"zzz\"]\n\u003c/script\u003e\n```\n\n## Some mind-blowing example\n\n**sort by a single property**\n\n```typescript\n//js or ts file\nimport {byValue, byNumber, byString} from 'sort-es'\n\nconst arrayUnsorted = [\n  {prop: \"xxx\", foo: 34},\n  {prop: \"aaa\", foo: 325},\n  {prop: \"zzz\", foo: 15},\n  {prop: \"ccc\", foo: 340},\n  {prop: \"bbb\", foo: 0}\n];\n\n//this sort by the foo property ascending\nconst sortedByFoo = arrayUnsorted.sort(byValue((i) =\u003e i.foo, byNumber()));\nconsole.log(sortedByFoo); //(5) [{prop: \"bbb\", foo : 0}, {prop: \"zzz\", foo: 15}, .....];\n\n//this sort by the prop property descending\nconst sortedByProp = arrayUnsorted.sort(byValue((i) =\u003e i.prop, byString({desc: true})));\nconsole.log(sortedByProp); //(5) [{prop: \"zzz\", foo : 15}, {prop: \"xxx\", foo: 34}, .....];\n```\n\n**sort by a multiple property**\n\n```javascript\n//js or ts file\nimport {byNumber, byString, byValues} from \"sort-es\";\n\nconst objsToSort = [\n  {id: 2, name: 'teresa'},\n  {id: 3, name: 'roberto'},\n  {id: 2, name: 'roberto'}\n];\n\n//i sort by THEIR NAMES and THEN by their ids\nconst sortedObject = objsToSort.sort(byValues([\n  [(x) =\u003e x.name, byString()],\n  [(x) =\u003e x.id, byNumber()]\n]));\n\nconsole.log(sortedObject); //[{roberto, 2}, {roberto, 3}, {teresa, 2}];\n\n//i sort by THEIR IDS and THEN by their names\nconst sortedObject2 = objsToSort.sort(byValues([\n  [(x) =\u003e x.id, byNumber()],\n  [(x) =\u003e x.name, byString()]\n]));\nconsole.log(sortedObject2); //[{roberto, 2}, {teresa, 2}, {roberto, 3}];\n\n//i sort by THEIR IDS and THEN by their names DESCENDING\nconst sortedObject3 = objsToSort.sort(byValues([\n  [(x) =\u003e x.id, byNumber()],\n  [(x) =\u003e x.name, byString({desc: true})],\n]));\nconsole.log(sortedObject3); //[{teresa, 2}, {roberto, 2}, {roberto, 3}];\n\n```\n\n**typescript types check**\n\n```typescript\n//ts file\nimport {byValue, byNumber, byString} from 'sort-es'\n\nconst objsArray = [{numbProp: 2, stringProp: 'a'}, {numbProp: 3, stringProp: 'f'}];\n\n//Incorrect sort property\nconst incorrectSortedArray = objsArray.sort(byValue(i =\u003e i.numbProp, byString()));\n//ts check error : Type 'number' is not assignable to type 'string'.\n\n//Correct sort type\nconst sortedArray = objsArray.sort(byValue(i =\u003e i.numbProp, byNumber()))\n//ts check ok\n\n```\n\n## See full Docs\n\n### [**sort-es.netlify.app**](https://sort-es.netlify.app)\n\n# License\n\nMIT © Cosimo chellini\n","funding_links":["https://github.com/sponsors/cosimochellini"],"categories":["TypeScript"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcosimochellini%2Fsort-es","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcosimochellini%2Fsort-es","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcosimochellini%2Fsort-es/lists"}