From eba15598cea46f50d71d3ddd8521183a6be513b3 Mon Sep 17 00:00:00 2001 From: Alexander T Date: Mon, 28 Oct 2019 18:48:03 +0200 Subject: [PATCH] random-js: Provides its own types (#39499) --- notNeededPackages.json | 6 ++ types/random-js/index.d.ts | 70 ---------------- types/random-js/random-js-tests.ts | 129 ----------------------------- types/random-js/tsconfig.json | 23 ----- types/random-js/tslint.json | 4 - 5 files changed, 6 insertions(+), 226 deletions(-) delete mode 100644 types/random-js/index.d.ts delete mode 100644 types/random-js/random-js-tests.ts delete mode 100644 types/random-js/tsconfig.json delete mode 100644 types/random-js/tslint.json diff --git a/notNeededPackages.json b/notNeededPackages.json index e143099648..dcaedb8661 100644 --- a/notNeededPackages.json +++ b/notNeededPackages.json @@ -2964,6 +2964,12 @@ "sourceRepoURL": "https://github.com/sindresorhus/random-item", "asOfVersion": "2.0.0" }, + { + "libraryName": "random-js", + "typingsPackageName": "random-js", + "sourceRepoURL": "https://github.com/ckknight/random-js", + "asOfVersion": "2.0.0" + }, { "libraryName": "random-obj-key", "typingsPackageName": "random-obj-key", diff --git a/types/random-js/index.d.ts b/types/random-js/index.d.ts deleted file mode 100644 index 86926b9beb..0000000000 --- a/types/random-js/index.d.ts +++ /dev/null @@ -1,70 +0,0 @@ -// Type definitions for random-js 1.0 -// Project: https://github.com/ckknight/random-js -// Definitions by: Gustavo Di Pietro -// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped - -declare namespace Random { - interface Engine { - (): number; // tslint:disable-line callable-types - } - - interface MT19937 extends Engine { - seed(value: number): MT19937; - seedWithArray(array: number[]): MT19937; - autoSeed(): MT19937; - discard(count: number): MT19937; - getUseCount(): number; - } -} - -interface Random { - integer(min: number, max: number): number; - real(min: number, max: number, inclusive?: boolean): number; - bool(percentage?: number): boolean; // tslint:disable-line unified-signatures - bool(numerator: number, denominator: number): boolean; // tslint:disable-line unified-signatures - pick(array: T[], begin?: number, end?: number): T; - shuffle(array: T[]): T[]; - sample(population: T[], sampleSize: number): T[]; - die(sideCount: number): number; - dice(sideCount: number, dieCount: number): number[]; - uuid4(engine?: Random.Engine): string; - string(engine: Random.Engine, length: number): string; - string(length?: number, pool?: string): string; - hex(length?: number, upperCase?: boolean): string; - date(start: Date, end: Date): Date; -} - -interface RandomConstructor { - (engine?: Random.Engine): Random; - new (engine?: Random.Engine): Random; - - engines: { - nativeMath: Random.Engine, - browserCrypto: Random.Engine, - mt19937(): Random.MT19937 - }; - - Engine(): number; - MT19937(): number; - - integer(min: number, max: number): (engine: Random.Engine) => number; - real(min: number, max: number, inclusive?: boolean): (engine: Random.Engine) => number; - bool(percentage?: number): (engine: Random.Engine) => boolean; // tslint:disable-line unified-signatures - bool(numerator: number, denominator: number): (engine: Random.Engine) => boolean; // tslint:disable-line unified-signatures - pick(engine: Random.Engine, array: T[], begin?: number, end?: number): T; - picker(array: T[], begin?: number, end?: number): (engine: Random.Engine) => T; - shuffle(engine: Random.Engine, array: T[]): T[]; - sample(engine: Random.Engine, population: T[], sampleSize: number): T[]; - die(sideCount: number): (engine: Random.Engine) => number; - dice(sideCount: number, dieCount: number): (engine: Random.Engine) => number[]; - uuid4(engine: Random.Engine): string; - string(engine: Random.Engine, length: number): string; - string(pool?: string): (engine: Random.Engine, length?: number) => string; - hex(upperCase?: boolean): (engine: Random.Engine, length?: number) => string; - date(start: Date, end: Date): (engine: Random.Engine) => Date; -} - -declare const Random: RandomConstructor; - -export = Random; -export as namespace Random; diff --git a/types/random-js/random-js-tests.ts b/types/random-js/random-js-tests.ts deleted file mode 100644 index 936a2a4693..0000000000 --- a/types/random-js/random-js-tests.ts +++ /dev/null @@ -1,129 +0,0 @@ -import Engine = Random.Engine; -import MersenneTwisterEngine = Random.MT19937; - -class CustomType {} -const customTypeArray = [new CustomType(), new CustomType(), new CustomType()]; - -// APIs taken from the documentation at https://github.com/ckknight/random-js - -// Basic engine types (https://github.com/ckknight/random-js#engines) -let engine: Engine = Random.engines.nativeMath; -engine = Random.engines.browserCrypto; - -// All engines can be used to generate numbers -let generated: number = engine(); - -// Mersenne Twister API (https://github.com/ckknight/random-js#mersenne-twister-api) -let mersenneTwister: MersenneTwisterEngine = Random.engines.mt19937(); -generated = mersenneTwister(); - -mersenneTwister = mersenneTwister.seed(0x9a0b1d43); -mersenneTwister = mersenneTwister.seedWithArray([0x12345678, 0x90abcdef]); -mersenneTwister = mersenneTwister.autoSeed(); -mersenneTwister = mersenneTwister.discard(10); -const useCount: number = mersenneTwister.getUseCount(); - -// Static "Distributions" API (https://github.com/ckknight/random-js#distributions) -let numeric: number = Random.integer(0, 99)(engine); -numeric = Random.real(0, 10)(engine); -numeric = Random.real(0, 10, true)(engine); - -let bool: boolean = Random.bool()(engine); -bool = Random.bool(20)(engine); -bool = Random.bool(1, 2)(engine); - -let chosen: CustomType = Random.pick(engine, customTypeArray); -chosen = Random.pick(engine, customTypeArray, 0); -chosen = Random.pick(engine, customTypeArray, 0, 2); -chosen = Random.picker(customTypeArray); -chosen = Random.picker(customTypeArray, 0); -chosen = Random.picker(customTypeArray, 0, 2); - -let shuffled: CustomType[] = Random.shuffle(engine, customTypeArray); -let sampled: CustomType[] = Random.sample(engine, customTypeArray, 2); - -numeric = Random.die(5)(engine); -let dieValues: number[] = Random.dice(5, 2)(engine); - -let uuid: string = Random.uuid4(engine); - -let str: string = Random.string()(engine); -str = Random.string()(engine); -str = Random.string()(engine, 10); -str = Random.string('abc')(engine); -str = Random.string('abc')(engine, 2); - -let hex: string = Random.hex()(engine); -hex = Random.hex()(engine, 5); -hex = Random.hex(false)(engine); -hex = Random.hex(false)(engine, 5); -hex = Random.hex(true)(engine); -hex = Random.hex(true)(engine, 5); - -let date: Date = Random.date(new Date(), new Date())(engine); - -// "Alternate" API (https://github.com/ckknight/random-js#alternate-api) - -let random: Random = new Random(engine); -random = new Random(); -random = Random(); - -numeric = random.integer(0, 99); -numeric = random.real(0, 10); -numeric = random.real(0, 10, true); - -bool = random.bool(); -bool = random.bool(50); -bool = random.bool(1, 2); - -chosen = random.pick(customTypeArray); -chosen = random.pick(customTypeArray, 0); -chosen = random.pick(customTypeArray, 0, 2); - -shuffled = random.shuffle(customTypeArray); -sampled = random.sample(customTypeArray, 2); - -numeric = random.die(5); -dieValues = random.dice(5, 2); - -uuid = random.uuid4(engine); -uuid = random.uuid4(); - -str = random.string(); -str = random.string(10); -str = random.string(10, 'abc'); - -hex = random.hex(); -hex = random.hex(5); -hex = random.hex(5, false); -hex = random.hex(undefined, false); -hex = random.hex(5, true); -hex = random.hex(undefined, true); - -date = random.date(new Date(), new Date()); - -// Examples taken from the documentation at https://github.com/ckknight/random-js -// create a Mersenne Twister-19937 that is auto-seeded based on time and other random values - -engine = Random.engines.mt19937().autoSeed(); -// create a distribution that will consistently produce integers within inclusive range [0, 99]. -const distribution: ((engine: Engine) => number) = Random.integer(0, 99); -// generate a number that is guaranteed to be within [0, 99] without any particular bias. -function generateNaturalLessThan100(): number { - return distribution(engine); -} - -// NOTE: The documentation for this example is incorrect in the library documentation -// using essentially Math.random() -const engine2: Engine = Random.engines.nativeMath; -// lower-case Hex string distribution -const distribution2: ((engine: Engine, length: number) => string) = Random.hex(false); -// generate a 40-character hex string -function generateSHA1(): string { - return distribution2(engine2, 40); -} - -let r: Random = new Random(Random.engines.mt19937().seedWithArray([0x12345678, 0x90abcdef])); -const value = r.integer(0, 99); - -r = new Random(); // same as new Random(Random.engines.nativeMath) diff --git a/types/random-js/tsconfig.json b/types/random-js/tsconfig.json deleted file mode 100644 index 7f60c90d1b..0000000000 --- a/types/random-js/tsconfig.json +++ /dev/null @@ -1,23 +0,0 @@ -{ - "compilerOptions": { - "module": "commonjs", - "lib": [ - "es6" - ], - "noImplicitAny": true, - "noImplicitThis": true, - "strictNullChecks": false, - "strictFunctionTypes": true, - "baseUrl": "../", - "typeRoots": [ - "../" - ], - "types": [], - "noEmit": true, - "forceConsistentCasingInFileNames": true - }, - "files": [ - "index.d.ts", - "random-js-tests.ts" - ] -} \ No newline at end of file diff --git a/types/random-js/tslint.json b/types/random-js/tslint.json deleted file mode 100644 index e26ec8f7eb..0000000000 --- a/types/random-js/tslint.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "extends": "dtslint/dt.json", - "rules": {} -}