Socket
Socket
Sign inDemoInstall

base62

Package Overview
Dependencies
0
Maintainers
1
Versions
17
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    base62

Javascript Base62 encode/decoder


Version published
Maintainers
1
Install size
25.7 kB
Created

Readme

Source

Base62.js

build status npm version devDependency Status Gitter chat

A javascript Base62 encode/decoder for node.js

What is Base62 encoding?

From wikipedia:

Base62 is a priority system to the base 62, which for encoding large numbers using ASCII is character. The digits 0-9 (value 0-9), uppercase letters A-Z (value 10-35) and lowercase letters a-z (value 36-61) are used.

Due to the high number of base formed shorter strings than with the decimal or hexadecimal system , which mainly offers two advantages:

  • They can be entered by a human being faster and with a smaller risk of error. In this case, a font should be selected in which characters that can be confused, such as small L and large i, or zero, and large O, are distinguishable.
  • Length restrictions, eg when a number is to be used as part of an identifier or file name, can be bypassed. However, it should be noted that the processing system is case-sensitive.

Install

npm install base62

or for yarn:

yarn add base62

Usage

Default Character Set Example

Base62 = require('base62')
Base62.encode(999)  // 'g7'
Base62.decode('g7') // 999

Custom Character Set Example

The default character set is 0-9a-zA-Z. This can be updated to a custom character set. Naturally, it must be 62 characters long.

Instead of the character set 0-9a-zA-Z you want to use 0-9A-Za-z, call the setCharacterSet() method on the Base62 object passing in the string "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz". Note that all characters must be unique.

Base62 = require('base62')
Base62.setCharacterSet("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz");
Base62.encode(999)  // 'G7'
Base62.decode('G7') // 999

Development

Source hosted at GitHub. Report Issues/Feature requests on GitHub Issues.

Note on Patches/Pull Requests

  • Fork the project.
  • Make your feature addition or bug fix.
  • Add tests for it. This is important so I don't break it in a future version unintentionally.
  • Send me a pull request. Bonus points for topic branches.

Copyright (c) 2016 Andrew Nesbitt. See LICENSE for details.

Keywords

FAQs

Last updated on 10 Feb 2018

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