diff --git a/hashids/hashids-test.ts b/hashids/hashids-test.ts new file mode 100644 index 0000000000..9e51c8b8ab --- /dev/null +++ b/hashids/hashids-test.ts @@ -0,0 +1,19 @@ +/// + +/* require hashids */ +import Hashids = require("hashids"); + +/* creating class object */ +var hashids = new Hashids("this is my salt"); + +/* encoding several numbers into one id */ +var id = hashids.encode(1337, 5, 77, 12345678); +id = hashids.encode(1337); +id = hashids.encode(45, 434, 1313, 99); + +/* decoding that id */ +var numbers = hashids.decode(id); +numbers.length > 0 ? true : false; + +hashids = new Hashids("this is my salt", 0, "abcdefgh123456789"); +hashids = new Hashids("this is my salt", 8); diff --git a/hashids/hashids.d.ts b/hashids/hashids.d.ts new file mode 100644 index 0000000000..9a98259b0f --- /dev/null +++ b/hashids/hashids.d.ts @@ -0,0 +1,36 @@ +// Type definitions for Hashids.js 1.x +// Project: https://github.com/ivanakimov/hashids.node.js +// Definitions by: Paulo Cesar +// Definitions: https://github.com/borisyankov/DefinitelyTyped + +/// + +declare module Hashids { + + export interface IHashids { + new(salt: string, minHashLength?: number, alphabet?: string): IHashids; + version: string; + minAlphabetLength: number; + sepDiv: number; + guardDiv: number; + errorAlphabetLength: string; + errorAlphabetSpace: string; + alphabet: string[]; + seps: string; + minHashLength: number; + salt: string; + decode(hash: string): number[]; + encode(arg: number): string; + encode(arg: number[]): string; + encode(...args: number[]): string; + encodeHex(str: string): string; + decodeHex(hash: string): string; + hash(input: number, alphabet: string): string; + unhash(input: string[], alphabet: string): number; + } +} + +declare module 'hashids' { + var hashids: Hashids.IHashids; + export = hashids; +} \ No newline at end of file