Add definition for uuid-1345

npm: https://www.npmjs.com/package/uuid-1345
project: https://github.com/scravy/uuid-1345
This commit is contained in:
TANAKA Koichi
2016-03-24 00:17:44 +09:00
parent a44529fcb1
commit dc679ea85e
2 changed files with 304 additions and 0 deletions

View File

@@ -0,0 +1,220 @@
///<reference path="../node/node.d.ts" />
///<reference path="./uuid-1345.d.ts" />
'use strict';
import * as UUID from 'uuid-1345';
var uuid:string;
var uuidBuffer:Buffer;
var uuidObject:UUID.UUID;
// sync without options
uuid = UUID.v1();
uuid = UUID.v4();
uuid = UUID.v4fast();
// sync with options
uuid = UUID.v1({encoding: 'ascii'});
uuidBuffer = UUID.v1({encoding: 'binary'});
uuidObject = UUID.v1({encoding: 'object'});
uuid = UUID.v3({namespace: uuid, name: 'http://example.com/'});
uuid = UUID.v3({encoding: 'ascii', namespace: uuidBuffer, name: 'http://example.com/'});
uuidBuffer = UUID.v3({encoding: 'binary', namespace: uuidObject, name: 'http://example.com/'});
uuidObject = UUID.v3({encoding: 'object', namespace: uuid, name: 'http://example.com/'});
uuid = UUID.v4({encoding: 'ascii'});
uuidBuffer = UUID.v4({encoding: 'binary'});
uuidObject = UUID.v4({encoding: 'object'});
uuid = UUID.v4fast({encoding: 'ascii'});
uuidBuffer = UUID.v4fast({encoding: 'binary'});
uuidObject = UUID.v4fast({encoding: 'object'});
uuid = UUID.v5({namespace: uuid, name: 'http://example.com/'});
uuid = UUID.v5({encoding: 'ascii', namespace: uuidBuffer, name: 'http://example.com/'});
uuidBuffer = UUID.v5({encoding: 'binary', namespace: uuidObject, name: 'http://example.com/'});
uuidObject = UUID.v5({encoding: 'object', namespace: uuid, name: 'http://example.com/'});
// async without options
UUID.v1((error:string, result:string) => {
if (error) {
console.error(error);
} else {
console.log(result);
}
});
UUID.v4((error:string, result:string) => {
if (error) {
console.error(error);
} else {
console.log(result);
}
});
UUID.v4fast((error: string, result:string) => {
if (error) {
console.error(error);
} else {
console.log(result);
}
});
// async with options
UUID.v1({encoding: 'ascii'}, (error: string, result:string) => {
if (error) {
console.error(error);
} else {
console.log(result);
}
});
UUID.v1({encoding: 'binary'}, (error: string, result:Buffer) => {
if (error) {
console.error(error);
} else {
console.log(result);
}
});
UUID.v1({encoding: 'object'}, (error: string, result:UUID.UUID) => {
if (error) {
console.error(error);
} else {
console.log(result);
}
});
UUID.v1({mac: false}, (error: string, result:string) => {
if (error) {
console.error(error);
} else {
console.log(result);
}
});
UUID.v3({namespace: uuid, name: 'http://example.com/'}, (error: string, result:string) => {
if (error) {
console.error(error);
} else {
console.log(result);
}
});
UUID.v3({encoding: 'ascii', namespace: uuidBuffer, name: 'http://example.com/'}, (error: string, result:string) => {
if (error) {
console.error(error);
} else {
console.log(result);
}
});
UUID.v3({encoding: 'binary', namespace: uuidObject, name: 'http://example.com/'}, (error: string, result:Buffer) => {
if (error) {
console.error(error);
} else {
console.log(result);
}
});
UUID.v3({encoding: 'object', namespace: uuid, name: 'http://example.com/'}, (error: string, result:UUID.UUID) => {
if (error) {
console.error(error);
} else {
console.log(result);
}
});
UUID.v4({encoding: 'ascii'}, (error: string, result:string) => {
if (error) {
console.error(error);
} else {
console.log(result);
}
});
UUID.v4({encoding: 'binary'}, (error: string, result:Buffer) => {
if (error) {
console.error(error);
} else {
console.log(result);
}
});
UUID.v4({encoding: 'object'}, (error: string, result:UUID.UUID) => {
if (error) {
console.error(error);
} else {
console.log(result);
}
});
UUID.v4fast({encoding: 'ascii'}, (error: string, result:string) => {
if (error) {
console.error(error);
} else {
console.log(result);
}
});
UUID.v4fast({encoding: 'binary'}, (error: string, result:Buffer) => {
if (error) {
console.error(error);
} else {
console.log(result);
}
});
UUID.v4fast({encoding: 'object'}, (error: string, result:UUID.UUID) => {
if (error) {
console.error(error);
} else {
console.log(result);
}
});
UUID.v5({namespace: uuid, name: 'http://example.com/'}, (error: string, result:string) => {
if (error) {
console.error(error);
} else {
console.log(result);
}
});
UUID.v5({encoding: 'ascii', namespace: uuidBuffer, name: 'http://example.com/'}, (error: string, result:string) => {
if (error) {
console.error(error);
} else {
console.log(result);
}
});
UUID.v5({encoding: 'binary', namespace: uuidObject, name: 'http://example.com/'}, (error: string, result:Buffer) => {
if (error) {
console.error(error);
} else {
console.log(result);
}
});
UUID.v5({encoding: 'object', namespace: uuid, name: 'http://example.com/'}, (error: string, result:UUID.UUID) => {
if (error) {
console.error(error);
} else {
console.log(result);
}
});
// namespaces for v3, v5
console.log(UUID.namespace.dns);
console.log(UUID.namespace.url);
console.log(UUID.namespace.oid);
console.log(UUID.namespace.x500);
// more API
var checkResult:{version?:number, variant:string, format:string};
checkResult = UUID.check(uuid);
uuidBuffer = UUID.parse(uuid);
uuid = UUID.stringify(uuidBuffer);

