{"id":16275018,"url":"https://github.com/whawker/ubersort","last_synced_at":"2025-04-08T16:27:14.621Z","repository":{"id":23013613,"uuid":"26364449","full_name":"whawker/ubersort","owner":"whawker","description":"Configurable priority based sorting ","archived":false,"fork":false,"pushed_at":"2014-11-09T23:45:21.000Z","size":736,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-14T14:01:51.493Z","etag":null,"topics":["javascript","priority","sorting"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/whawker.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-11-08T15:20:14.000Z","updated_at":"2021-03-17T17:39:09.000Z","dependencies_parsed_at":"2022-08-21T17:31:39.276Z","dependency_job_id":null,"html_url":"https://github.com/whawker/ubersort","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/whawker%2Fubersort","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/whawker%2Fubersort/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/whawker%2Fubersort/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/whawker%2Fubersort/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/whawker","download_url":"https://codeload.github.com/whawker/ubersort/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247880603,"owners_count":21011697,"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","priority","sorting"],"created_at":"2024-10-10T18:31:37.589Z","updated_at":"2025-04-08T16:27:14.594Z","avatar_url":"https://github.com/whawker.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Ubersort\n\nConfigurable priority based sorting for arrays of complex objects.\n\n## Using\n`bower install --save ubersort`\n\n## Built in comparators\n* **text** compare as case sensitive strings\n* **numeric** compare by numeric value\n* *Custom* A function added with `Array.prototype.ubersort.addComparator` (See below)\n\n## Methods\n### ubersort( sortConfig )\n```javascript\nmyArr.ubersort({ property: 'propertyName', comparator: 'text' });\n```\n```javascript\nmyArr.ubersort({\n  property: 'propertyName',\n  comparator: function (a, b) {\n    return a - b;\n  }\n});\n```\n```javascript\nmyArr.ubersort([\n  { property: 'nested.propertyName', comparator: 'text' },\n  { property: 'otherProperty', comparator: 'numeric', reverse: true}\n]);\n```\n\n#### PARAMETERS\n* **sortConfig** `Array|Object` sorting options (see below)\n\n##### Sorting options, \nArray of objects with the following properties, **or** single object with properties\n```javascript\n{\n  property: 'String', // Name of object property to be compared, can be a nested property i.e. myObj.subObj.property\n  comparator: 'String|Function', // Name of function to be used, or a function definition\n  reverse: 'Boolean', // If true, sort in descending order, default false\n}\n```\n\n### Array.prototype.ubersort.addComparator( name, sortDefinition )\nAdd a function that can later be reference by it's given name\n```javascript\nArray.prototype.ubersort.addComparator('nearestToMillion', function (a, b) {\n  var aVal = Math.abs(a - 1000000),\n      bVal = Math.abs(b - 1000000);\n  return aVal - bVal;\n});\nmyArray.ubersort({ property: 'propName', comparator: 'nearestToMillion' });\n```\n#### PARAMETERS\n* **name** `String` name of sorting function\n* **sortDefinition** `Function` a sorting function, that takes to values to be compared\n\n## Example\nThe order of a football league table has many rules\n\n\u003cblockquote\u003e\n  \u003cp\u003eIn the league format, the ranking in each group is determined as follows\u003c/p\u003e\n  \u003col\u003e\n    \u003cli\u003egreatest number of points obtained in all group matches;\u003c/li\u003e\n    \u003cli\u003egoal difference in all group matches;\u003c/li\u003e\n    \u003cli\u003egreatest number of goals scored in all group matches.\u003c/li\u003e\n  \u003c/ol\u003e\n\u003c/blockquote\u003e\n\nThe second and third rules only come into play if the previous rules yield no difference.\n\n```javascript\nvar teams = [\n  {name: 'Ghana', played: 3, won: 0, drawn: 1, lost: 2, gf: 4, ga: 6, gd: -2, points: 1},\n  {name: 'USA', played: 3, won: 1, drawn: 1, lost: 1, gf: 4, ga: 4, gd: 0, points: 4},\n  {name: 'Germany', played: 3, won: 2, drawn: 1, lost: 0, gf: 7, ga: 2, gd: 5, points: 7},\n  {name: 'Portugal', played: 3, won: 1, drawn: 1, lost: 1, gf: 4, ga: 7, gd: -3, points: 4}\n];\n\nteams.ubersort([\n  {property: 'points', comparator: 'numeric', reverse: true},\n  {property: 'gd', comparator: 'numeric', reverse: true},\n  {property: 'gf', comparator: 'numeric', reverse: true}\n]);\n\nconsole.log(teams);\n/*\n[\n  {name: 'Germany', played: 3, won: 2, drawn: 1, lost: 0, gf: 7, ga: 2, gd: 5, points: 7},\n  {name: 'USA', played: 3, won: 1, drawn: 1, lost: 1, gf: 4, ga: 4, gd: 0, points: 4},\n  {name: 'Portugal', played: 3, won: 1, drawn: 1, lost: 1, gf: 4, ga: 7, gd: -3, points: 4},\n  {name: 'Ghana', played: 3, won: 0, drawn: 1, lost: 2, gf: 4, ga: 6, gd: -2, points: 1}\n]\n*/\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwhawker%2Fubersort","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwhawker%2Fubersort","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwhawker%2Fubersort/lists"}