mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-06-30 23:30:06 +00:00
update uuid to v3 (#16264)
* update uuid to v3 - remove the parse/unparse functions - allow importing 'uuid/v1' and 'uuid/v4' directly - keep v2 typings as 'uuid-v2' * Fix v2 folder naming
This commit is contained in:
37
types/uuid/index.d.ts
vendored
37
types/uuid/index.d.ts
vendored
@@ -1,35 +1,16 @@
|
||||
// Type definitions for uuid v2.0.3
|
||||
// Type definitions for uuid 3.0
|
||||
// Project: https://github.com/defunctzombie/node-uuid
|
||||
// Definitions by: Oliver Hoffmann <https://github.com/iamolivinius/>
|
||||
// Felipe Ochoa <https://github.com/felipeochoa/>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.2
|
||||
|
||||
/// <reference types="node" />
|
||||
import { v1, v4 } from './interfaces';
|
||||
|
||||
declare namespace uuid {
|
||||
interface V1Options {
|
||||
node?: number[];
|
||||
clockseq?: number;
|
||||
msecs?: number | Date;
|
||||
nsecs?: number;
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
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 UuidStatic {
|
||||
v1: v1;
|
||||
v4: v4;
|
||||
}
|
||||
|
||||
declare const uuid: uuid.UuidStatic
|
||||
export = uuid
|
||||
declare const uuid: UuidStatic & v4;
|
||||
export = uuid;
|
||||
|
||||
21
types/uuid/interfaces.d.ts
vendored
Normal file
21
types/uuid/interfaces.d.ts
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
/// <reference types="node" />
|
||||
|
||||
// Uses ArrayLike to admit Unit8 and co.
|
||||
export type OutputBuffer = ArrayLike<number> | Buffer;
|
||||
|
||||
export interface V1Options {
|
||||
node?: number[];
|
||||
clockseq?: number;
|
||||
msecs?: number | Date;
|
||||
nsecs?: number;
|
||||
}
|
||||
|
||||
export type V4Options = {random: number[]} | {rng(): number[]};
|
||||
|
||||
export type v1String = (options?: V1Options) => string;
|
||||
export type v1Buffer = <T extends OutputBuffer>(options: V1Options | null | undefined, buffer: T, offset?: number) => T;
|
||||
export type v1 = v1String & v1Buffer;
|
||||
|
||||
export type v4String = (options?: V4Options) => string;
|
||||
export type v4Buffer = <T extends OutputBuffer>(options: V4Options | null | undefined, buffer: T, offset?: number) => T;
|
||||
export type v4 = v4String & v4Buffer;
|
||||
@@ -6,7 +6,9 @@
|
||||
],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictNullChecks": false,
|
||||
"strictNullChecks": true,
|
||||
"alwaysStrict": true,
|
||||
"strict": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": [
|
||||
"../"
|
||||
@@ -17,6 +19,9 @@
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"v1.d.ts",
|
||||
"v4.d.ts",
|
||||
"interfaces.d.ts",
|
||||
"uuid-tests.ts"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
1
types/uuid/tslint.json
Normal file
1
types/uuid/tslint.json
Normal file
@@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
@@ -1,31 +1,43 @@
|
||||
import uuid = require('uuid');
|
||||
import v1 = require('uuid/v1');
|
||||
import v4 = require('uuid/v4');
|
||||
|
||||
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
|
||||
node: [0x01, 0x23, 0x45, 0x67, 0x89, 0xab],
|
||||
clockseq: 0x1234,
|
||||
msecs: new Date('2011-11-01').getTime(),
|
||||
nsecs: 5678
|
||||
});
|
||||
|
||||
let bufferv1: number[] = new Array(32);
|
||||
uuidv1 = v1();
|
||||
uuidv1 = v1({
|
||||
node: [0x01, 0x23, 0x45, 0x67, 0x89, 0xab],
|
||||
clockseq: 0x1234,
|
||||
msecs: new Date('2011-11-01').getTime(),
|
||||
nsecs: 5678
|
||||
});
|
||||
|
||||
let bufferv1 = new Uint8Array(32);
|
||||
bufferv1 = uuid.v1(null, bufferv1);
|
||||
bufferv1 = uuid.v1(null, bufferv1, 16);
|
||||
bufferv1 = uuid.v1(undefined, bufferv1, 16);
|
||||
bufferv1 = v1(undefined, bufferv1);
|
||||
bufferv1 = 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
|
||||
0x10, 0x91, 0x56, 0xbe, 0xc4, 0xfb, 0xc1, 0xea,
|
||||
0x71, 0xb4, 0xef, 0xe1, 0x67, 0x1c, 0x58, 0x36
|
||||
];
|
||||
uuidv4 = uuid({ random: randoms });
|
||||
uuidv4 = uuid({ rng: () => randoms })
|
||||
uuidv4 = uuid({ rng: () => randoms });
|
||||
uuidv4 = v4({ random: randoms });
|
||||
uuidv4 = v4({ rng: () => randoms });
|
||||
|
||||
let bufferv4: number[] = new Array(32);
|
||||
bufferv4 = uuid(null, bufferv4);
|
||||
bufferv4 = uuid(undefined, bufferv4);
|
||||
bufferv4 = uuid(null, bufferv4, 16);
|
||||
|
||||
let nodeBufferv4 = Buffer.alloc(32);
|
||||
nodeBufferv4 = uuid.v4(null, nodeBufferv4);
|
||||
nodeBufferv4 = uuid.v4(null, nodeBufferv4, 16);
|
||||
bufferv4 = v4(null, bufferv4);
|
||||
bufferv4 = v4(undefined, bufferv4, 16);
|
||||
|
||||
5
types/uuid/v1.d.ts
vendored
Normal file
5
types/uuid/v1.d.ts
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
import { v1 } from './interfaces';
|
||||
|
||||
declare const v1: v1;
|
||||
|
||||
export = v1;
|
||||
35
types/uuid/v2/index.d.ts
vendored
Normal file
35
types/uuid/v2/index.d.ts
vendored
Normal file
@@ -0,0 +1,35 @@
|
||||
// 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;
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
declare const uuid: uuid.UuidStatic
|
||||
export = uuid
|
||||
25
types/uuid/v2/tsconfig.json
Normal file
25
types/uuid/v2/tsconfig.json
Normal file
@@ -0,0 +1,25 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": [
|
||||
"es6"
|
||||
],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictNullChecks": false,
|
||||
"baseUrl": "../..",
|
||||
"typeRoots": [
|
||||
"../.."
|
||||
],
|
||||
"paths": {
|
||||
"uuid": ["uuid/v2"]
|
||||
},
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"uuid-tests.ts"
|
||||
]
|
||||
}
|
||||
31
types/uuid/v2/uuid-tests.ts
Normal file
31
types/uuid/v2/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);
|
||||
5
types/uuid/v4.d.ts
vendored
Normal file
5
types/uuid/v4.d.ts
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
import { v4 } from './interfaces';
|
||||
|
||||
declare const v4: v4;
|
||||
|
||||
export = v4;
|
||||
Reference in New Issue
Block a user