2024-01-01 21:11:32 +00:00
|
|
|
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
|
2023-09-12 11:31:03 +00:00
|
|
|
// Copyright 2023 Yoshiya Hinosawa. All rights reserved. MIT license.
|
|
|
|
// Copyright 2017 Alizain Feerasta. All rights reserved. MIT license.
|
|
|
|
// This module is browser compatible.
|
|
|
|
|
|
|
|
/**
|
2023-12-01 09:55:52 +00:00
|
|
|
* Utilities for generating and working with
|
2024-01-25 14:08:29 +00:00
|
|
|
* {@link https://github.com/ulid/spec | Universally Unique Lexicographically Sortable Identifiers (ULIDs)}.
|
2023-12-01 09:55:52 +00:00
|
|
|
*
|
2024-05-22 13:42:59 +00:00
|
|
|
* To generate a ULID use the {@linkcode ulid} function. This will generate a
|
|
|
|
* ULID based on the current time.
|
|
|
|
*
|
2024-06-03 04:10:27 +00:00
|
|
|
* ```ts no-assert
|
2024-05-22 13:42:59 +00:00
|
|
|
* import { ulid } from "@std/ulid";
|
|
|
|
*
|
|
|
|
* ulid(); // 01HYFKMDF3HVJ4J3JZW8KXPVTY
|
|
|
|
* ```
|
|
|
|
*
|
|
|
|
* {@linkcode ulid} does not guarantee that the ULIDs will be strictly
|
|
|
|
* increasing for the same current time. If you need to guarantee that the ULIDs
|
|
|
|
* will be strictly increasing, even for the same current time, use the
|
|
|
|
* {@linkcode monotonicUlid} function.
|
|
|
|
*
|
2024-06-03 04:10:27 +00:00
|
|
|
* ```ts no-assert
|
2024-05-22 13:42:59 +00:00
|
|
|
* import { monotonicUlid } from "@std/ulid";
|
|
|
|
*
|
|
|
|
* monotonicUlid(); // 01HYFKHG5F8RHM2PM3D7NSTDAS
|
|
|
|
* monotonicUlid(); // 01HYFKHG5F8RHM2PM3D7NSTDAT
|
|
|
|
* ```
|
|
|
|
*
|
|
|
|
* Because each ULID encodes the time it was generated, you can extract the
|
|
|
|
* timestamp from a ULID using the {@linkcode decodeTime} function.
|
|
|
|
*
|
|
|
|
* ```ts
|
|
|
|
* import { decodeTime, ulid } from "@std/ulid";
|
refactor(assert,async,bytes,cli,collections,crypto,csv,data-structures,datetime,dotenv,encoding,expect,fmt,front-matter,fs,html,http,ini,internal,io,json,jsonc,log,media-types,msgpack,net,path,semver,streams,testing,text,toml,ulid,url,uuid,webgpu,yaml): import from `@std/assert` (#5199)
* refactor: import from `@std/assert`
* update
2024-06-30 08:30:10 +00:00
|
|
|
* import { assertEquals } from "@std/assert";
|
2024-06-03 04:10:27 +00:00
|
|
|
*
|
|
|
|
* const timestamp = 150_000;
|
|
|
|
* const ulidString = ulid(timestamp);
|
2024-05-22 13:42:59 +00:00
|
|
|
*
|
2024-06-03 04:10:27 +00:00
|
|
|
* assertEquals(decodeTime(ulidString), timestamp);
|
2024-05-22 13:42:59 +00:00
|
|
|
* ```
|
|
|
|
*
|
2023-09-12 11:31:03 +00:00
|
|
|
* @module
|
|
|
|
*/
|
|
|
|
|
2024-07-12 07:48:01 +00:00
|
|
|
export * from "./decode_time.ts";
|
|
|
|
export * from "./monotonic_ulid.ts";
|
|
|
|
export * from "./ulid.ts";
|