From 8ca6bc3f619666c4a56bf1b5db54851ddcb24f9e Mon Sep 17 00:00:00 2001 From: rhysd Date: Sun, 6 Dec 2015 22:54:48 +0900 Subject: [PATCH] Add type definitions of shuffle-array package --- shuffle-array/shuffle-array-tests.ts | 20 +++++++++++++ shuffle-array/shuffle-array.d.ts | 42 ++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+) create mode 100644 shuffle-array/shuffle-array-tests.ts create mode 100644 shuffle-array/shuffle-array.d.ts diff --git a/shuffle-array/shuffle-array-tests.ts b/shuffle-array/shuffle-array-tests.ts new file mode 100644 index 000000000..9b799bb6e --- /dev/null +++ b/shuffle-array/shuffle-array-tests.ts @@ -0,0 +1,20 @@ +/// + +import shuffle = require('shuffle-array'); + +// shuffle() +var a = [1, 2, 3, 4, 5]; +var result: number[]; +result = shuffle(a); +result = shuffle(a, {}); +result = shuffle(a, {copy: true}); +result = shuffle(a, {rng: () => 0}); +result = shuffle(a, {copy: true, rng: () => 0}); + +var b = ['aaa', 'bbb', 'ccc'] +var result2: string[]; +result2 = shuffle.pick(b); +result2 = shuffle.pick(b, {}); +result2 = shuffle.pick(b, {picks: 3}); +result2 = shuffle.pick(b, {rng: () => 0}); +result2 = shuffle.pick(b, {picks: 3, rng: () => 0}); diff --git a/shuffle-array/shuffle-array.d.ts b/shuffle-array/shuffle-array.d.ts new file mode 100644 index 000000000..880396c4a --- /dev/null +++ b/shuffle-array/shuffle-array.d.ts @@ -0,0 +1,42 @@ +// Type definitions for shuffle-array +// Project: https://github.com/pazguille/shuffle-array +// Definitions by: rhysd +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +declare module "shuffle-array" { + /** + * copy - Sets if should return a shuffled copy of the given array. By default it's a falsy value. + * rng - Specifies a custom random number generator. + */ + interface ShuffleOption { + copy?: boolean; + rng?: () => number; + } + /** + * picks - Specifies how many random elements you want to pick. By default it picks 1. + * rng - Specifies a custom random number generator. + */ + interface PickOption { + picks?: number; + rng?: () => number; + } + interface ShuffleArray { + /** + * Randomizes the order of the elements in a given array. + * + * arr - The given array. + * options - Optional configuration options. + */ + (arr: T[], options?: ShuffleOption): T[]; + /** + * Pick one or more random elements from the given array. + * + * arr - The given array. + * options - Optional configuration options. + */ + pick(arr: T[], options?: Object): T[]; + } + var shuffle: ShuffleArray; + export = shuffle; +} +