Code Monkey home page Code Monkey logo

nanoid.rb's Introduction

nanoid.rb

This is ReadMe for version 2.0, if you looking for version compatible with NanoID 1.x look in branch v1.x.

A tiny, secure URL-friendly unique string ID generator.

Ruby implementation of original NanoID https://github.com/ai/nanoid

Installation

Into Gemfile / gems.rb add:

gem 'nanoid'

Usage

require 'nanoid'

Nanoid.generate

Options

parameter type description
size integer Length of generated string
alphabet string Collection of characters used for generated string
non_secure boolean Switch to use non-secure generated string. Do not use if you don't need

Default options:

Size: 21 character length

Alphabet: _-0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ

Non secure: false

Examples

Simple generate unique string

require 'nanoid'

Nanoid.generate
# => "MVNBLMwrcdbKjpo73qsmN"

Change length of generated string

require 'nanoid'

Nanoid.generate(size: 10)
# => "zRTPzok801"

Change alphabet of generated string

require 'nanoid'

Nanoid.generate(alphabet: '1234567890abcdef')
# => "84e292c6aabbbf50bf087"

Change size and alphabet of generated string

require 'nanoid'

Nanoid.generate(size: 14, alphabet: '1234567890abcdef')
# => "c5db3470fadf94"

Use non-secure generator

require 'nanoid'

Nanoid.generate(non_secure: true)
# => "-BX3dH02BmRX9Al4drpIb"

nanoid.rb's People

Contributors

antoshalee avatar citizen428 avatar dependabot-preview[bot] avatar okuramasafumi avatar radeno avatar v-kolesnikov avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

nanoid.rb's Issues

This gem is obsolete as of Ruby 2.7+

Howdy.

I was looking for a Rubiesque implementation of NanoID and first found this. Looking at the code, I wondered if SecureRandom might have a better implementation.

Come to find out SecureRandom.urlsafe_base64() returns the same result as NanoID. No gem required. Would you mind updating your Readme to the more appropriate Ruby solution? Thanks.

API 2.0

Let’s update the library to be compatible with the latest Nano ID 2.0:

  • Replace ~ to - in default alphabet
  • Add non-secure fast generator

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.