-
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2c32302
commit ec25adc
Showing
7 changed files
with
112 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1 @@ | ||
* text=auto | ||
*.js text eol=lf | ||
* text=auto eol=lf |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
language: node_js | ||
node_js: | ||
- '10' | ||
- '8' | ||
- '6' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import ColorClass = require('color'); | ||
|
||
declare namespace Randoma { | ||
interface Options { | ||
/** | ||
[Initialization seed.](https://en.m.wikipedia.org/wiki/Random_seed) Multiple instances of `Randoma` with the same seed will generate the same random numbers. | ||
*/ | ||
seed: string | number; | ||
} | ||
|
||
type Color = ColorClass; | ||
} | ||
|
||
declare class Randoma { | ||
/** | ||
@returns A random seed you could use in the `seed` option if you for some reason don't want deterministic randomness. | ||
*/ | ||
static seed(): number; | ||
|
||
/** | ||
User-friendly [pseudorandom number generator (PRNG)](https://en.wikipedia.org/wiki/Pseudorandom_number_generator). | ||
This is not cryptographically secure. | ||
@example | ||
``` | ||
import Randoma = require('randoma'); | ||
const random = new Randoma({seed: 10}); | ||
random.integer(); | ||
//=> 2027521326 | ||
random.integer(); | ||
//=> 677268843 | ||
(new Randoma({seed: '🦄'}).integer()); | ||
//=> 1659974344 | ||
(new Randoma({seed: '🦄'}).integer()); | ||
//=> 1659974344 | ||
``` | ||
*/ | ||
constructor(options: Randoma.Options); | ||
|
||
integer(): number; | ||
integerInRange(min: number, max: number): number; | ||
float(): number; | ||
floatInRange(min: number, max: number): number; | ||
boolean(): boolean; | ||
arrayItem<T>(array: readonly T[]): T; | ||
date(): Date; | ||
dateInRange(startDate: Date, endDate: Date): Date; | ||
|
||
/** | ||
@param saturation - Saturation percentage in the range `0...1`. Default: `0.5`. | ||
@returns A random [aesthetically pleasing color](https://martin.ankerl.com/2009/12/09/how-to-create-random-colors-programmatically/) as a [`color`](https://github.com/Qix-/color) object. | ||
@example | ||
``` | ||
random.color(0.5).hex().toString() | ||
//=> '#AAF2B0' | ||
``` | ||
*/ | ||
color(saturation?: number): Randoma.Color; | ||
} | ||
|
||
export = Randoma; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import {expectType} from 'tsd'; | ||
import Randoma = require('.'); | ||
|
||
const options: Randoma.Options = {seed: 10}; | ||
|
||
const random = new Randoma(options); | ||
new Randoma({seed: '🦄'}); | ||
new Randoma({seed: Randoma.seed()}); | ||
|
||
expectType<number>(random.integer()); | ||
expectType<number>(random.integerInRange(0, 1)); | ||
expectType<number>(random.float()); | ||
expectType<number>(random.floatInRange(0, 1)); | ||
expectType<boolean>(random.boolean()); | ||
expectType<string>(random.arrayItem(['🦄'])); | ||
expectType<Date>(random.date()); | ||
expectType<Date>(random.dateInRange(new Date(), new Date())); | ||
expectType<Randoma.Color>(random.color()); | ||
random | ||
.color(0.5) | ||
.hex() | ||
.toString(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters