diff --git a/std/uuid/_common.ts b/std/uuid/_common.ts index 8f13ac7e32..ef0bb42be7 100644 --- a/std/uuid/_common.ts +++ b/std/uuid/_common.ts @@ -1,4 +1,8 @@ // Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. +/** + * Converts the byte array to a UUID string + * @param bytes Used to convert Byte to Hex + */ export function bytesToUuid(bytes: number[] | Uint8Array): string { const bits: string[] = [...bytes].map((bit): string => { const s: string = bit.toString(16); @@ -17,6 +21,10 @@ export function bytesToUuid(bytes: number[] | Uint8Array): string { ].join(""); } +/** + * Converts a string to a byte array by converting the hex value to a number + * @param uuid Value that gets converted + */ export function uuidToBytes(uuid: string): number[] { const bytes: number[] = []; @@ -28,6 +36,10 @@ export function uuidToBytes(uuid: string): number[] { return bytes; } +/** + * Converts a string to a byte array using the char code + * @param str Value that gets converted + */ export function stringToBytes(str: string): number[] { str = unescape(encodeURIComponent(str)); const bytes = new Array(str.length); @@ -37,6 +49,10 @@ export function stringToBytes(str: string): number[] { return bytes; } +/** + * Creates a buffer for creating a SHA-1 hash + * @param content Buffer for SHA-1 hash + */ export function createBuffer(content: number[]): ArrayBuffer { const arrayBuffer = new ArrayBuffer(content.length); const uint8Array = new Uint8Array(arrayBuffer); diff --git a/std/uuid/mod.ts b/std/uuid/mod.ts index 61b10e895c..ff20fa807f 100644 --- a/std/uuid/mod.ts +++ b/std/uuid/mod.ts @@ -1,4 +1,5 @@ -// Based on https://github.com/kelektiv/node-uuid +// Based on https://github.com/kelektiv/node-uuid -> https://www.ietf.org/rfc/rfc4122.txt +// Supporting Support for RFC4122 version 1, 4, and 5 UUIDs // Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. import * as v1 from "./v1.ts"; import * as v4 from "./v4.ts"; @@ -6,6 +7,10 @@ import * as v5 from "./v5.ts"; export const NIL_UUID = "00000000-0000-0000-0000-000000000000"; +/** + * Checks if UUID is nil + * @param val UUID value + */ export function isNil(val: string): boolean { return val === NIL_UUID; } diff --git a/std/uuid/v1.ts b/std/uuid/v1.ts index ef1882d853..4adb0d6f92 100644 --- a/std/uuid/v1.ts +++ b/std/uuid/v1.ts @@ -6,6 +6,10 @@ const UUID_RE = new RegExp( "i", ); +/** + * Validates the UUID v1 + * @param id UUID value + */ export function validate(id: string): boolean { return UUID_RE.test(id); } @@ -25,6 +29,12 @@ type V1Options = { rng?: () => number[]; }; +/** + * Generates a RFC4122 v1 UUID (time-based) + * @param options Can use RFC time sequence values as overwrites + * @param buf Can allow the UUID to be written in byte-form starting at the offset + * @param offset Index to start writing on the UUID bytes in buffer + */ export function generate( options?: V1Options | null, buf?: number[], diff --git a/std/uuid/v4.ts b/std/uuid/v4.ts index f338440f56..1245f2678c 100644 --- a/std/uuid/v4.ts +++ b/std/uuid/v4.ts @@ -6,10 +6,15 @@ const UUID_RE = new RegExp( "i", ); +/** + * Validates the UUID v4 + * @param id UUID value + */ export function validate(id: string): boolean { return UUID_RE.test(id); } +/** Generates a RFC4122 v4 UUID (pseudo-randomly-based) */ export function generate(): string { const rnds = crypto.getRandomValues(new Uint8Array(16)); diff --git a/std/uuid/v5.ts b/std/uuid/v5.ts index 9b4c4111ad..64c131c5a1 100644 --- a/std/uuid/v5.ts +++ b/std/uuid/v5.ts @@ -11,6 +11,10 @@ import { assert } from "../_util/assert.ts"; const UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i; +/** + * Validates the UUID v5 + * @param id UUID value + */ export function validate(id: string): boolean { return UUID_RE.test(id); } @@ -20,6 +24,12 @@ interface V5Options { namespace: string | number[]; } +/** + * Generates a RFC4122 v5 UUID (SHA-1 namespace-based) + * @param options Can use a namespace and value to creat SHA-1 hash + * @param buf Can allow the UUID to be written in byte-form starting at the offset + * @param offset Index to start writing on the UUID bytes in buffer + */ export function generate( options: V5Options, buf?: number[],