From 625675d4d0029fdfd1648c35424da0e23568b07d Mon Sep 17 00:00:00 2001 From: Ian Copp Date: Tue, 1 May 2018 08:57:43 -0700 Subject: [PATCH] Add rword (#25444) --- types/rword/index.d.ts | 69 ++++++++++++++++++++++++++++++++++++++ types/rword/rword-tests.ts | 12 +++++++ types/rword/tsconfig.json | 23 +++++++++++++ types/rword/tslint.json | 1 + 4 files changed, 105 insertions(+) create mode 100644 types/rword/index.d.ts create mode 100644 types/rword/rword-tests.ts create mode 100644 types/rword/tsconfig.json create mode 100644 types/rword/tslint.json diff --git a/types/rword/index.d.ts b/types/rword/index.d.ts new file mode 100644 index 0000000000..cad044933b --- /dev/null +++ b/types/rword/index.d.ts @@ -0,0 +1,69 @@ +// Type definitions for rword 2.2 +// Project: https://github.com/Xyfir/rword#readme +// Definitions by: icopp +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +export interface GenerateOptions { + /** + * Allows you to set an exact length or range of lengths for words to return. + */ + length?: number | string; + /** + * Words that don't match the regexp will not be returned. + */ + contains?: string | RegExp; + /** + * Changes the capitalization of the words returned. + */ + capitalize?: 'none' | 'all' | 'first'; +} + +/** + * Generates words from the global words array. + * @param count How many words to return. If 1 or not present, a string is + * returned. If greater than 1 an array of strings is returned. + * @param options Allows you to modify the output and words that could be + * randomly chosen. + */ +export function generate(count?: 1, options?: GenerateOptions): string; +/** + * Generates words from the global words array. + * @param count How many words to return. If 1 or not present, a string is + * returned. If greater than 1 an array of strings is returned. + * @param options Allows you to modify the output and words that could be + * randomly chosen. + */ +export function generate(count: number, options?: GenerateOptions): string[]; + +/** + * Generates words from the global pool array. The pool is automatically + * filled using rword.generate(500) and then words are taken out of that + * array as needed. Faster than rword.generate() for generating small + * amounts of words. + * + * You cannot request more than 10 words through this method. + * + * @param count How many words to return. If 1 or not present, a string is + * returned. If greater than 1 an array of strings is returned. + */ +export function generateFromPool(count?: 1): string; + +/** + * Generates words from the global pool array. The pool is automatically + * filled using rword.generate(500) and then words are taken out of that + * array as needed. Faster than rword.generate() for generating small + * amounts of words. + * + * You cannot request more than 10 words through this method. + * + * @param count How many words to return. If 1 or not present, a string is + * returned. If greater than 1 an array of strings is returned. + */ +export function generateFromPool(count: 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10): string[]; + +/** + * Shuffles both the global words and pool arrays. This method can most + * likely be ignored as it is automatically called on first run and then + * every 10 to 30 minutes after. + */ +export function shuffle(): void; diff --git a/types/rword/rword-tests.ts b/types/rword/rword-tests.ts new file mode 100644 index 0000000000..7fbab8082a --- /dev/null +++ b/types/rword/rword-tests.ts @@ -0,0 +1,12 @@ +import rword = require('rword'); + +rword.generate(); // $ExpectType string +rword.generate(5, { length: 5 }); // $ExpectType string[] +rword.generate(3, { length: '3-4' }); // $ExpectType string[] +rword.generate(5, { contains: '.*ed' }); // $ExpectType string[] +rword.generate(5, { contains: 'af' }); // $ExpectType string[] +rword.generate(5, { contains: /.*ing$/ }); // $ExpectType string[] +rword.generate(3, { capitalize: 'all' }); // $ExpectType string[] +rword.generate(3, { capitalize: 'first' }); // $ExpectType string[] +rword.generateFromPool(5); // $ExpectType string[] +rword.shuffle(); // $ExpectType void diff --git a/types/rword/tsconfig.json b/types/rword/tsconfig.json new file mode 100644 index 0000000000..f98e8b5cb7 --- /dev/null +++ b/types/rword/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "rword-tests.ts" + ] +} diff --git a/types/rword/tslint.json b/types/rword/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/rword/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }