Socket
Socket
Sign inDemoInstall

elen

Package Overview
Dependencies
0
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    elen

ELEN - Efficient Lexicographic Encoding of Numbers. For JavaScript.


Version published
Weekly downloads
362
increased by29.75%
Maintainers
1
Install size
1.07 MB
Created
Weekly downloads
 

Readme

Source

ELEN - Efficient Lexicographic Encoding of Numbers

Build Status

Based on the paper by Peter Seymour.

Installation

$ npm install --save elen

Why would I want to use ELEN?

ELEN 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.

Imagine you need to represent numbers textually. A simple solution would be to simply call num.toString(). E.g.:

7..toString() // '7'
11..toString() // '11'

For 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.:

[7, 11].sort((a, b) => a - b)    // [ 7, 11 ]
['7', '11'].sort()               // [ '11', '7' ]

That's where ELEN comes in. ELEN provides a way of textually representing numbers such that the following property is fulfilled:

assert.deepEqual(
  nums.map(elen.encode).sort().map(elen.decode),
  nums.sort((a, b) => a - b)
)

Usage

In Node.js

const elen = require('elen')

const encoded = [
  elen.encode(0),
  elen.encode(42),
  elen.encode(1),
  elen.encode(-10),
  elen.encode(5e100),
  elen.encode(-Infinity),
]

encoded.sort()

elen.decode(encoded[4]) // 42

Browser

Script Tag
<html>
  <head>
    ...
    <script src="https://cdn.rawgit.com/ealmansi/elen/master/dist/elen-1.0.10.min.js"></script>
  </head>
  ...
</html>

Documentation

Generate and Browse Locally

$ npm run docs

Online

Browse automatically generated jsdocs online.

Keywords

FAQs

Last updated on 29 Aug 2019

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc