mexx / hashids-fs

A hashids (http://hashids.org) implementation in F#

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Hashids-fs

A hashids implementation in F#. It allows the encoding of one or more numbers into a single YouTube-like random string. Please visit http://hashids.org for implementations in other languages.

Usage

Open the Hashids namespace

open Hashids

Create a configuration

A HashidConfiguration stores the salt, minimum id length, alphabet, and separators.

let config = 
    HashidConfiguration.create 
        { Salt = "zupdog"
          MinimumHashLength = 0
          Alphabet = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"
          Separators = "cfhistuCFHISTU" }

Alternatively, the values from the defaultOptions record can be modified.

let config = 
    HashidConfiguration.create 
        { HashidConfiguration.defaultOptions with Salt = "zupdog" }

Create an encode and decode function

Create curried versions of Hashid.encode64 and Hashid.decode64 with a baked in configuration.

let encode = Hashid.encode64 config
let decode = Hashid.decode64 config

Encode and decode numbers

let id = encode [| 73L; 88L |]
let numbers = decode id

The resulting id will be rlVfvd.

Building

Hashids-fs uses FAKE for building. (http://fsharp.github.io/FAKE/) Simply run build.bat and look for the files in the build folder.

About

A hashids (http://hashids.org) implementation in F#

License:MIT License


Languages

Language:F# 99.3%Language:Batchfile 0.7%