mirror of
https://github.com/FlipsideCrypto/DefinitelyTyped.git
synced 2026-02-06 10:56:53 +00:00
🤖 Merge PR #46395 Upgrade types for uuid@8.3.0 by @ctavan
* Revert "added typing for "validate" function added in uuid release 8.3.0 (#46557)"
This reverts commit c50f1201c7.
* Upgrade types for uuid@8.3.0
* Export v1/v4 options
This commit is contained in:
parent
e8d83de7f5
commit
5ac9294b5d
67
types/uuid/index.d.ts
vendored
67
types/uuid/index.d.ts
vendored
@ -1,4 +1,4 @@
|
||||
// Type definitions for uuid 8.0
|
||||
// Type definitions for uuid 8.3
|
||||
// Project: https://github.com/uuidjs/uuid
|
||||
// Definitions by: Oliver Hoffmann <https://github.com/iamolivinius>
|
||||
// Felipe Ochoa <https://github.com/felipeochoa>
|
||||
@ -8,10 +8,73 @@
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.8
|
||||
|
||||
import { v1, v3, v4, v5, validate } from './interfaces';
|
||||
// disable automatic export
|
||||
export {};
|
||||
|
||||
// Uses ArrayLike to admit Unit8 and co.
|
||||
type OutputBuffer = ArrayLike<number>;
|
||||
type InputBuffer = ArrayLike<number>;
|
||||
|
||||
interface RandomOptions {
|
||||
random?: InputBuffer;
|
||||
}
|
||||
interface RngOptions {
|
||||
rng?: () => InputBuffer;
|
||||
}
|
||||
|
||||
interface V1BaseOptions {
|
||||
node?: InputBuffer;
|
||||
clockseq?: number;
|
||||
msecs?: number | Date;
|
||||
nsecs?: number;
|
||||
}
|
||||
interface V1RandomOptions extends V1BaseOptions, RandomOptions {}
|
||||
interface V1RngOptions extends V1BaseOptions, RngOptions {}
|
||||
|
||||
export type V1Options = V1RandomOptions | V1RngOptions;
|
||||
export type V4Options = RandomOptions | RngOptions;
|
||||
|
||||
type v1String = (options?: V1Options) => string;
|
||||
type v1Buffer = <T extends OutputBuffer>(options: V1Options | null | undefined, buffer: T, offset?: number) => T;
|
||||
type v1 = v1Buffer & v1String;
|
||||
|
||||
type v4String = (options?: V4Options) => string;
|
||||
type v4Buffer = <T extends OutputBuffer>(options: V4Options | null | undefined, buffer: T, offset?: number) => T;
|
||||
type v4 = v4Buffer & v4String;
|
||||
|
||||
type v3String = (name: string | InputBuffer, namespace: string | InputBuffer) => string;
|
||||
type v3Buffer = <T extends OutputBuffer>(name: string | InputBuffer, namespace: string | InputBuffer, buffer: T, offset?: number) => T;
|
||||
interface v3Static {
|
||||
// https://github.com/uuidjs/uuid/blob/master/src/v35.js#L22
|
||||
DNS: string;
|
||||
// https://github.com/uuidjs/uuid/blob/master/src/v35.js#L23
|
||||
URL: string;
|
||||
}
|
||||
type v3 = v3Buffer & v3String & v3Static;
|
||||
|
||||
type v5String = (name: string | InputBuffer, namespace: string | InputBuffer) => string;
|
||||
type v5Buffer = <T extends OutputBuffer>(name: string | InputBuffer, namespace: string | InputBuffer, buffer: T, offset?: number) => T;
|
||||
interface v5Static {
|
||||
// https://github.com/uuidjs/uuid/blob/master/src/v35.js#L22
|
||||
DNS: string;
|
||||
// https://github.com/uuidjs/uuid/blob/master/src/v35.js#L23
|
||||
URL: string;
|
||||
}
|
||||
type v5 = v5Buffer & v5String & v5Static;
|
||||
|
||||
type NIL = string;
|
||||
|
||||
type parse = (uuid: string) => OutputBuffer;
|
||||
type stringify = (buffer: InputBuffer, offset?: number) => string;
|
||||
type validate = (uuid: string) => boolean;
|
||||
type version = (uuid: string) => number;
|
||||
|
||||
export const NIL: NIL;
|
||||
export const parse: parse;
|
||||
export const stringify: stringify;
|
||||
export const v1: v1;
|
||||
export const v3: v3;
|
||||
export const v4: v4;
|
||||
export const v5: v5;
|
||||
export const validate: validate;
|
||||
export const version: version;
|
||||
|
||||
52
types/uuid/interfaces.d.ts
vendored
52
types/uuid/interfaces.d.ts
vendored
@ -1,52 +0,0 @@
|
||||
// Uses ArrayLike to admit Unit8 and co.
|
||||
export type OutputBuffer = ArrayLike<number>;
|
||||
export type InputBuffer = ArrayLike<number>;
|
||||
|
||||
export interface RandomOptions {
|
||||
random?: InputBuffer;
|
||||
}
|
||||
export interface RngOptions {
|
||||
rng?: () => InputBuffer;
|
||||
}
|
||||
|
||||
export interface V1BaseOptions {
|
||||
node?: InputBuffer;
|
||||
clockseq?: number;
|
||||
msecs?: number | Date;
|
||||
nsecs?: number;
|
||||
}
|
||||
export interface V1RandomOptions extends V1BaseOptions, RandomOptions {}
|
||||
export interface V1RngOptions extends V1BaseOptions, RngOptions {}
|
||||
|
||||
export type V1Options = V1RandomOptions | V1RngOptions;
|
||||
export type V4Options = RandomOptions | RngOptions;
|
||||
|
||||
export type v1String = (options?: V1Options) => string;
|
||||
export type v1Buffer = <T extends OutputBuffer>(options: V1Options | null | undefined, buffer: T, offset?: number) => T;
|
||||
export type v1 = v1Buffer & v1String;
|
||||
|
||||
export type v4String = (options?: V4Options) => string;
|
||||
export type v4Buffer = <T extends OutputBuffer>(options: V4Options | null | undefined, buffer: T, offset?: number) => T;
|
||||
export type v4 = v4Buffer & v4String;
|
||||
|
||||
export type v3String = (name: string | InputBuffer, namespace: string | InputBuffer) => string;
|
||||
export type v3Buffer = <T extends OutputBuffer>(name: string | InputBuffer, namespace: string | InputBuffer, buffer: T, offset?: number) => T;
|
||||
export interface v3Static {
|
||||
// https://github.com/uuidjs/uuid/blob/master/src/v35.js#L22
|
||||
DNS: string;
|
||||
// https://github.com/uuidjs/uuid/blob/master/src/v35.js#L23
|
||||
URL: string;
|
||||
}
|
||||
export type v3 = v3Buffer & v3String & v3Static;
|
||||
|
||||
export type v5String = (name: string | InputBuffer, namespace: string | InputBuffer) => string;
|
||||
export type v5Buffer = <T extends OutputBuffer>(name: string | InputBuffer, namespace: string | InputBuffer, buffer: T, offset?: number) => T;
|
||||
export interface v5Static {
|
||||
// https://github.com/uuidjs/uuid/blob/master/src/v35.js#L22
|
||||
DNS: string;
|
||||
// https://github.com/uuidjs/uuid/blob/master/src/v35.js#L23
|
||||
URL: string;
|
||||
}
|
||||
export type v5 = v5Buffer & v5String & v5Static;
|
||||
|
||||
export type validate = (uuid: string) => boolean;
|
||||
@ -1,6 +1,18 @@
|
||||
/// <reference types="node" />
|
||||
|
||||
import { v1 as uuidv1, v4 as uuidv4, v3 as uuidv3, v5 as uuidv5, validate as uuidValidate } from 'uuid';
|
||||
import {
|
||||
v1 as uuidv1,
|
||||
v4 as uuidv4,
|
||||
v3 as uuidv3,
|
||||
v5 as uuidv5,
|
||||
NIL as NIL_UUID,
|
||||
parse as uuidParse,
|
||||
stringify as uuidStringify,
|
||||
validate as uuidValidate,
|
||||
version as uuidVersion,
|
||||
V1Options,
|
||||
V4Options,
|
||||
} from 'uuid';
|
||||
|
||||
const randoms = [
|
||||
0x10, 0x91, 0x56, 0xbe, 0xc4, 0xfb, 0xc1, 0xea,
|
||||
@ -25,6 +37,13 @@ stringv1 = uuidv1({
|
||||
rng: () => randoms,
|
||||
});
|
||||
|
||||
const v1Options: V1Options = {
|
||||
msecs: new Date('2011-11-01').getTime(),
|
||||
nsecs: 5678,
|
||||
rng: () => randoms,
|
||||
};
|
||||
stringv1 = uuidv1(v1Options);
|
||||
|
||||
let bufferv1 = new Uint8Array(32);
|
||||
bufferv1 = uuidv1(null, bufferv1);
|
||||
bufferv1 = uuidv1(undefined, bufferv1, 16);
|
||||
@ -33,6 +52,9 @@ let stringv4: string = uuidv4();
|
||||
stringv4 = uuidv4({ random: randoms });
|
||||
stringv4 = uuidv4({ rng: () => randoms });
|
||||
|
||||
const v4Options: V4Options = { random: randoms };
|
||||
stringv4 = uuidv4(v4Options);
|
||||
|
||||
let bufferv4: number[] = new Array(32);
|
||||
bufferv4 = uuidv4(undefined, bufferv4);
|
||||
bufferv4 = uuidv4(null, bufferv4, 16);
|
||||
@ -62,4 +84,19 @@ class CustomBuffer extends Uint8Array {}
|
||||
const h = new CustomBuffer(10);
|
||||
uuidv4(null, h); // $ExpectType CustomBuffer
|
||||
|
||||
const av: boolean = uuidValidate('6ec0bd7f-11c0-43da-975e-2a8ad9ebae0b');
|
||||
const nil5: string = uuidv5('hello', NIL_UUID);
|
||||
|
||||
const stringified: string = uuidStringify(bufferv4);
|
||||
const parsed: ArrayLike<number> = uuidParse(stringified);
|
||||
|
||||
let valid: boolean = uuidValidate(stringv1);
|
||||
valid = uuidValidate(stringv4);
|
||||
valid = uuidValidate(a3);
|
||||
valid = uuidValidate(a5);
|
||||
valid = uuidValidate(NIL_UUID);
|
||||
|
||||
let version: number = uuidVersion(stringv1);
|
||||
version = uuidVersion(stringv4);
|
||||
version = uuidVersion(a3);
|
||||
version = uuidVersion(a5);
|
||||
version = uuidVersion(NIL_UUID);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user