• Stars
    star
    10
  • Rank 1,750,148 (Top 36 %)
  • Language
    Crystal
  • License
    MIT License
  • Created almost 6 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Base62 encoder/decoder for Crystal

Base62.cr CI Releases License

Crystal shard for Base62 encoding/decoding. It's especially useful for converting data into shortened strings suitable for URL shortening and/or obfuscating auto-incrementing resource ids from being exposed through RESTful APIs.

What is Base62 encoding?

Base62 encoding converts numbers to ASCII strings (0-9, a-z, and A-Z) and vice versa, which typically results in comparatively short strings. Such identifiers also tend to be more readily identifiable by humans.

Installation

Add this to your application's shard.yml:

dependencies:
  base62:
    github: Sija/base62.cr

Usage

require "base62"

Base62.encode(999)  # => "G7"
Base62.decode("G7") # => 999

This uses the default ASCII character set for encoding/decoding.

It's also possible to define a custom character set instead:

charset = "~9876543210ABCDEFGHIJKLMNOPQRSTU$#@%!abcdefghijklmnopqrstuvw-="

Base62.encode(999, charset)  # => "F3"
Base62.decode("F3", charset) # => 999

Note that charset typically expects the respective string to contain exactly 62 unique characters. It's also possible to use character sets with more than 62 characters to achieve shorter identifiers for large numbers.

Contributing

  1. Fork it (https://github.com/Sija/base62.cr/fork)
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

Contributors

  • @Sija Sijawusz Pur Rahnama - creator, maintainer

More Repositories

1

garb

A Ruby wrapper for the Google Analytics API
Ruby
147
star
2

raven.cr

Raven is a Crystal client for Sentry
Crystal
120
star
3

debug.cr

Debug macro for Crystal
Crystal
92
star
4

ipaddress.cr

A Crystal library to handle IPv4 and IPv6 addresses in a modern and productive way.
Crystal
43
star
5

retriable.cr

Retriable.cr is a simple DSL to retry failed code blocks
Crystal
38
star
6

any_hash.cr

Better JSON::Any for Crystal
Crystal
33
star
7

blurhash.cr

A pure Crystal implementation of BlurHash algorithm
Crystal
22
star
8

backtracer.cr

Crystal shard aiming to assist with parsing backtraces into a structured form.
Crystal
16
star
9

ksuid.cr

Crystal implementation of K-Sortable Globally Unique IDs
Crystal
16
star
10

crystal-dash-docset

Dash docset generator for Crystal
Shell
16
star
11

gphoto2.cr

Crystal shard wrapping libgphoto2
Crystal
15
star
12

climate.cr

Tiny tool to make your CLI output 🌈 coloured
Crystal
14
star
13

serialport.cr

Crystal bindings for libserialport: cross-platform library for accessing serial ports.
Crystal
12
star
14

crystal-environment

Crystal::Environment
Crystal
7
star
15

gphoto2-web

Web API for libgphoto2
Crystal
6
star
16

gitbook2pdf

CLI utility to turn a published GitBook website into a collection of PDFs for offline reading
JavaScript
3
star
17

Gizmo

Quick'n'easy file based content management system
PHP
2
star
18

jsonl.cr

Crystal shard for handling JSONL (JSON Lines) parsing
Crystal
1
star
19

Sija

1
star
20

coffeeshop

Unfinished Coffee powered, Express based framework for Node.js
CoffeeScript
1
star
21

kPilot.w3

Web backend for kPilot Konnekt IM plugin.
PHP
1
star
22

markdown

PSR-0 compliant Markdown library
PHP
1
star
23

seedling

Rails 3 plugin for a database-independent YAML seeds import/export.
Ruby
1
star
24

MazeSolver

Maze solver written in PHP 5.
PHP
1
star
25

kZmieniacz

kZmieniacz to wtyczka dla komunikatora Konnekt pozwalająca zmieniać status opisowy jednocześnie we wszystkich wykorzystywanych sieciach.
C++
1
star
26

photoindex

Ancient, self-contained php gallery script.
PHP
1
star
27

resque-dry

Ruby
1
star
28

swift

Never finished C++ templating engine.
C++
1
star
29

kulturadaru

PHP
1
star
30

smartypants

PSR-0 compliant Smartypants library
PHP
1
star
31

kAway

Away system for the Konnekt IM
C++
1
star
32

git-rewrite-author

CLI tool for rewriting author/committer history of a git repository
Crystal
1
star
33

QRKit

QR Reader in Objective C ported from zxing
C++
1
star
34

thumb-cutter

Blazingly fast thumb cutting and image juggling middleware for any node/express.js kitchen sink
JavaScript
1
star
35

sunspot_resque

Sunspot-Resque Session Proxy
Ruby
1
star
36

jquery.clamp

JavaScript with CSS "overflow: ellipsis" line clamping, as jQuery plugin and standalone AMD module
CoffeeScript
1
star