84
uuid-1345/uuid-1345.d.ts vendored Normal file
View File

@@ -0,0 +1,84 @@
// Type definitions for uuid-1345 0.99
// Project: https://github.com/scravy/uuid-1345
// Definitions by: TANAKA Koichi <https://github.com/mugeso/>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
///<reference path="../node/node" />
declare module "uuid-1345" {
export interface UUID {
version: string;
variant: string;
toString(): string;
toBuffer(): Buffer;
}
type UuidTypes = string|Buffer|UUID;
interface ASCIICallback {
(error: string, result: string):void;
}
interface BinaryCallback {
(error: string, result: Buffer):void;
}
interface ObjectCallback {
(error: string, result: UUID):void;
}
export var namespace: {
dns: UUID
url: UUID,
oid: UUID,
x500: UUID
};
export function check(uuid:string|Buffer): {version?:number, variant: string, format: string};
export function parse(uuid:string): Buffer;
export function stringify(uuid:Buffer): string;
export function v1():string;
export function v1(options:{mac?:boolean}):string;
export function v1(options:{encoding:'ascii', mac?:boolean}):string;
export function v1(options:{encoding:'binary', mac?:boolean}):Buffer;
export function v1(options:{encoding:'object', mac?:boolean}):UUID;
export function v1(options:{mac?:boolean}, callback:ASCIICallback):void;
export function v1(options:{encoding:'ascii', mac?:boolean}, callback:ASCIICallback):void;
export function v1(options:{encoding:'binary', mac?:boolean}, callback:BinaryCallback):void;
export function v1(options:{encoding:'object', mac?:boolean}, callback:ObjectCallback):void;
export function v1(callback:ASCIICallback):void;
export function v3(options:{namespace:UuidTypes, name: string}):string;
export function v3(options:{encoding:'ascii', namespace:UuidTypes, name: string}):string;
export function v3(options:{encoding:'binary', namespace:UuidTypes, name: string}):Buffer;
export function v3(options:{encoding:'object', namespace:UuidTypes, name: string}):UUID;
export function v3(options:{namespace:UuidTypes, name: string}, callback:ASCIICallback):void;
export function v3(options:{encoding:'ascii', namespace:UuidTypes, name: string}, callback:ASCIICallback):void;
export function v3(options:{encoding:'binary', namespace:UuidTypes, name: string}, callback:BinaryCallback):void;
export function v3(options:{encoding:'object', namespace:UuidTypes, name: string}, callback:ObjectCallback):void;
export function v4():string;
export function v4(options:{encoding:'ascii'}):string;
export function v4(options:{encoding:'binary'}):Buffer;
export function v4(options:{encoding:'object'}):UUID;
export function v4(options:{encoding:'ascii'}, callback:ASCIICallback):void;
export function v4(options:{encoding:'binary'}, callback:BinaryCallback):void;
export function v4(options:{encoding:'object'}, callback:ObjectCallback):void;
export function v4(callback:ASCIICallback):void;
export function v4fast():string;
export function v4fast(options:{encoding:'ascii'}):string;
export function v4fast(options:{encoding:'binary'}):Buffer;
export function v4fast(options:{encoding:'object'}):UUID;
export function v4fast(options:{encoding:'ascii'}, callback:ASCIICallback):void;
export function v4fast(options:{encoding:'binary'}, callback:BinaryCallback):void;
export function v4fast(options:{encoding:'object'}, callback:ObjectCallback):void;
export function v4fast(callback:ASCIICallback):void;
export function v5(options:{namespace:UuidTypes, name: string}):string;
export function v5(options:{encoding:'ascii', namespace:UuidTypes, name: string}):string;
export function v5(options:{encoding:'binary', namespace:UuidTypes, name: string}):Buffer;
export function v5(options:{encoding:'object', namespace:UuidTypes, name: string}):UUID;
export function v5(options:{namespace:UuidTypes, name: string}, callback:ASCIICallback):void;
export function v5(options:{encoding:'ascii', namespace:UuidTypes, name: string}, callback:ASCIICallback):void;
export function v5(options:{encoding:'binary', namespace:UuidTypes, name: string}, callback:BinaryCallback):void;
export function v5(options:{encoding:'object', namespace:UuidTypes, name: string}, callback:ObjectCallback):void;
}