Thanks to visit codestin.com
Credit goes to github.com

Skip to content

arkdro/hashids-erlang

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

40 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

hashids

Hashids

Build status

The Erlang port of Hashids from JavaScript.

Installation

Add Hashids as a dependency to rebar.config

{deps,
    [
        {hashids, ".*",  {git, "git://github.com/snaiper80/hashids-erlang.git",  {tag, "1.0.2"}}}
    ]
}.

Usage

Hashids encodes a integer or a list of integers.

1> hashids:new().   % create a new hashids context with default options
{hashids_context,"this is my salt",8,
                 "5N6y2rljDQak4xgzn8ZR1oKYLmJpEbVq3OBv9WwXPMe7",
                 "UHuhtcITCsFifS","AdG0"}

2> hashids:new([]). % same as new/0
{hashids_context,"this is my salt",8,
                 "5N6y2rljDQak4xgzn8ZR1oKYLmJpEbVq3OBv9WwXPMe7",
                 "UHuhtcITCsFifS","AdG0"}

3> Ctx = hashids:new([{salt, "this is my salt"}, {min_hash_length, 8}]).
{hashids_context,"this is my salt",8,
                 "5N6y2rljDQak4xgzn8ZR1oKYLmJpEbVq3OBv9WwXPMe7",
                 "UHuhtcITCsFifS","AdG0"}

4> Encoded = hashids:encode(Ctx, 12345).
"B0NkK9A5"

5> Encoded2 = hashids:encode(Ctx, [12345, 6789]).
"Y9awcOLv"

decode/2 returns a list of numbers

6> hashids:decode(Ctx, Encoded).
[12345]

7> hashids:decode(Ctx, Encoded2).
[12345,6789]

You can use customized characters (least 16 characters long)

Ctx = hashids:new([{salt, "this is my salt"},
                   {min_hash_length, 8}, {default_alphabet, "ABCDEFGhijklmn34567890-:"}]).

License

This software is licensed under the MIT license.

About

The Erlang port of Hashid to generate YouTube-like hashids from one or many numbers.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Erlang 97.0%
  • Makefile 3.0%