Giter Club home page Giter Club logo

sqids-bazel's Introduction

Github Actions

Sqids (pronounced "squids") is a small library that lets you generate unique IDs from numbers. It's good for link shortening, fast & URL-safe ID generation and decoding back into numbers for quicker database lookups.

Features:

  • Encode multiple numbers - generate short IDs from one or several non-negative numbers
  • Quick decoding - easily decode IDs back into numbers
  • Unique IDs - generate unique IDs by shuffling the alphabet once
  • ID padding - provide minimum length to make IDs more uniform
  • URL safe - auto-generated IDs do not contain common profanity
  • Randomized output - Sequential input provides nonconsecutive IDs
  • Many implementations - Support for multiple programming languages

๐Ÿงฐ Use-cases

Good for:

  • Generating IDs for public URLs (eg: link shortening)
  • Generating IDs for internal systems (eg: event tracking)
  • Decoding for quicker database lookups (eg: by primary keys)

Not good for:

  • Sensitive data (this is not an encryption library)
  • User IDs (can be decoded revealing user count)

๐Ÿš€ Getting started

Head over to the Releases to pick a version and read the install instructions.

Load from the module:

load("@sqids_bazel//:defs.bzl", "encode", "decode")

๐Ÿ‘ฉโ€๐Ÿ’ป Examples

Simple encode & decode:

id = encode([1, 2, 3]) # "86Rf07"
numbers = decode(id) # [1, 2, 3]

Note ๐Ÿšง Because of the algorithm's design, multiple IDs can decode back into the same sequence of numbers. If it's important to your design that IDs are canonical, you have to manually re-encode decoded numbers and check that the generated ID matches.

Enforce a minimum length for IDs:

id = encode([1, 2, 3], min_length = 10) # "86Rf07xd4z"
numbers = decode(id) # [1, 2, 3]

Randomize IDs by providing a custom alphabet:

alphabet = "FxnXM1kBN6cuhsAvjW3Co7l2RePyY8DwaU04Tzt9fHQrqSVKdpimLGIJOgb5ZE"
id = encode([1, 2, 3], alphabet) # "B4aajs"
numbers = decode(id, alphabet) # [1, 2, 3]

Prevent specific words from appearing anywhere in the auto-generated IDs:

id = encode([1, 2, 3], blocklist = ["86Rf07"])
numbers = decode(id) # [1, 2, 3]

๐Ÿ“ License

MIT

sqids-bazel's People

Contributors

4kimov avatar mgred avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

sqids-bazel's Issues

Init

Random todos for v0.1:

  • Init blank repo
  • @mgred I wanted to confirm that sqids-bazel is more appropriate than sqids-starlark?
  • Ensure that initial version is non-production (eg: 0.1.x)
  • Fill out the sample README.md template
  • Is it possible to include a Github Actions tests badge in the README?
  • Update website @4kimov

Edit: @mgred If you want to create a PR from https://github.com/mgred/sqids-bazel and merge it here, that's fine. Or if you want to just push to main directly, that's also fine. Either way you should have access to this repo now.

feat: Enable usage from `WORKSPACE` file

Currently this only works with Bzlmod enabled and git_override. We should also make this work in WORKSPACE files by providing a release and the necessary instructions.

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.