mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-04-01 09:01:45 +08:00
defs + tests from examples
This commit is contained in:
19
hashids/hashids-test.ts
Normal file
19
hashids/hashids-test.ts
Normal 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
36
hashids/hashids.d.ts
vendored
Normal 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;
|
||||
}
|
||||
Reference in New Issue
Block a user