{"id":16440465,"url":"https://github.com/icai/token-sort","last_synced_at":"2025-06-15T09:08:43.942Z","repository":{"id":57377717,"uuid":"115850995","full_name":"icai/token-sort","owner":"icai","description":"Token(ize) Sort, also support weight sort","archived":false,"fork":false,"pushed_at":"2020-05-30T10:54:03.000Z","size":75,"stargazers_count":1,"open_issues_count":5,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-06-05T05:42:18.070Z","etag":null,"topics":["sort","token","tokenize"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/token-sort","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/icai.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":"2017-12-31T08:03:37.000Z","updated_at":"2018-11-05T02:58:42.000Z","dependencies_parsed_at":"2022-09-26T16:41:51.469Z","dependency_job_id":null,"html_url":"https://github.com/icai/token-sort","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/icai/token-sort","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/icai%2Ftoken-sort","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/icai%2Ftoken-sort/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/icai%2Ftoken-sort/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/icai%2Ftoken-sort/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/icai","download_url":"https://codeload.github.com/icai/token-sort/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/icai%2Ftoken-sort/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259949680,"owners_count":22936411,"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":["sort","token","tokenize"],"created_at":"2024-10-11T09:12:09.727Z","updated_at":"2025-06-15T09:08:43.920Z","avatar_url":"https://github.com/icai.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Token(ize) Sort\n\n[![Greenkeeper badge](https://badges.greenkeeper.io/icai/token-sort.svg)](https://greenkeeper.io/)\n\n[![npm](https://img.shields.io/npm/v/token-sort.svg)](https://www.npmjs.org/package/token-sort)\n[![npm](https://img.shields.io/npm/dm/token-sort.svg)](https://www.npmjs.org/package/token-sort)\n[![Build Status](https://travis-ci.org/icai/token-sort.svg?branch=master)](https://travis-ci.org/icai/token-sort)\n[![GitHub issues](https://img.shields.io/github/issues-closed/icai/token-sort.svg)](https://github.com/icai/token-sort/issues)\n[![GitHub contributors](https://img.shields.io/github/contributors/icai/token-sort.svg)](https://github.com/icai/token-sort/graphs/contributors)\n[![David](https://img.shields.io/david/icai/token-sort.svg)](https://david-dm.org/icai/token-sort)\n[![David Dev](https://img.shields.io/david/dev/icai/token-sort.svg)](https://david-dm.org/icai/token-sort?type=dev)\n[![DUB](https://img.shields.io/dub/l/vibe-d.svg)](https://github.com/icai/token-sort/blob/master/LICENSE)\n\n\u003c!-- [![Coveralls](https://img.shields.io/coveralls/icai/token-sort.svg)](https://coveralls.io/github/icai/token-sort?branch=master) --\u003e\n\n\u003e make sort more humane.\n\nToken(ize) Sort for Array, for human, current project  https://github.com/icai/token-sort.\n\n## OverView\n\ntitle sort, title sort, 1,10,23456789, 😑\n\n![](https://raw.githubusercontent.com/icai/token-sort/master/error.png?goodluck)\n\n🤔, may be better.\n\n## Usage\n\n\n### Install\n\n```bash\nnpm install token-sort --save\n```\n\n### Options\n\n1. Overview\n\n```javascript\ntokenSort(arr[,setting])\n\n@setting\n{\n  field: String:'sort field for arr item'\n  order: String: ['asc', 'desc']\n  tokens: Object[Array][RegExp:String]: 'custom tokens'\n}\n\n@tokens {\n    @exmaple\n    number: [\n      \"[\\\\d.]+\",\n      \"['零一二三四五六七八九十百千万亿']+\",\n    ]\n}\n```\n\n2. Use Short\n\n```javascript\ntokenSort(arr[,field][,order])\n\n@exmaple\ntokenSort(arr, 'title') // field\ntokenSort(arr, 'asc') // order\ntokenSort(arr, 'title', 'asc') // field and order\n\n```\n\n3. Sort by weight\n\n```javascript\n@exmaple\n let arr =[{\n    title: '第四章',\n  }, {\n    title: '第一章',\n  }, {\n    title: '第二章',\n  },{\n    title: '第七章last',\n    _score: 0.3\n  },{\n    title: '第七章top',\n    _score: 0.4\n  }];\n\n  tokenSort(arr, 'title')\n  // Output [\n  // {\"title\":\"第一章\"},\n  // {\"title\":\"第二章\"},\n  // {\"title\":\"第四章\"},\n  // {\"title\":\"第七章top\",\"_score\":0.4},\n  // {\"title\":\"第七章last\",\"_score\":0.3}\n  // ]\n```\n\n### Demo\n\n```javascript\nconst tokenSort = require('token-sort');\n\n// Object::Array\nlet arr = [{\n  title: '第四章'\n},{\n  title: '第一章',\n}, {\n  title: '第二章'\n}];\ntokenSort(arr, {\n  field: 'title'\n})\n// equal to:\ntokenSort(arr, 'title');\n\n// String::Array\nlet longshort = [\n  \"第1章 课程3总结\",\n  \"第1章 课程2概要分类\",\n  \"第1章 课程1概要\",\n]\ntokenSort(longshort);\n\n```\n\nIf you need to see more demos, please checkout the unit tests.\n\n-EOF\n\nHappy 2018.\n\n## License\n\nCopyright (c) 2018 Terry Cai. Licensed under the MIT license.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ficai%2Ftoken-sort","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ficai%2Ftoken-sort","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ficai%2Ftoken-sort/lists"}