mirror of
https://github.com/FlipsideCrypto/DefinitelyTyped.git
synced 2026-02-06 10:56:53 +00:00
Types 2.0: Move UUID.js and add type definitions for npm package uuid (#11785)
* Move UUID.js type definitions from uuid to uuidjs Issue: #10766 * Add type definitions for npm package: uuid Issue: #10766 * Minor fix in uuidjs tests file * Clean up UUID types * Convert to external module * Formatting fixes * Allow the `export = uuid` to be called as a function directly
This commit is contained in:
parent
4c8bd1073c
commit
6fdf789f54
101
uuid/index.d.ts
vendored
101
uuid/index.d.ts
vendored
@ -1,82 +1,35 @@
|
||||
// Type definitions for UUID.js v3.3.0
|
||||
// Project: https://github.com/LiosK/UUID.js
|
||||
// Definitions by: Jason Jarrett <https://github.com/staxmanade/>
|
||||
// Type definitions for uuid v2.0.3
|
||||
// Project: https://github.com/defunctzombie/node-uuid
|
||||
// Definitions by: Oliver Hoffmann <https://github.com/iamolivinius/>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
/// <reference types="node" />
|
||||
|
||||
declare namespace uuid {
|
||||
interface V1Options {
|
||||
node?: number[];
|
||||
clockseq?: number;
|
||||
msecs?: number | Date;
|
||||
nsecs?: number;
|
||||
}
|
||||
|
||||
interface UUID {
|
||||
intFields: UUIDArray<number>;
|
||||
bitFields: UUIDArray<string>;
|
||||
hexFields: UUIDArray<string>;
|
||||
version: number;
|
||||
bitString: string;
|
||||
hexString: string;
|
||||
urn: string;
|
||||
type V4Options = { random: number[] } | { rng: () => number[]; }
|
||||
|
||||
interface UuidStatic {
|
||||
(options?: V4Options): string;
|
||||
(options: V4Options | null, buffer: number[], offset?: number): number[];
|
||||
(options: V4Options | null, buffer: Buffer, offset?: number): Buffer;
|
||||
|
||||
/**
|
||||
* Tests if two {@link UUID} objects are equal.
|
||||
* @param {UUID} uuid
|
||||
* @returns {bool} True if two {@link UUID} objects are equal.
|
||||
*/
|
||||
equals(uuid: UUID): boolean;
|
||||
|
||||
/**
|
||||
* Returns UUID string representation.
|
||||
* @returns {string} {@link UUID#hexString}.
|
||||
*/
|
||||
toString(): string;
|
||||
v1(options?: V1Options): string;
|
||||
v1(options: V1Options | null, buffer: number[], offset?: number): number[];
|
||||
v1(options: V1Options | null, buffer: Buffer, offset?: number): Buffer;
|
||||
v4: UuidStatic;
|
||||
parse(id: string): number[];
|
||||
parse(id: string, buffer: number[], offset?: number): number[];
|
||||
parse(id: string, buffer: Buffer, offset?: number): Buffer;
|
||||
unparse(buffer: number[] | Buffer, offset?: number): string;
|
||||
}
|
||||
}
|
||||
|
||||
interface UUIDArray<T> extends Array<T> {
|
||||
timeLow: string;
|
||||
timeMid: string;
|
||||
timeHiAndVersion: string;
|
||||
clockSeqHiAndReserved: string;
|
||||
clockSeqLow: string;
|
||||
node: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* The simplest function to get an UUID string.
|
||||
* @returns {string} A version 4 UUID string.
|
||||
*/
|
||||
export declare function generate(): string;
|
||||
|
||||
/**
|
||||
* Generates a version 4 {@link UUID}.
|
||||
* @returns {UUID} A version 4 {@link UUID} object.
|
||||
* @since 3.0
|
||||
*/
|
||||
export declare function genV4(): UUID;
|
||||
|
||||
|
||||
/**
|
||||
* Generates a version 1 {@link UUID}.
|
||||
* @returns {UUID} A version 1 {@link UUID} object.
|
||||
* @since 3.0
|
||||
*/
|
||||
export declare function genV1(): UUID;
|
||||
|
||||
/**
|
||||
* Converts hexadecimal UUID string to an {@link UUID} object.
|
||||
* @param {string} uuid UUID hexadecimal string representation ("xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx").
|
||||
* @returns {UUID} {@link UUID} object or null.
|
||||
* @since 3.0
|
||||
*/
|
||||
export declare function parse(uuid: string): UUID;
|
||||
|
||||
|
||||
/**
|
||||
* Re-initializes version 1 UUID state.
|
||||
* @since 3.0
|
||||
*/
|
||||
export declare function resetState(): void;
|
||||
|
||||
/**
|
||||
* Reinstalls {@link UUID.generate} method to emulate the interface of UUID.js version 2.x.
|
||||
* @since 3.1
|
||||
* @deprecated Version 2.x. compatible interface is not recommended.
|
||||
*/
|
||||
export declare function makeBackwardCompatible(): void;
|
||||
declare const uuid: uuid.UuidStatic
|
||||
export = uuid
|
||||
|
||||
@ -16,4 +16,4 @@
|
||||
"index.d.ts",
|
||||
"uuid-tests.ts"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
31
uuid/uuid-tests.ts
Normal file
31
uuid/uuid-tests.ts
Normal file
@ -0,0 +1,31 @@
|
||||
import uuid = require('uuid');
|
||||
|
||||
let uuidv1: string = uuid.v1();
|
||||
|
||||
uuidv1 = uuid.v1({
|
||||
node: [0x01, 0x23, 0x45, 0x67, 0x89, 0xab],
|
||||
clockseq: 0x1234,
|
||||
msecs: new Date('2011-11-01').getTime(),
|
||||
nsecs: 5678
|
||||
});
|
||||
|
||||
let bufferv1: number[] = new Array(32);
|
||||
bufferv1 = uuid.v1(null, bufferv1);
|
||||
bufferv1 = uuid.v1(null, bufferv1, 16);
|
||||
|
||||
let uuidv4: string = uuid.v4();
|
||||
|
||||
const randoms = [
|
||||
0x10, 0x91, 0x56, 0xbe, 0xc4, 0xfb, 0xc1, 0xea,
|
||||
0x71, 0xb4, 0xef, 0xe1, 0x67, 0x1c, 0x58, 0x36
|
||||
];
|
||||
uuidv4 = uuid({ random: randoms });
|
||||
uuidv4 = uuid({ rng: () => randoms })
|
||||
|
||||
let bufferv4: number[] = new Array(32);
|
||||
bufferv4 = uuid(null, bufferv4);
|
||||
bufferv4 = uuid(null, bufferv4, 16);
|
||||
|
||||
let nodeBufferv4 = Buffer.alloc(32);
|
||||
nodeBufferv4 = uuid.v4(null, nodeBufferv4);
|
||||
nodeBufferv4 = uuid.v4(null, nodeBufferv4, 16);
|
||||
@ -1,4 +1,4 @@
|
||||
import UUID = require("uuid");
|
||||
import UUID = require("uuidjs");
|
||||
|
||||
const uuid1: string = UUID.generate()
|
||||
const uuid2: UUID.UUID = UUID.genV4()
|
||||
82
uuidjs/index.d.ts
vendored
Normal file
82
uuidjs/index.d.ts
vendored
Normal file
@ -0,0 +1,82 @@
|
||||
// Type definitions for UUID.js v3.3.0
|
||||
// Project: https://github.com/LiosK/UUID.js
|
||||
// Definitions by: Jason Jarrett <https://github.com/staxmanade/>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
|
||||
|
||||
interface UUID {
|
||||
intFields: UUIDArray<number>;
|
||||
bitFields: UUIDArray<string>;
|
||||
hexFields: UUIDArray<string>;
|
||||
version: number;
|
||||
bitString: string;
|
||||
hexString: string;
|
||||
urn: string;
|
||||
|
||||
|
||||
/**
|
||||
* Tests if two {@link UUID} objects are equal.
|
||||
* @param {UUID} uuid
|
||||
* @returns {bool} True if two {@link UUID} objects are equal.
|
||||
*/
|
||||
equals(uuid: UUID): boolean;
|
||||
|
||||
/**
|
||||
* Returns UUID string representation.
|
||||
* @returns {string} {@link UUID#hexString}.
|
||||
*/
|
||||
toString(): string;
|
||||
}
|
||||
|
||||
interface UUIDArray<T> extends Array<T> {
|
||||
timeLow: string;
|
||||
timeMid: string;
|
||||
timeHiAndVersion: string;
|
||||
clockSeqHiAndReserved: string;
|
||||
clockSeqLow: string;
|
||||
node: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* The simplest function to get an UUID string.
|
||||
* @returns {string} A version 4 UUID string.
|
||||
*/
|
||||
export declare function generate(): string;
|
||||
|
||||
/**
|
||||
* Generates a version 4 {@link UUID}.
|
||||
* @returns {UUID} A version 4 {@link UUID} object.
|
||||
* @since 3.0
|
||||
*/
|
||||
export declare function genV4(): UUID;
|
||||
|
||||
|
||||
/**
|
||||
* Generates a version 1 {@link UUID}.
|
||||
* @returns {UUID} A version 1 {@link UUID} object.
|
||||
* @since 3.0
|
||||
*/
|
||||
export declare function genV1(): UUID;
|
||||
|
||||
/**
|
||||
* Converts hexadecimal UUID string to an {@link UUID} object.
|
||||
* @param {string} uuid UUID hexadecimal string representation ("xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx").
|
||||
* @returns {UUID} {@link UUID} object or null.
|
||||
* @since 3.0
|
||||
*/
|
||||
export declare function parse(uuid: string): UUID;
|
||||
|
||||
|
||||
/**
|
||||
* Re-initializes version 1 UUID state.
|
||||
* @since 3.0
|
||||
*/
|
||||
export declare function resetState(): void;
|
||||
|
||||
/**
|
||||
* Reinstalls {@link UUID.generate} method to emulate the interface of UUID.js version 2.x.
|
||||
* @since 3.1
|
||||
* @deprecated Version 2.x. compatible interface is not recommended.
|
||||
*/
|
||||
export declare function makeBackwardCompatible(): void;
|
||||
19
uuidjs/tsconfig.json
Normal file
19
uuidjs/tsconfig.json
Normal file
@ -0,0 +1,19 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"target": "es6",
|
||||
"noImplicitAny": true,
|
||||
"strictNullChecks": false,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": [
|
||||
"../"
|
||||
],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"UUID-tests.ts"
|
||||
]
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user