Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

user_friendly_id

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

user_friendly_id

  • 1.0.0
  • Rubygems
  • Socket score

Version published
Maintainers
1
Created
Source

user_friendly_id

Add methods to Integer and String to convert between base10 and base34 representations of a number.

Base34 rocks!!!

  • shorter than decimal
  • shorter than hexadecimal
  • case insensitive when compared with base64
  • avoids user input confusion associated with 1/I and 0/O

Base34 is represented with the following characters: [0-9] and [A-Z, minus I & O to avoid any readability issues]

Applications of user_friendly_id could include, but are not limited to:

  • gift/promotion/discount/redemption code generation
  • much shorter string representation of long decimal strings, such as a UUID or MongoDB object id

Example Usage:

>> 33.to_base34
=> "Z"

>> 34.to_base34
=> "10"

>> "10".to_base10
=> 34

>> 1155.to_base34
=> "ZZ"

>> "ZZ".from_base34
=> 1155

>> "0000000000ZZ".from_base34
=> 1155

>> "   00ZZ  ".from_base34
=> 1155

# you can represent 10^24 - one septillion - with just 16 base34 digits, aka, a string of length 16
>> (10 ** 24).to_base34
=> "ANGMLFL5UA0AW72G"

# typical MongoDB ObjectId
>> "507f191e810c19729de860ea".hex.to_base34
=> "6RRUV0LLDJG0N6MAYBL" 

# typical UUID
>> "6948DF80-14BD-4E04-8842-7668D9C001F5".gsub(/-/,'').hex.to_base34
=> "QKH6RDPUM5ACPE8GWKWB2PSMB" 

FAQs

Package last updated on 25 Nov 2014

Did you know?

Socket

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc