mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2025-10-16 12:05:41 +00:00
* Remove incorrect callbacks, change state type
Seedrandom's state function does not return a function. It returns an object intended to be opaque, which I don't know how to describe in TS. It's serializable (unlike a function), so I made it just be an empty object. It's properties are unpredictable, but always of a similar shape: { [x]: number, [y]: number, [z]: number[] }. x,y, and z vary from implementation, and users are not intended to know what they are. The important thing is that it can be passed back to the state option when making a new instance of seedrandom, and that it be serializable (which the previous implementation was not).
In addition, seedrandom's alternate algorithms do not take a third "callback" argument, so I removed it.
* Adding attribution
46 lines
1.4 KiB
TypeScript
46 lines
1.4 KiB
TypeScript
// Type definitions for seedrandom 2.4.2
|
|
// Project: https://github.com/davidbau/seedrandom
|
|
// Definitions by: Kern Handa <https://github.com/kernhanda>, Eugene Zaretskiy <https://github.com/EugeneZ>
|
|
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
|
|
|
declare namespace seedrandom {
|
|
|
|
export type State = {};
|
|
|
|
interface prng {
|
|
new (seed?: string, options?: seedRandomOptions, callback?: any): prng;
|
|
(): number;
|
|
quick(): number;
|
|
int32(): number;
|
|
double(): number;
|
|
state(): State;
|
|
}
|
|
|
|
interface seedrandom_prng {
|
|
(seed?: string, options?: seedRandomOptions, callback?: seedrandomCallback): prng;
|
|
alea: (seed?: string, options?: seedRandomOptions) => prng;
|
|
xor128: (seed?: string, options?: seedRandomOptions) => prng;
|
|
tychei: (seed?: string, options?: seedRandomOptions) => prng;
|
|
xorwow: (seed?: string, options?: seedRandomOptions) => prng;
|
|
xor4096: (seed?: string, options?: seedRandomOptions) => prng;
|
|
xorshift7: (seed?: string, options?: seedRandomOptions) => prng;
|
|
quick: (seed?: string, options?: seedRandomOptions) => prng;
|
|
}
|
|
|
|
interface seedrandomCallback {
|
|
(prng?: prng, shortseed?: string, global?: boolean, state?: State): prng;
|
|
}
|
|
|
|
interface seedRandomOptions {
|
|
entropy?: boolean;
|
|
'global'?: boolean;
|
|
state?: boolean | State;
|
|
pass?: seedrandomCallback;
|
|
}
|
|
}
|
|
|
|
declare var seedrandom: seedrandom.seedrandom_prng;
|
|
|
|
export = seedrandom;
|
|
export as namespace seedrandom;
|