Name: hashids
Owner: BuzzFeed
Description: Hashids, ported for Swift (http://www.hashids.org)
Created: 2015-08-24 20:52:32.0
Updated: 2017-04-11 19:59:24.0
Pushed: 2016-11-28 15:45:42.0
Homepage: null
Size: 58
Language: Swift
GitHub Committers
User | Most Recent Commit | # Commits |
---|
Other Committers
User | Most Recent Commit | # Commits |
---|
A Swift class to generate YouTube-like ids from numbers.
Ported from Hashids.php by ivanakimov
Read documentation at http://hashids.org/php
hashids = Hashids(salt:"this is my salt");
hash = hashids.encode(1, 2, 3); // hash:"laHquq"
values = hashids.decode(hash!); // values:[1,2,3]
Example with custom alphabet and minimum hash length
hashids = Hashids(salt:"this is my salt", minHashLength:8, alphabet:"abcdefghij1234567890");
hash = hashids.encode(1, 2, 3); // hash:"514cdi42"
values = hashids.decode(s!); // values:[1,2,3]
Example with UTF8 alphabet
hashids = Hashids(salt:"this is my salt", minHashLength:0, alphabet:"????????");
hash = hashids.encode(1, 2, 3); // hash:"??????"
values = hashids.decode(hash!); // values:[1,2,3]
Internally `Hashids
is using integer array rather than strings.
By default ``
Hashids` class is just a type alias for
Hashids_<UInt32>``
and is using unicode scalars for all string manipulations. This makes it possible to use unicode alphabets eq. ':hatched_chick::pig::cat::dog::mouse:'.
Generic version `Hashids_<T>
` can be used for both ASCII and UTF alphabets. Based on how characters are interpreted in Swift there are possible 3 scenarios
MIT License. See the LICENSE
file.