defs + tests from examples

This commit is contained in:
Paulo Cesar
2015-05-24 19:39:37 -03:00
parent c2b70ba731
commit 0242bb8147
2 changed files with 55 additions and 0 deletions

19
hashids/hashids-test.ts Normal file
View File

@@ -0,0 +1,19 @@
/// <reference path="hashids.d.ts" />
/* 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);

36
hashids/hashids.d.ts vendored Normal file
View File

@@ -0,0 +1,36 @@
// Type definitions for Hashids.js 1.x
// Project: https://github.com/ivanakimov/hashids.node.js
// Definitions by: Paulo Cesar <https://github.com/pocesar/>
// Definitions: https://github.com/borisyankov/DefinitelyTyped
/// <reference path="../node/node.d.ts" />
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;
}