Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/alexagranov/user_friendly_id
Make giant IDs pretty, smaller, case insensitive and avoid 1/I, 0/O confusion using base34. Useful for discount/promo codes, Mongo Ids, UUID shortening, etc.
https://github.com/alexagranov/user_friendly_id
base34 friendly-id uuid
Last synced: 22 days ago
JSON representation
Make giant IDs pretty, smaller, case insensitive and avoid 1/I, 0/O confusion using base34. Useful for discount/promo codes, Mongo Ids, UUID shortening, etc.
- Host: GitHub
- URL: https://github.com/alexagranov/user_friendly_id
- Owner: alexagranov
- License: mit
- Created: 2013-02-08T20:08:14.000Z (almost 12 years ago)
- Default Branch: master
- Last Pushed: 2017-03-30T01:06:06.000Z (almost 8 years ago)
- Last Synced: 2024-10-25T03:19:16.890Z (2 months ago)
- Topics: base34, friendly-id, uuid
- Language: Ruby
- Homepage:
- Size: 14.6 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[![Build Status](https://travis-ci.org/alexagranov/user_friendly_id.svg?branch=master)](https://travis-ci.org/alexagranov/user_friendly_id)
[![Gem Version](https://badge.fury.io/rb/user_friendly_id.svg)](https://badge.fury.io/rb/user_friendly_id)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/OBase34 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 idExample Usage:
==============```ruby
>> 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"```