refactor(uuid): move UUID v7 APIs to ./unstable-v7 (#5937)

This commit is contained in:
Yoshiya Hinosawa 2024-09-11 20:23:31 +09:00 committed by GitHub
parent 635a8860d7
commit 95d4c19c5d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 6 additions and 32 deletions

View File

@ -9,6 +9,6 @@
"./v3": "./v3.ts", "./v3": "./v3.ts",
"./v4": "./v4.ts", "./v4": "./v4.ts",
"./v5": "./v5.ts", "./v5": "./v5.ts",
"./v7": "./v7.ts" "./unstable-v7": "./unstable_v7.ts"
} }
} }

View File

@ -33,11 +33,6 @@ import { generate as generateV1, validate as validateV1 } from "./v1.ts";
import { generate as generateV3, validate as validateV3 } from "./v3.ts"; import { generate as generateV3, validate as validateV3 } from "./v3.ts";
import { validate as validateV4 } from "./v4.ts"; import { validate as validateV4 } from "./v4.ts";
import { generate as generateV5, validate as validateV5 } from "./v5.ts"; import { generate as generateV5, validate as validateV5 } from "./v5.ts";
import {
extractTimestamp as extractTimestampV7,
generate as generateV7,
validate as validateV7,
} from "./v7.ts";
/** /**
* Generator and validator for * Generator and validator for
@ -111,24 +106,3 @@ export const v5 = {
generate: generateV5, generate: generateV5,
validate: validateV5, validate: validateV5,
}; };
/**
* Generator and validator for
* {@link https://www.rfc-editor.org/rfc/rfc9562.html#section-5.7 | UUIDv7}.
*
* @experimental **UNSTABLE**: New API, yet to be vetted.
*
* @example Usage
* ```ts
* import { v7 } from "@std/uuid";
* import { assert } from "@std/assert";
*
* const uuid = v7.generate();
* assert(v7.validate(uuid));
* ```
*/
export const v7 = {
generate: generateV7,
validate: validateV7,
extractTimestamp: extractTimestampV7,
};

View File

@ -10,7 +10,7 @@
* *
* @example * @example
* ```ts * ```ts
* import { generate, validate, extractTimestamp } from "@std/uuid/v7"; * import { generate, validate, extractTimestamp } from "@std/uuid/unstable-v7";
* import { assert, assertEquals } from "@std/assert"; * import { assert, assertEquals } from "@std/assert";
* *
* const uuid = generate(); * const uuid = generate();
@ -37,7 +37,7 @@ const UUID_RE =
* *
* @example Usage * @example Usage
* ```ts * ```ts
* import { validate } from "@std/uuid/v7"; * import { validate } from "@std/uuid/unstable-v7";
* import { assert, assertFalse } from "@std/assert"; * import { assert, assertFalse } from "@std/assert";
* *
* assert(validate("017f22e2-79b0-7cc3-98c4-dc0c0c07398f")); * assert(validate("017f22e2-79b0-7cc3-98c4-dc0c0c07398f"));
@ -61,7 +61,7 @@ export function validate(id: string): boolean {
* *
* @example Usage * @example Usage
* ```ts * ```ts
* import { generate, validate } from "@std/uuid/v7"; * import { generate, validate } from "@std/uuid/unstable-v7";
* import { assert } from "@std/assert"; * import { assert } from "@std/assert";
* *
* const uuid = generate(); * const uuid = generate();
@ -98,7 +98,7 @@ export function generate(timestamp: number = Date.now()): string {
* *
* @example Usage * @example Usage
* ```ts * ```ts
* import { extractTimestamp } from "@std/uuid/v7"; * import { extractTimestamp } from "@std/uuid/unstable-v7";
* import { assertEquals } from "@std/assert"; * import { assertEquals } from "@std/assert";
* *
* const uuid = "017f22e2-79b0-7cc3-98c4-dc0c0c07398f"; * const uuid = "017f22e2-79b0-7cc3-98c4-dc0c0c07398f";

View File

@ -1,6 +1,6 @@
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
import { assert, assertEquals, assertThrows } from "@std/assert"; import { assert, assertEquals, assertThrows } from "@std/assert";
import { extractTimestamp, generate, validate } from "./v7.ts"; import { extractTimestamp, generate, validate } from "./unstable_v7.ts";
import { stub } from "../testing/mock.ts"; import { stub } from "../testing/mock.ts";
Deno.test("generate() generates a non-empty string", () => { Deno.test("generate() generates a non-empty string", () => {