buzzfeed/hashids

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

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

Hashids.swift

A Swift class to generate YouTube-like ids from numbers.

Ported from Hashids.php by ivanakimov

Read documentation at http://hashids.org/php

Example Usage
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]
Notes

Internally `Hashidsis using integer array rather than strings. By default ``Hashids` class is just a type alias forHashids_<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

License

MIT License. See the LICENSE file.


This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.