Added support for LiosK's UUID.js

This commit is contained in:
Jason Jarrett 2013-08-30 21:04:36 -07:00
parent 9653895ef1
commit 6e22352317
2 changed files with 134 additions and 0 deletions

46
UUID/UUID-tests.ts Normal file
View File

@ -0,0 +1,46 @@
/// <reference path="UUID.d.ts" />
// Copied below from readme at https://github.com/LiosK/UUID.js
// the simplest way to get an UUID (as a hexadecimal string)
console.log(UUID.generate()); // "0db9a5fa-f532-4736-89d6-8819c7f3ac7b"
// create a version 4 (random-numbers-based) UUID object
var objV4 = UUID.genV4();
// create a version 1 (time-based) UUID object
var objV1 = UUID.genV1();
// create an UUID object from a hexadecimal string
var uuid = UUID.parse("a0e0f130-8c21-11df-92d9-95795a3bcd40");
// UUID object as a string
console.log(uuid.toString()); // "a0e0f130-8c21-11df-92d9-95795a3bcd40"
console.log(uuid.hexString); // "a0e0f130-8c21-11df-92d9-95795a3bcd40"
console.log(uuid.bitString); // "101000001110000 ... 1100110101000000"
console.log(uuid.urn); // "urn:uuid:a0e0f130-8c21-11df-92d9-95795a3bcd40"
// compare UUID objects
console.log(objV4.equals(objV1)); // false
// show version numbers
console.log(objV4.version); // 4
console.log(objV1.version); // 1
// get UUID field values in 3 different formats by 2 different accessors
console.log(uuid.intFields.timeLow); // 2699096368
console.log(uuid.bitFields.timeMid); // "1000110000100001"
console.log(uuid.hexFields.timeHiAndVersion); // "11df"
console.log(uuid.intFields.clockSeqHiAndReserved); // 146
console.log(uuid.bitFields.clockSeqLow); // "11011001"
console.log(uuid.hexFields.node); // "95795a3bcd40"
console.log(uuid.intFields[0]); // 2699096368
console.log(uuid.bitFields[1]); // "1000110000100001"
console.log(uuid.hexFields[2]); // "11df"
console.log(uuid.intFields[3]); // 146
console.log(uuid.bitFields[4]); // "11011001"
console.log(uuid.hexFields[5]); // "95795a3bcd40"

88
UUID/UUID.d.ts vendored Normal file
View File

@ -0,0 +1,88 @@
// Type definitions for UUID.js core-1.0
// Project: https://github.com/LiosK/UUID.js
// Definitions by: Jason Jarrett <https://github.com/staxmanade/>
// Definitions: https://github.com/borisyankov/DefinitelyTyped
declare module UUID {
interface UUIDStatic {
/**
* The simplest function to get an UUID string.
* @returns {string} A version 4 UUID string.
*/
generate(): string;
/**
* Generates a version 4 {@link UUID}.
* @returns {UUID} A version 4 {@link UUID} object.
* @since 3.0
*/
genV4(): UUID;
/**
* Generates a version 1 {@link UUID}.
* @returns {UUID} A version 1 {@link UUID} object.
* @since 3.0
*/
genV1(): UUID;
/**
* Converts hexadecimal UUID string to an {@link UUID} object.
* @param {string} strId UUID hexadecimal string representation ("xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx").
* @returns {UUID} {@link UUID} object or null.
* @since 3.0
*/
parse(uuid: string): UUID;
/**
* Re-initializes version 1 UUID state.
* @since 3.0
*/
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.
*/
makeBackwardCompatible(): void;
}
interface UUIDArray<T> extends Array<T> {
timeLow: string;
timeMid: string;
timeHiAndVersion: string;
clockSeqHiAndReserved: string;
clockSeqLow: string;
node: string;
}
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;
}
}
declare var UUID: UUID.UUIDStatic;