Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions types/uuid/index.d.mts
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
import uuid from "./index.js";
export import v1 = uuid.v1;
export import v1ToV6 = uuid.v1ToV6;
export import v3 = uuid.v3;
export import v4 = uuid.v4;
export import v5 = uuid.v5;
export import v6 = uuid.v6;
export import v6ToV1 = uuid.v6ToV1;
export import v7 = uuid.v7;
export import NIL = uuid.NIL;
export import MAX = uuid.MAX;
export import version = uuid.version;
export import validate = uuid.validate;
export import stringify = uuid.stringify;
export import parse = uuid.parse;
export import V1Options = uuid.V1Options;
export import V4Options = uuid.V4Options;
export import V6Options = uuid.V6Options;
export import V7Options = uuid.V7Options;
27 changes: 27 additions & 0 deletions types/uuid/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,22 @@ interface V1RngOptions extends V1BaseOptions, RngOptions {}

export type V1Options = V1RandomOptions | V1RngOptions;
export type V4Options = RandomOptions | RngOptions;
export type V6Options = V1Options;

interface V7BaseOptions {
msecs?: number | Date | undefined;
seq?: number;
}
export type V7Options = (RandomOptions | RngOptions) & V7BaseOptions;

type VToV = ((uuid: string) => string) & ((uuid: OutputBuffer) => Uint8Array);

type v1String = (options?: V1Options) => string;
type v1Buffer = <T extends OutputBuffer>(options: V1Options | null | undefined, buffer: T, offset?: number) => T;
type v1 = v1Buffer & v1String;

type v1ToV6 = VToV;

type v4String = (options?: V4Options) => string;
type v4Buffer = <T extends OutputBuffer>(options: V4Options | null | undefined, buffer: T, offset?: number) => T;
type v4 = v4Buffer & v4String;
Expand Down Expand Up @@ -68,19 +79,35 @@ interface v5Static {
}
type v5 = v5Buffer & v5String & v5Static;

type v6String = (options?: V6Options) => string;
type v6Buffer = <T extends OutputBuffer>(options: V6Options | null | undefined, buffer: T, offset?: number) => T;
type v6 = v6Buffer & v6String;

type v6ToV1 = VToV;

type v7String = (options?: V7Options) => string;
type v7Buffer = <T extends OutputBuffer>(options: V7Options | null | undefined, buffer: T, offset?: number) => T;
type v7 = v7Buffer & v7String;

type NIL = string;
type MAX = string;

type parse = (uuid: string) => Uint8Array;
type stringify = (buffer: InputBuffer, offset?: number) => string;
type validate = (uuid: string) => boolean;
type version = (uuid: string) => number;

export const NIL: NIL;
export const MAX: MAX;
export const parse: parse;
export const stringify: stringify;
export const v1: v1;
export const v1ToV6: v1ToV6;
export const v3: v3;
export const v4: v4;
export const v5: v5;
export const v6: v6;
export const v6ToV1: v6ToV1;
export const v7: v7;
export const validate: validate;
export const version: version;
2 changes: 1 addition & 1 deletion types/uuid/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"private": true,
"name": "@types/uuid",
"version": "9.0.9999",
"version": "10.0.9999",
"projects": [
"https://github.com/uuidjs/uuid"
],
Expand Down
69 changes: 68 additions & 1 deletion types/uuid/uuid-tests.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,22 @@
/// <reference types="node" />

import {
MAX as MAX_UUID,
NIL as NIL_UUID,
parse as uuidParse,
stringify as uuidStringify,
v1 as uuidv1,
V1Options,
v1ToV6,
v3 as uuidv3,
v4 as uuidv4,
V4Options,
v5 as uuidv5,
v6 as uuidv6,
V6Options,
v6ToV1,
v7 as uuidv7,
V7Options,
validate as uuidValidate,
version as uuidVersion,
} from "uuid";
Expand Down Expand Up @@ -62,6 +69,10 @@ let bufferv1 = new Uint8Array(32);
bufferv1 = uuidv1(null, bufferv1);
bufferv1 = uuidv1(undefined, bufferv1, 16);

const stringv16: string = v1ToV6(stringv1);
const bufferv16: Uint8Array = v1ToV6(bufferv1);
const arrayv16: ArrayLike<number> = v1ToV6(uuidv6(undefined, []));

let stringv4: string = uuidv4();
stringv4 = uuidv4({ random: randoms });
stringv4 = uuidv4({ rng: () => randoms });
Expand All @@ -73,6 +84,61 @@ let bufferv4: number[] = new Array(32);
bufferv4 = uuidv4(undefined, bufferv4);
bufferv4 = uuidv4(null, bufferv4, 16);

let stringv6: string = uuidv6();
stringv6 = uuidv6({
node: [0x01, 0x23, 0x45, 0x67, 0x89, 0xab],
clockseq: 0x1234,
msecs: new Date("2011-11-01").getTime(),
nsecs: 5678,
});
stringv6 = uuidv6({
msecs: new Date("2011-11-01").getTime(),
nsecs: 5678,
random: randoms,
});
stringv6 = uuidv6({
msecs: new Date("2011-11-01").getTime(),
nsecs: 5678,
rng: () => randoms,
});

const v6Options: V6Options = {
msecs: new Date("2011-11-01").getTime(),
nsecs: 5678,
rng: () => randoms,
};
stringv6 = uuidv6(v6Options);

let bufferv6 = new Uint8Array(32);
bufferv6 = uuidv6(null, bufferv1);
bufferv6 = uuidv6(undefined, bufferv1, 16);

const stringv61: string = v6ToV1(stringv6);
const bufferv61: Uint8Array = v6ToV1(bufferv6);
const arrayv61: ArrayLike<number> = v6ToV1(uuidv6(undefined, []));

let stringv7: string = uuidv7();
stringv7 = uuidv7({ random: randoms });
stringv7 = uuidv7({ rng: () => randoms });
stringv7 = uuidv7({
msecs: new Date("2011-11-01").getTime(),
random: randoms,
});
stringv7 = uuidv7({
msecs: new Date("2011-11-01").getTime(),
rng: () => randoms,
});

const v7Options: V7Options = {
msecs: new Date("2011-11-01").getTime(),
random: randoms,
};
stringv7 = uuidv7(v7Options);

let bufferv7: number[] = new Array(32);
bufferv7 = uuidv4(undefined, bufferv7);
bufferv7 = uuidv4(null, bufferv7, 16);

// https://github.com/uuidjs/uuid#quickstart---commonjs-recommended
const MY_NAMESPACE = uuidv4();
const a3: string = uuidv3("hello", MY_NAMESPACE);
Expand Down Expand Up @@ -108,9 +174,10 @@ valid = uuidValidate(stringv4);
valid = uuidValidate(a3);
valid = uuidValidate(a5);
valid = uuidValidate(NIL_UUID);
valid = uuidValidate(MAX_UUID);

let version: number = uuidVersion(stringv1);
version = uuidVersion(stringv4);
version = uuidVersion(a3);
version = uuidVersion(a5);
version = uuidVersion(NIL_UUID);
version = uuidVersion(MAX_UUID);