Giter VIP home page Giter VIP logo

hashids-fs's Introduction

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.

alt text

Usage in F#

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 = "this is my salt"
          MinimumHashLength = 0
          Alphabet = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"
          Separators = "cfhistuCFHISTU" }

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

let config = 
    HashidConfiguration.create 
        { HashidConfiguration.defaultOptions with Salt = "this is my salt" }

If the only thing that needs changing is the salt, use withSalt.

let config = HashidConfiguration.withSalt "this is my salt"

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.

Usage in C#

Using Hashids in C# is very similar to F# except for the currying. For a more object oriented approach please try Hashids.net (https://github.com/ullmark/hashids.net).

var config = HashidConfiguration.Create("this is my salt");
var id = Hashid.Encode(config, new int[] { 1, 2, 3 });
var numbers = Hashid.Decode(config, id);

Installation

Install the package with NuGet.

Install-Package hashids-fs

hashids-fs's People

Contributors

rbertels avatar dstockhammer avatar

Stargazers

Felix Wang avatar Asti avatar Sebastian Brandt avatar Yves Reynhout avatar  avatar Dejan Milicic avatar Yuri avatar David.Gao avatar Jared Updike avatar  avatar Finn Newick avatar Chris Anderson avatar Max Malook avatar jd avatar

Watchers

 avatar

hashids-fs's Issues

Hashid.encode returns empty string if one number is zero

If one of the integers in Hashid.encode is zero, an empty string is returned.
I expected it to return a valid hash, at least hashids.org suggests it would work: "Do not try to encode negative numbers. It won't work. The library currently supports only positive numbers and zero."

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.