forked from tzuryby/Faker.js
-
Notifications
You must be signed in to change notification settings - Fork 3
/
unique.ts
38 lines (33 loc) · 867 Bytes
/
unique.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import uniqueExec from "../vendor/unique.ts";
/**
*
* @namespace faker.unique
*/
class Unique {
constructor(faker: any) {}
// initialize unique module class variables
// maximum time unique.exec will attempt to run before aborting
maxTime?: 10;
// maximum retries unique.exec will recurse before abortings ( max loop depth )
maxRetries?: 10;
// time the script started
// const startTime = 0;
/**
* unique
*
* @method unique
*/
unique(method: Function, args: any, opts: any) {
opts = opts || {};
opts.startTime = new Date().getTime();
if (typeof opts.maxTime !== "number") {
opts.maxTime = this.maxTime;
}
if (typeof opts.maxRetries !== "number") {
opts.maxRetries = this.maxRetries;
}
opts.currentIterations = 0;
return uniqueExec.exec(method, args, opts);
}
}
export { Unique };