Git Product home page Git Product logo

regle's Introduction

regle

Haitian Creole for Hash

What is it?

Regle is a collection of utilities that generate ids.

Regle currently contains:

  • An Hashids port that generates short, unique, non-sequential ids from numbers.
  • An Optimus port that obfuscates ids based on Knuth's multiplicative hashing method.
  • An Nano ID port that is a tiny, platform dependant secure, URL friendly, unique string ID generator.

Installation

You need to install the following libraries from HaxeLib and GitHub.

  1. regle - haxelib git regle https://github.com/skial/regle master src
  2. hashids - haxelib git hashids https://github.com/kevinresol/hashids master src
    • This is optional, but it is more widely used.

Then in your .hxml file, add -lib regle and you're set.

Hashids Usage

package ;

import uhx.uid.Hashids;

class Main {
	
	public static function main() {
		var hids = new Hashids();
		var id = hids.encode( [1, 2, 3] ); // `id` is now `o2fXhV`.
		var values = hids.decode( id ); // `values` is now `[1, 2, 3]`.
	}
	
}
Notes
  • If you already have the hashids library included, uhx.uid.Hashids points to that instead of the one included.
  • A bytes based implementation, which should be faster, is available via -D hashids_bytes. Compile bench.hxml and run one of the target outputs to see the speed differences.

Optimus Usage

package ;

import uhx.uid.Optimus;

class Main {

	public static function main() {
		var optimus = new Optimus(1580030173, 59260789, 1163945558);
		var id = optimus.encode(15); // 1103647397
		var value = optimus.decode(id); // 15
	}

}

To generate project specific values, call Optimus.make() which will generate an .optimus file containing a Json string. The only dependency at the moment to use Opimus.make() is to have the unzip command available. See OptimusSpec for an example.

Nano ID Usage

package ;

import uhx.uid.Nanoid;

class Main {

	public static function main() {
		var nanoid = new Nanoid();
		var id = nanoid.toString(); // `nanoid.toString() == nanoid.toString()` == true.
		// Using a custom alphabet and length
		var id = Nanoid.generate(Nanoid.Url, 50);
	}

}
Notes
  • The HashLink & Neko targets uses Math.random. They pass the flat distribution test, but wont be classed as secure.

regle's People

Contributors

skial avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar

regle's Issues

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.