All Projects → leodutra → simpleflakes

leodutra / simpleflakes

Licence: other
Fast and test-driven distributed 64-bit ID generation, using pure JavaScript, for Node.js.

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to simpleflakes

avrio-rs
Avrio's core code written in rust.
Stars: ✭ 14 (-56.25%)
Mutual labels:  sharding
metagraf
metaGraf is a opinionated specification for describing a software component and what its requirements are from the runtime environment. The mg command, turns metaGraf specifications into Kubernetes resources, supporting CI, CD and GitOps software delivery.
Stars: ✭ 15 (-53.12%)
Mutual labels:  generator
justgo
Skeleton for jump-starting a Go-powered microservice project with Docker and Go best-practices + easy code hot-reloading (for dev environments)!
Stars: ✭ 29 (-9.37%)
Mutual labels:  generator
nuzlocke-generator
📃 A nuzlocke template generator.
Stars: ✭ 21 (-34.37%)
Mutual labels:  generator
yang-schematics
Yet Another Angular Generator - based on @schematics/angular
Stars: ✭ 16 (-50%)
Mutual labels:  generator
ulid-creator
A Java library for generating Universally Unique Lexicographically Sortable Identifiers (ULID)
Stars: ✭ 38 (+18.75%)
Mutual labels:  guid
gommon
A collection of common util libraries for Go
Stars: ✭ 26 (-18.75%)
Mutual labels:  generator
autumn
采用Spring、Spring Boot、Redis、MyBatis、Shiro、Druid框架开发,搭载mysql数据。 如果你厌烦了MyBatis中需要手动创建表的事情,这个项目非常适合你,自动为你生成表。 从此你不在需要导入sql文件了,项目初始化变得异常简单,结构清晰,易于开发,真正拿来可用。 全注解MyBatis开发,没有任何mapper文件,一切sql 映射都用代码实现,全程无xml配置,对xml编写mapper有恐惧症的人的福音。 提供双向生成功能: 实体类自动生成数据库表,全过程不需要任何SQL语句,所有表自动生成 通过表生成基础结构代码,生成代码中已包含CRUD功能,表级别的API接口全部都有 基本实例数据全自动通过代码初始化,无需干预 仅仅只需要修改数据库连接地址,…
Stars: ✭ 28 (-12.5%)
Mutual labels:  generator
mosaic-node-generator
Generate mosaic images in Node.
Stars: ✭ 25 (-21.87%)
Mutual labels:  generator
unity-plumber
A component to procedurally generate pipe-like meshes in Unity
Stars: ✭ 55 (+71.88%)
Mutual labels:  generator
username-generation-guide
A definitive guide to generating usernames for OSINT purposes
Stars: ✭ 38 (+18.75%)
Mutual labels:  generator
Discord-Bot-TypeScript-Template
Discord bot - A discord.js bot template written with TypeScript.
Stars: ✭ 86 (+168.75%)
Mutual labels:  sharding
Layr
A decentralized (p2p) file storage system built atop Kademlia DHT that enforces data integrity, privacy, and availability through sharding, proofs of retrievability, redundancy, and encryption, with smart-contract powered incentive scheme
Stars: ✭ 90 (+181.25%)
Mutual labels:  sharding
roadifier
Open Source road mesh generator script for Unity
Stars: ✭ 30 (-6.25%)
Mutual labels:  generator
wolmo-bootstrap-react-native
Bootstrap generator for React Native projects
Stars: ✭ 20 (-37.5%)
Mutual labels:  generator
liferay-starter
Generate & download your Liferay workspace from a webapp.
Stars: ✭ 25 (-21.87%)
Mutual labels:  generator
combustor
MVC code generator for the Codeigniter framework.
Stars: ✭ 31 (-3.12%)
Mutual labels:  generator
base64uid
Generate UID like YouTube
Stars: ✭ 52 (+62.5%)
Mutual labels:  uid
crafting
Website for generating Minecraft crafting recipe JSON files
Stars: ✭ 31 (-3.12%)
Mutual labels:  generator
micro-svelte-compiler
Micro Svelte compiler (naive clone)
Stars: ✭ 56 (+75%)
Mutual labels:  generator

simpleflakes

travis status npm

coveralls status FOSSA Status

tonicdev demo david dep status david dev dep status

Simpleflake is the smartest way to generate a 64-bit + time-ordered + snowflake based ID. See the presentation!

Test-driven, pure JavaScript

This port is test-driven and no release goes out without tests.
Also, this library does not rely on low-level bindings, with OpenSSL, libgmp or anything beyond pure JavaScript.

Assumes original Python implementation as reference and fixes epoch (starts on 2000-01-01T00:00:00.000Z (UTC) while Python API v0.1.5 epoch starts on 2000-01-01T05:00:00.000Z).

simpleflakes uses the TC39 BigInt implementation when running on newer versions of Node.js. When BigInt is not available, Fedor Indutny's big number library (bn.js) is used as the fastest fallback for big number calculations.

How to Install:

npm install simpleflakes --save

Usage:

const { simpleflake } = require('simpleflakes');

const flakeBigInt = simpleflake()

// simpleflake(
//    timestamp = Date.now(), 
//    random_bits = 23-bit random, 
//     epoch = Date.UTC(2000, 0, 1)
// )
// returns BigInt on newer Node.js or bn.js BigNum on older engines.

flakeBigInt.toString();       // 4234673179811182512
flakeBigInt.toString(16);     // 3ac494d21e84f7b0
flakeBigInt.toString(2);      // 11101011000100...
flakeBigInt.toString(36);     // 20rfh5

You can check the original Python API 0.1.5 documentation for more info.

Reference

// Main flake function and its defaults
simpleflake(
    timestamp = Date.now(), 
    random_bits = 23-bit random, 
    epoch = Date.UTC(2000, 0, 1)
)

// Static constant epoch for simpleflake timestamps, starts at the year 2000  
simpleflake.SIMPLEFLAKE_EPOCH // const = 946702800

// Show binary digits of a number, pads to 64 bits unless specified.
simpleflake.binary(number, padding=true)

// Extract a portion of a bit string. Similar to substr().
simpleflake.extractBits(data, shift, length)

// Parses a simpleflake and returns a named tuple with the parts.
simpleflake.parseSimpleflake(flake)

// original API alias for SimpleFlake class, from the Python API
simpleflake.simpleflakeStruct

// same as simpleflake.simpleflakeStruct
SimpleFlake.SimpleFlakeStruct

License:

MIT

FOSSA Status

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].