GithubHelp home page GithubHelp logo

dondreytaylor / hashids Goto Github PK

View Code? Open in Web Editor NEW

This project forked from malczak/hashids

0.0 3.0 0.0 43 KB

Hashids, ported for Swift (http://www.hashids.org)

License: MIT License

Ruby 4.74% Swift 95.26%

hashids's Introduction

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

var hashids = Hashids(salt:"this is my salt");
var hash = hashids.encode(1, 2, 3); // hash:"laHquq"
var values = hashids.decode(hash!); // values:[1,2,3]

Example with custom alphabet and minimum hash length

var hashids = Hashids(salt:"this is my salt", minHashLength:8, alphabet:"abcdefghij1234567890");
var hash = hashids.encode(1, 2, 3); // hash:"514cdi42"
var values = hashids.decode(s!); // values:[1,2,3]

Example with UTF8 alphabet

var hashids = Hashids(salt:"this is my salt", minHashLength:0, alphabet:"▁▂▃▄▅▆▇█");
var hash = hashids.encode(1, 2, 3); // hash:"▅▅▂▄▃▆"
var values = hashids.decode(hash!); // values:[1,2,3]

Notes

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

  • Hashids_<UInt8> ASCII, uses String.UTF8View
  • Hashids_<UInt16> UTF16, uses String.UTF16View
  • Hashids_<UInt32> Unicode, uses String.UnicodeScalarView
Swift 2.3

For Swift 2.3 (2) version checkout branch swift-2.3

License

MIT License. See the LICENSE file.

hashids's People

Contributors

malczak avatar addie9000 avatar

Watchers

James Cloos avatar Dondrey Taylor avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.