feat(uuid): add pre-defined namespace UUIDs (#3352)

This commit is contained in:
David Luis 2023-05-02 21:51:43 +07:00 committed by GitHub
parent 264c7144b1
commit a5b9694784
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 69 additions and 3 deletions

47
uuid/constants.ts Normal file
View File

@ -0,0 +1,47 @@
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
// This module is browser compatible.
/**
* Name string is a fully-qualified domain name.
*
* @example
* ```ts
* import { NAMESPACE_DNS } from "https://deno.land/std@$STD_VERSION/uuid/constants.ts";
*
* console.log(NAMESPACE_DNS); // => 6ba7b810-9dad-11d1-80b4-00c04fd430c8
* ```
*/
export const NAMESPACE_DNS = "6ba7b810-9dad-11d1-80b4-00c04fd430c8";
/**
* Name string is a URL.
*
* @example
* ```ts
* import { NAMESPACE_URL } from "https://deno.land/std@$STD_VERSION/uuid/constants.ts";
*
* console.log(NAMESPACE_URL); // => 6ba7b811-9dad-11d1-80b4-00c04fd430c8
* ```
*/
export const NAMESPACE_URL = "6ba7b811-9dad-11d1-80b4-00c04fd430c8";
/**
* Name string is an ISO OID.
*
* @example
* ```ts
* import { NAMESPACE_OID } from "https://deno.land/std@$STD_VERSION/uuid/constants.ts";
*
* console.log(NAMESPACE_OID); // => 6ba7b812-9dad-11d1-80b4-00c04fd430c8
* ```
*/
export const NAMESPACE_OID = "6ba7b812-9dad-11d1-80b4-00c04fd430c8";
/**
* Name string is an X.500 DN (in DER or a text output format).
*
* @example
* ```ts
* import { NAMESPACE_X500 } from "https://deno.land/std@$STD_VERSION/uuid/constants.ts";
*
* console.log(NAMESPACE_X500); // => 6ba7b814-9dad-11d1-80b4-00c04fd430c8
* ```
*/
export const NAMESPACE_X500 = "6ba7b814-9dad-11d1-80b4-00c04fd430c8";

16
uuid/constants_test.ts Normal file
View File

@ -0,0 +1,16 @@
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
import { assertEquals } from "../testing/asserts.ts";
import {
NAMESPACE_DNS,
NAMESPACE_OID,
NAMESPACE_URL,
NAMESPACE_X500,
} from "./constants.ts";
import { validate } from "./mod.ts";
Deno.test("[UUID] validate_namespaces", () => {
assertEquals(validate(NAMESPACE_DNS), true);
assertEquals(validate(NAMESPACE_URL), true);
assertEquals(validate(NAMESPACE_OID), true);
assertEquals(validate(NAMESPACE_X500), true);
});

View File

@ -2,7 +2,7 @@
// This module is browser compatible.
/**
* Generators and validators for UUIDs for versions v1, v4 and v5.
* Generators and validators for UUIDs for versions v1, v3, v4 and v5.
*
* Consider using the web platform
* [`crypto.randomUUID`](https://developer.mozilla.org/en-US/docs/Web/API/Crypto/randomUUID)
@ -10,14 +10,17 @@
*
* Based on https://github.com/kelektiv/node-uuid -> https://www.ietf.org/rfc/rfc4122.txt
*
* Support for RFC4122 version 1, 4, and 5 UUIDs
* Support for RFC4122 version 1, 3, 4, and 5 UUIDs
*
* This module is browser compatible.
*
* @module
*/
export * from "./constants.ts";
import * as v1 from "./v1.ts";
import * as v3 from "./v3.ts";
import * as v4 from "./v4.ts";
import * as v5 from "./v5.ts";
@ -72,4 +75,4 @@ export function version(uuid: string): number {
return parseInt(uuid[14], 16);
}
export { v1, v4, v5 };
export { v1, v3, v4, v5 };