• Stars
    star
    270
  • Rank 146,311 (Top 3 %)
  • Language
    Elixir
  • License
    MIT License
  • Created almost 10 years ago
  • Updated about 1 year ago

Reviews

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

Repository Details

Stringify your ids

Hashids

Module Version Hex Docs Total Download License Last Updated

Hashids lets you obfuscate numerical identifiers via reversible mapping.

This is a port of Hashids from JavaScript.

Installation

Add Hashids as a dependency to your Mix project:

defp deps do
  [
    {:hashids, "~> 2.0"}
  ]
end

Usage

Hashids encodes a list of integers into a string (technically, iodata). Some of the encoding parameters can be customized.

s = Hashids.new([
  salt: "123",  # using a custom salt helps producing unique cipher text
  min_len: 2,   # minimum length of the cipher text (1 by default)
])

cipher1 = Hashids.encode(s, 129)
#=> "pE6"

cipher2 = Hashids.encode(s, [1,2,3,4])
#=> "4bSwImsd"

# decode() always returns a list of numbers

Hashids.decode(s, cipher1)
#=> {:ok, [129]}

Hashids.decode!(s, cipher2)
#=> [1, 2, 3, 4]

It is also possible to customize the character set used for the cipher text by providing a custom alphabet. It has to be at least 16 characters long.

defmodule MyAccessToken do
  @cyrillic_alphabet "123456789абвгґдеєжзиіїйклмнопрстуфцчшщьюяАБВГҐДЕЄЖЗИІЇЙКЛМНОПРСТУФЦЧШЩЬЮЯ"
  @coder Hashids.new(alphabet: @cyrillic_alphabet)

  def encode(token_ids) do
    Hashids.encode(@coder, token_ids)
  end

  def decode(data) do
    Hashids.decode(@coder, data)
  end
end

data = MyAccessToken.encode([1234, 786, 21, 0])
#=> "ЦфюєИНаЛ1И"

MyAccessToken.decode(data)
#=> {:ok, [1234, 786, 21, 0]}

Migrating from 1.0

See the changelog.

License

This software is licensed under the MIT license.

More Repositories

1

gostart

A getting started guide for Go newcomers
1,827
star
2

porcelain

Work with external processes like a boss
Elixir
917
star
3

benchfella

Microbenchmarking tool for Elixir
Elixir
510
star
4

psdump

Extract layout from Photoshop files into one of several text-based formats.
C
85
star
5

goon

Middleman implementation for Porcelain
Go
53
star
6

chatty

Basic IRC client for writing bots
Elixir
35
star
7

pipespect

Auto-inspect for pipes
Elixir
29
star
8

ExReminder

A simple reminder app written in Elixir
Elixir
25
star
9

elixir-datetime

Elixir
23
star
10

erlang-mix-project

A sample Erlang project that uses Mix
Erlang
19
star
11

phoenix-docker-example

A demo showing how to run a Phoenix app within a docker container
Elixir
19
star
12

mix-erlang-tasks

Common tasks for Erlang projects that use Mix
Elixir
18
star
13

EGL_mac_ios

A port of the EGL API to Mac OS X (OpenGL) and iOS (OpenGL ES 1 & 2)
Objective-C
12
star
14

beamie_bot

Find beamie on #elixir-lang on irc.freenode.net
Elixir
11
star
15

commando

Advanced command-line argument parsing
Elixir
10
star
16

muweb

A minimalistic web framework
Elixir
9
star
17

miniweb

Web-related utilities
Elixir
8
star
18

TastyKVO

A simpler key-value observing API (with blocks!)
Objective-C
7
star
19

numspell

A simple python module for number spelling
Python
6
star
20

go_pil

Go
6
star
21

blog

My blog
Shell
5
star
22

gochan

Implementation of Go channels in Elixir
Elixir
5
star
23

cloaked-octo-robot

Elixir
4
star
24

EGL_samples

Sample apps for the EGL_mac_ios port
Objective-C
4
star
25

porcelain_example

Example project showing how to use Porcelain
Elixir
4
star
26

dayton-talk-cli-apps

Slides and code for my Dayton talk about command-line apps in Elixir
Elixir
3
star
27

wyvern

Versatile view engine for Elixir
Elixir
3
star
28

Remotely

A set of Objective-C classes to simplify downloading/uploading/syncing files and directories
Objective-C
2
star
29

objc.string

Self-contained library for efficient string manipulation in Objective-C.
Objective-C
2
star
30

mix-run

A sample project showing how to teach Mix to behave
Elixir
2
star
31

rust-digest

Implementations of missing hash/digest/checksum algorithms for Rust
Rust
2
star
32

simpleweb

A simple web framework in Elixir
Elixir
2
star
33

2048-elixir

Sliding tile puzzle game implemented in Elixir.
Elixir
2
star
34

french-cards

Flash cards for studying French
Python
2
star
35

ace-mode-elixir

Elixir mode for Ace editor
JavaScript
1
star
36

elixir-datefmt

Elixir
1
star
37

99-lisp-problems

My solutions
Clojure
1
star
38

Numerissimo

Client-side web app for aspired foreign language learners
JavaScript
1
star
39

bingo

Parse binary data in Go like a boss
Go
1
star
40

elixir-docs

The Unofficial Elixir Documentation
Python
1
star
41

exdoc_sphinx_formatter

Custom formatter for ExDoc
Elixir
1
star
42

ansi-progress

Elixir
1
star
43

PhotoJS

A collection of scripts for automating common gamedev related tasks in Photoshop
JavaScript
1
star
44

3d

3d
JavaScript
1
star
45

perseus

Perseus persist HTML nodes, form fields and your custom objects
JavaScript
1
star
46

Funjective

Functional programming with blocks for Objective-C
Objective-C
1
star
47

parallax

A rudimentary parallax test
JavaScript
1
star
48

requestanimationframedemo

JavaScript
1
star
49

wyvern-examples

WIP, check back later
Elixir
1
star