{"id":28394967,"url":"https://github.com/ealmansi/elen","last_synced_at":"2025-06-27T01:31:35.096Z","repository":{"id":40984178,"uuid":"114415689","full_name":"ealmansi/elen","owner":"ealmansi","description":"ELEN - Efficient Lexicographic Encoding of Numbers","archived":false,"fork":false,"pushed_at":"2022-12-30T18:31:15.000Z","size":2027,"stargazers_count":9,"open_issues_count":18,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-06-01T06:31:55.212Z","etag":null,"topics":["efficient","elen","encoding","javascript","lexicographic","numbers","peter-seymour"],"latest_commit_sha":null,"homepage":"","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/ealmansi.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-15T22:18:09.000Z","updated_at":"2025-05-17T10:25:54.000Z","dependencies_parsed_at":"2023-01-31T13:15:47.661Z","dependency_job_id":null,"html_url":"https://github.com/ealmansi/elen","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/ealmansi/elen","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ealmansi%2Felen","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ealmansi%2Felen/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ealmansi%2Felen/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ealmansi%2Felen/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ealmansi","download_url":"https://codeload.github.com/ealmansi/elen/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ealmansi%2Felen/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":262172458,"owners_count":23270011,"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":["efficient","elen","encoding","javascript","lexicographic","numbers","peter-seymour"],"created_at":"2025-05-31T19:09:32.811Z","updated_at":"2025-06-27T01:31:35.089Z","avatar_url":"https://github.com/ealmansi.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ELEN - Efficient Lexicographic Encoding of Numbers\n\n[![Build Status](https://travis-ci.org/ealmansi/elen.svg?branch=master)](https://travis-ci.com/ealmansi/elen)\n\nBased on the [paper](https://github.com/ealmansi/elen/blob/master/resources/elen.pdf) by Peter Seymour.\n\n## Installation\n\n`$ npm install --save elen`\n\n## Why would I want to use ELEN?\n\nELEN provides a way of textually representing numbers such that their natural order is preserved as a lexicographical order (i.e. alphabetical order) of their representations.\n\nImagine you need to represent numbers textually. A simple solution would be to simply call `num.toString()`. E.g.:\n\n```\n7..toString() // '7'\n11..toString() // '11'\n```\n\nFor many applications, this will suffice. However, notice that the natural order of the input numbers does not match the lexicographical order of the generated strings. I.e.:\n\n```\n[7, 11].sort((a, b) =\u003e a - b)    // [ 7, 11 ]\n['7', '11'].sort()               // [ '11', '7' ]\n```\n\nThat's where ELEN comes in. ELEN provides a way of textually representing numbers such that the following property is fulfilled:\n\n```\nassert.deepEqual(\n  nums.map(elen.encode).sort().map(elen.decode),\n  nums.sort((a, b) =\u003e a - b)\n)\n```\n\n## Usage\n\n### In Node.js\n\n```\nconst elen = require('elen')\n\nconst encoded = [\n  elen.encode(0),\n  elen.encode(42),\n  elen.encode(1),\n  elen.encode(-10),\n  elen.encode(5e100),\n  elen.encode(-Infinity),\n]\n\nencoded.sort()\n\nelen.decode(encoded[4]) // 42\n```\n\n### Browser\n\n#### Script Tag\n\n```\n\u003chtml\u003e\n  \u003chead\u003e\n    ...\n    \u003cscript src=\"https://unpkg.com/elen\"\u003e\u003c/script\u003e\n  \u003c/head\u003e\n  ...\n\u003c/html\u003e\n```\n\n## Documentation\n\n### Generate and Browse Locally\n\n```\n$ npm run docs\n```\n\n### Online\n\nBrowse automatically generated jsdocs [online](https://cdn.rawgit.com/ealmansi/elen/master/docs/global.html#encode).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fealmansi%2Felen","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fealmansi%2Felen","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fealmansi%2Felen/lists"}