Git Product home page Git Product logo

ulid's Introduction

ULID

This class is a utility class that provides functions for generating and decoding ULIDs (Universally Unique Lexicographically Sortable Identifiers). ULIDs are unique identifiers that are used to identify resources in a distributed system. They are designed to be globally unique, sortable by timestamp, and portable between different systems.

The Ulid class provides a number of functions that are used to generate and decode ULIDs:

  • generate: This function generates a new ULID by combining a timestamp and a random value, and encoding them using a base-32 encoding scheme.

  • encode: This function encodes an integer value into a base-32 string.

  • getTimestamp: This function generates a timestamp value for the ULID.

  • getRandom: This function generates a random value for the ULID.

  • decode: This function decodes a ULID back into its timestamp and random values.

  • decodePart: This function decodes a part of a ULID (either the timestamp or the random value) into an integer.

  • isValid: This function checks if it is a valid ULID by checking its length and the presence of only valid characters in the base-32 encoding scheme.

These functions can be used to generate unique identifiers that can be used to identify resources in a distributed system.

Usage

<?php
//generates a new ULID
$ulid = Ulid::generate(true);
echo $ulid . "\n"; // Outputs a ULID, e.g. "01D8X5H9C41E3QJZ08RY65K2V7MTUW4B"


// Decode a ULID back into its timestamp and random values
$decoded = Ulid::decode($ulid);
print_r($decoded);
// Outputs: Array ( [timestamp] => 1605846396825 [random] => 34890792831795 )

// You can validate ULIDs before inserting them into your database or using them in your application
if (Ulid::isValid($ulid)) {
    // The ULID is valid, do something with it
} else {
    // The ULID is invalid, handle the error
}

ulid's People

Contributors

khigashi avatar razvanstoica89 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.