Code Monkey home page Code Monkey logo

nanoid's Introduction

Nanoid port for Elixir

Elixir port of NanoID (https://github.com/ai/nanoid), a tiny, secure URL-friendly unique string ID generator.

Safe. It uses cryptographically strong random APIs and guarantees a proper distribution of symbols.

Compact. It uses a larger alphabet than UUID (A-Za-z0-9_~) and has a similar number of unique IDs in just 21 symbols instead of 36.

Installation

The package can be installed as Hex package:

  1. Add nanoid to your list of dependencies in mix.exs:
def deps do
  [{:nanoid, "~> 1.0.1"}]
end
  1. Run mix deps.get to fetch the package from hex

Usage

Generate NanoIDs of individual sizes and using the default alphabet

Generate a NanoID with the default size of 21 characters.

iex> Nanoid.generate()
"mJUHrGXZBZpNX50x2xkzf"

Generate a NanoID with a custom size of 64 characters.

iex> Nanoid.generate(64)
"wk9fsUrhK9k~MxY0hLazRKpcSlic8XYDFusks7Jb8FwCVnoQaKFSPsmmLHzP7qCX"

Generate NanoIDs of individual sizes and with an individual alphabet

Generate a NanoID with the default size of 21 characters and an individual alphabet.

iex> Nanoid.generate(21, "abcdef123")
"d1dcd2dee333cae1bfdea"

Generate a NanoID with custom size of 64 characters and an individual alphabet.

iex> Nanoid.generate(64, "abcdef123")
"aabbaca3c11accca213babed2bcd1213efb3e3fa1ad23ecbf11c2ffc123f3bbe"

License

The MIT License (MIT). Please see License File for more information.

nanoid's People

Contributors

railsmechanic avatar ai avatar nietaki avatar maratgaliev avatar

Watchers

James Cloos avatar Oskar Laska 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.