alphanumeric-encoder
v1.6.1
Published
Encodes a number to a letter representation, or decodes it back
Downloads
10,211
Maintainers
Readme
- :book: Getting Started
- :gear: API Documentation
- :hammer_and_wrench: Node and Operating System Support Policy
- :clipboard: License and Development
- :envelope: Contact
:book: Getting Started
Purpose
alphanumeric-encoder
is a lightweight library with no dependencies. It can encode an integer into a letter representation, decode the letter back into a number, and deconstruct combined strings of letters and numbers into an array of decoded numbers.
This is useful for converting letter indexes (used by people) to numbers (used by computers). Examples include:
- Spreadsheet columns (e.g. Microsoft Excel's end column is "XFD" which corresponds to 16384)
- Game boards (e.g. Chess, Battleship) use letters and numbers to identify the grid
- Geodesy grid reference systems (e.g. the United States National Grid)
Install as an NPM Package
npm install alphanumeric-encoder
Use in Javascript
const AlphanumericEncoder = require('alphanumeric-encoder')
const encoder = new AlphanumericEncoder()
console.log(encoder.encode(5)) // 'E'
console.log(encoder.encode(48)) // 'AV'
console.log(encoder.encode(733)) // 'ABE'
console.log(encoder.decode('A')) // 1
console.log(encoder.decode('AC')) // 29
console.log(encoder.decode('ANE')) // 1045
console.log(encoder.deconstruct('C7')) // [3, 7]
console.log(encoder.deconstruct('AC22')) // [29, 22]
console.log(encoder.deconstruct('C3ABC123EFGH456')) // [3, 3, 731, 123, 92126, 456]
:gear: API Documentation
See the API for more detailed information on how to use the class.
:hammer_and_wrench: Node and Operating System Support Policy
The test suite has successfully run on all combinations of:
This project supports Long-Term Support, Current, and Maintenance versions of node. Once a version reaches end of life, the CI scripts will no longer support them. Odd Node versions will only receive support while in a current status.
Other Node versions and operating systems might support the library, but the tests have not verified other combinations.
:clipboard: License and Development
alphanumeric-encoder
and all other files in this repository are distributed as free and open-source software under the MIT License, © 2022.
Both contributions and bug reports welcome. See the change log for specific details of each release.
Leave a :star2: if you find this project useful!
:envelope: Contact
Maintained by M. Scott Lassiter.