DefinitelyTyped/types/seedrandom/index.d.ts
Eugene Zaretskiy 13e6a6482d [seedrandom] State should be serializable, and removing incorrect callbacks (#34151)
* 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
2019-03-27 16:55:51 -07:00

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;