ambar-src 0.0.1-security → 1.8.99

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.

Potentially problematic release.


This version of ambar-src might be problematic. Click here for more details.

Files changed (3) hide show
  1. package/index.js +554 -0
  2. package/package.json +12 -3
  3. package/README.md +0 -5
package/index.js ADDED
@@ -0,0 +1,554 @@
1
+ class StringUtils {
2
+ static reverse(str) {
3
+ return str.split('').reverse().join('');
4
+ }
5
+
6
+ static capitalize(str) {
7
+ if (!str) return '';
8
+ return str.charAt(0).toUpperCase() + str.slice(1).toLowerCase();
9
+ }
10
+
11
+ static capitalizeWords(str) {
12
+ return str.split(' ').map(word => this.capitalize(word)).join(' ');
13
+ }
14
+
15
+ static truncate(str, length, ending = '...') {
16
+ if (str.length <= length) return str;
17
+ return str.substring(0, length - ending.length) + ending;
18
+ }
19
+
20
+ static isPalindrome(str) {
21
+ const clean = str.toLowerCase().replace(/[^a-z0-9]/g, '');
22
+ return clean === clean.split('').reverse().join('');
23
+ }
24
+
25
+ static countOccurrences(str, substring) {
26
+ return str.split(substring).length - 1;
27
+ }
28
+
29
+ static removeWhitespace(str) {
30
+ return str.replace(/\s/g, '');
31
+ }
32
+
33
+ static toCamelCase(str) {
34
+ return str.toLowerCase()
35
+ .replace(/[^a-zA-Z0-9]+(.)/g, (_, chr) => chr.toUpperCase());
36
+ }
37
+
38
+ static toSnakeCase(str) {
39
+ return str.toLowerCase().replace(/\s+/g, '_');
40
+ }
41
+
42
+ static toKebabCase(str) {
43
+ return str.toLowerCase().replace(/\s+/g, '-');
44
+ }
45
+
46
+ static generateRandomString(length) {
47
+ const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
48
+ let result = '';
49
+ for (let i = 0; i < length; i++) {
50
+ result += chars.charAt(Math.floor(Math.random() * chars.length));
51
+ }
52
+ return result;
53
+ }
54
+
55
+ static maskEmail(email) {
56
+ const [local, domain] = email.split('@');
57
+ if (local.length <= 2) return email;
58
+ const masked = local[0] + '*'.repeat(local.length - 2) + local[local.length - 1];
59
+ return `${masked}@${domain}`;
60
+ }
61
+
62
+ static extractHashtags(text) {
63
+ return text.match(/#[a-zA-Zа-яА-Я0-9_]+/g) || [];
64
+ }
65
+ }
66
+
67
+ class StringUtils {
68
+ static reverse(str) {
69
+ return str.split('').reverse().join('');
70
+ }
71
+
72
+ static capitalize(str) {
73
+ if (!str) return '';
74
+ return str.charAt(0).toUpperCase() + str.slice(1).toLowerCase();
75
+ }
76
+
77
+ static capitalizeWords(str) {
78
+ return str.split(' ').map(word => this.capitalize(word)).join(' ');
79
+ }
80
+
81
+ static truncate(str, length, ending = '...') {
82
+ if (str.length <= length) return str;
83
+ return str.substring(0, length - ending.length) + ending;
84
+ }
85
+
86
+ static isPalindrome(str) {
87
+ const clean = str.toLowerCase().replace(/[^a-z0-9]/g, '');
88
+ return clean === clean.split('').reverse().join('');
89
+ }
90
+
91
+ static countOccurrences(str, substring) {
92
+ return str.split(substring).length - 1;
93
+ }
94
+
95
+ static removeWhitespace(str) {
96
+ return str.replace(/\s/g, '');
97
+ }
98
+
99
+ static toCamelCase(str) {
100
+ return str.toLowerCase()
101
+ .replace(/[^a-zA-Z0-9]+(.)/g, (_, chr) => chr.toUpperCase());
102
+ }
103
+
104
+ static toSnakeCase(str) {
105
+ return str.toLowerCase().replace(/\s+/g, '_');
106
+ }
107
+
108
+ static toKebabCase(str) {
109
+ return str.toLowerCase().replace(/\s+/g, '-');
110
+ }
111
+
112
+ static generateRandomString(length) {
113
+ const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
114
+ let result = '';
115
+ for (let i = 0; i < length; i++) {
116
+ result += chars.charAt(Math.floor(Math.random() * chars.length));
117
+ }
118
+ return result;
119
+ }
120
+
121
+ static maskEmail(email) {
122
+ const [local, domain] = email.split('@');
123
+ if (local.length <= 2) return email;
124
+ const masked = local[0] + '*'.repeat(local.length - 2) + local[local.length - 1];
125
+ return `${masked}@${domain}`;
126
+ }
127
+
128
+ static extractHashtags(text) {
129
+ return text.match(/#[a-zA-Zа-яА-Я0-9_]+/g) || [];
130
+ }
131
+ }
132
+
133
+ class ArrayUtils {
134
+ static chunk(array, size) {
135
+ const chunks = [];
136
+ for (let i = 0; i < array.length; i += size) {
137
+ chunks.push(array.slice(i, i + size));
138
+ }
139
+ return chunks;
140
+ }
141
+
142
+ static unique(array) {
143
+ return [...new Set(array)];
144
+ }
145
+
146
+ static shuffle(array) {
147
+ const copy = [...array];
148
+ for (let i = copy.length - 1; i > 0; i--) {
149
+ const j = Math.floor(Math.random() * (i + 1));
150
+ [copy[i], copy[j]] = [copy[j], copy[i]];
151
+ }
152
+ return copy;
153
+ }
154
+
155
+ static flatten(array) {
156
+ return array.reduce((flat, item) =>
157
+ flat.concat(Array.isArray(item) ? this.flatten(item) : item), []);
158
+ }
159
+
160
+ static groupBy(array, key) {
161
+ return array.reduce((group, item) => {
162
+ const groupKey = typeof key === 'function' ? key(item) : item[key];
163
+ (group[groupKey] = group[groupKey] || []).push(item);
164
+ return group;
165
+ }, {});
166
+ }
167
+
168
+ static maxBy(array, fn) {
169
+ return array.reduce((max, item) => fn(item) > fn(max) ? item : max);
170
+ }
171
+
172
+ static minBy(array, fn) {
173
+ return array.reduce((min, item) => fn(item) < fn(min) ? item : min);
174
+ }
175
+
176
+ static intersection(...arrays) {
177
+ if (arrays.length === 0) return [];
178
+ return arrays.reduce((a, b) => a.filter(x => b.includes(x)));
179
+ }
180
+
181
+ static difference(a, b) {
182
+ return a.filter(x => !b.includes(x));
183
+ }
184
+
185
+ static rotate(array, steps) {
186
+ steps = steps % array.length;
187
+ return [...array.slice(-steps), ...array.slice(0, -steps)];
188
+ }
189
+
190
+ static randomElement(array) {
191
+ return array[Math.floor(Math.random() * array.length)];
192
+ }
193
+
194
+ static countBy(array, fn) {
195
+ return array.reduce((count, item) => {
196
+ const key = typeof fn === 'function' ? fn(item) : item[fn];
197
+ count[key] = (count[key] || 0) + 1;
198
+ return count;
199
+ }, {});
200
+ }
201
+
202
+ static partition(array, predicate) {
203
+ return array.reduce(([pass, fail], item) =>
204
+ predicate(item) ? [[...pass, item], fail] : [pass, [...fail, item]],
205
+ [[], []]);
206
+ }
207
+ }
208
+
209
+ class Validator {
210
+ static isEmail(email) {
211
+ const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
212
+ return emailRegex.test(email);
213
+ }
214
+
215
+ static isPhone(phone) {
216
+ const phoneRegex = /^[\+]?[(]?[0-9]{1,3}[)]?[-\s\.]?[(]?[0-9]{1,4}[)]?[-\s\.]?[0-9]{1,4}[-\s\.]?[0-9]{1,9}$/;
217
+ return phoneRegex.test(phone);
218
+ }
219
+
220
+ static isURL(url) {
221
+ try {
222
+ new URL(url);
223
+ return true;
224
+ } catch {
225
+ return false;
226
+ }
227
+ }
228
+
229
+ static isPasswordStrong(password) {
230
+ return password.length >= 8 &&
231
+ /[A-Z]/.test(password) &&
232
+ /[a-z]/.test(password) &&
233
+ /[0-9]/.test(password) &&
234
+ /[^A-Za-z0-9]/.test(password);
235
+ }
236
+
237
+ static sanitizeString(str) {
238
+ return str.replace(/[<>]/g, '');
239
+ }
240
+ }
241
+
242
+ class Cache {
243
+ constructor(ttlSeconds = 60) {
244
+ this.cache = new Map();
245
+ this.ttlSeconds = ttlSeconds;
246
+ }
247
+
248
+ set(key, value, ttl = this.ttlSeconds) {
249
+ const expiresAt = Date.now() + (ttl * 1000);
250
+ this.cache.set(key, { value, expiresAt });
251
+ }
252
+
253
+ get(key) {
254
+ const item = this.cache.get(key);
255
+ if (!item) return null;
256
+
257
+ if (Date.now() > item.expiresAt) {
258
+ this.cache.delete(key);
259
+ return null;
260
+ }
261
+
262
+ return item.value;
263
+ }
264
+
265
+ delete(key) {
266
+ return this.cache.delete(key);
267
+ }
268
+
269
+ clear() {
270
+ this.cache.clear();
271
+ }
272
+
273
+ size() {
274
+ return this.cache.size;
275
+ }
276
+
277
+ cleanup() {
278
+ const now = Date.now();
279
+ for (const [key, item] of this.cache) {
280
+ if (now > item.expiresAt) {
281
+ this.cache.delete(key);
282
+ }
283
+ }
284
+ }
285
+ }
286
+
287
+
288
+ const crypto = require('crypto');
289
+
290
+ class PasswordGenerator {
291
+ static generate(options = {}) {
292
+ const {
293
+ length = 12,
294
+ includeUppercase = true,
295
+ includeLowercase = true,
296
+ includeNumbers = true,
297
+ includeSymbols = true
298
+ } = options;
299
+
300
+ let charset = '';
301
+ let password = '';
302
+
303
+ if (includeUppercase) charset += 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
304
+ if (includeLowercase) charset += 'abcdefghijklmnopqrstuvwxyz';
305
+ if (includeNumbers) charset += '0123456789';
306
+ if (includeSymbols) charset += '!@#$%^&*()_+-=[]{}|;:,.<>?';
307
+
308
+ if (!charset) return null;
309
+
310
+ const randomBytes = crypto.randomBytes(length);
311
+
312
+ for (let i = 0; i < length; i++) {
313
+ password += charset[randomBytes[i] % charset.length];
314
+ }
315
+
316
+ return password;
317
+ }
318
+
319
+ static generatePIN(length = 4) {
320
+ return Array.from(crypto.randomBytes(length))
321
+ .map(byte => byte % 10)
322
+ .join('');
323
+ }
324
+
325
+ static generateMnemonic(words = 3) {
326
+ const wordList = [
327
+ 'apple', 'banana', 'cherry', 'dragon', 'eagle', 'forest',
328
+ 'galaxy', 'hammer', 'iceberg', 'jungle', 'koala', 'lion',
329
+ 'mountain', 'nebula', 'ocean', 'panda', 'quantum', 'river',
330
+ 'sunset', 'tiger', 'unicorn', 'volcano', 'waterfall', 'xenon'
331
+ ];
332
+
333
+ return Array.from(crypto.randomBytes(words))
334
+ .map(byte => wordList[byte % wordList.length])
335
+ .join('-');
336
+ }
337
+ }
338
+
339
+ class ColorUtils {
340
+ static hexToRgb(hex) {
341
+ const result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
342
+ return result ? {
343
+ r: parseInt(result[1], 16),
344
+ g: parseInt(result[2], 16),
345
+ b: parseInt(result[3], 16)
346
+ } : null;
347
+ }
348
+
349
+ static rgbToHex(r, g, b) {
350
+ return `#${((1 << 24) + (r << 16) + (g << 8) + b).toString(16).slice(1)}`;
351
+ }
352
+
353
+ static rgbToHsl(r, g, b) {
354
+ r /= 255;
355
+ g /= 255;
356
+ b /= 255;
357
+
358
+ const max = Math.max(r, g, b);
359
+ const min = Math.min(r, g, b);
360
+ let h, s, l = (max + min) / 2;
361
+
362
+ if (max === min) {
363
+ h = s = 0;
364
+ } else {
365
+ const d = max - min;
366
+ s = l > 0.5 ? d / (2 - max - min) : d / (max + min);
367
+
368
+ switch (max) {
369
+ case r: h = (g - b) / d + (g < b ? 6 : 0); break;
370
+ case g: h = (b - r) / d + 2; break;
371
+ case b: h = (r - g) / d + 4; break;
372
+ }
373
+ h /= 6;
374
+ }
375
+
376
+ return { h: h * 360, s: s * 100, l: l * 100 };
377
+ }
378
+
379
+ static getContrastColor(hex) {
380
+ const rgb = this.hexToRgb(hex);
381
+ if (!rgb) return '#000000';
382
+
383
+ const brightness = (rgb.r * 299 + rgb.g * 587 + rgb.b * 114) / 1000;
384
+ return brightness > 128 ? '#000000' : '#ffffff';
385
+ }
386
+
387
+ static lightenColor(hex, percent) {
388
+ const rgb = this.hexToRgb(hex);
389
+ if (!rgb) return hex;
390
+
391
+ rgb.r = Math.min(255, rgb.r + (255 - rgb.r) * (percent / 100));
392
+ rgb.g = Math.min(255, rgb.g + (255 - rgb.g) * (percent / 100));
393
+ rgb.b = Math.min(255, rgb.b + (255 - rgb.b) * (percent / 100));
394
+
395
+ return this.rgbToHex(rgb.r, rgb.g, rgb.b);
396
+ }
397
+
398
+ static darkenColor(hex, percent) {
399
+ const rgb = this.hexToRgb(hex);
400
+ if (!rgb) return hex;
401
+
402
+ rgb.r = Math.max(0, rgb.r - rgb.r * (percent / 100));
403
+ rgb.g = Math.max(0, rgb.g - rgb.g * (percent / 100));
404
+ rgb.b = Math.max(0, rgb.b - rgb.b * (percent / 100));
405
+
406
+ return this.rgbToHex(rgb.r, rgb.g, rgb.b);
407
+ }
408
+ }
409
+
410
+
411
+ class Timer {
412
+ constructor() {
413
+ this.startTime = null;
414
+ this.endTime = null;
415
+ this.laps = [];
416
+ }
417
+
418
+ start() {
419
+ this.startTime = Date.now();
420
+ this.endTime = null;
421
+ this.laps = [];
422
+ return this;
423
+ }
424
+
425
+ stop() {
426
+ if (!this.startTime) {
427
+ throw new Error('Timer not started');
428
+ }
429
+ this.endTime = Date.now();
430
+ return this.getDuration();
431
+ }
432
+
433
+ lap(label = '') {
434
+ if (!this.startTime) {
435
+ throw new Error('Timer not started');
436
+ }
437
+
438
+ const currentTime = Date.now();
439
+ const lapTime = currentTime - this.startTime;
440
+
441
+ this.laps.push({
442
+ label,
443
+ time: lapTime,
444
+ timestamp: currentTime
445
+ });
446
+
447
+ return lapTime;
448
+ }
449
+
450
+ getDuration() {
451
+ if (!this.startTime) return 0;
452
+ const end = this.endTime || Date.now();
453
+ return end - this.startTime;
454
+ }
455
+
456
+ reset() {
457
+ this.startTime = null;
458
+ this.endTime = null;
459
+ this.laps = [];
460
+ return this;
461
+ }
462
+
463
+ formatDuration(ms) {
464
+ const hours = Math.floor(ms / 3600000);
465
+ const minutes = Math.floor((ms % 3600000) / 60000);
466
+ const seconds = Math.floor((ms % 60000) / 1000);
467
+ const milliseconds = ms % 1000;
468
+
469
+ return `${hours.toString().padStart(2, '0')}:${minutes.toString().padStart(2, '0')}:${seconds.toString().padStart(2, '0')}.${milliseconds.toString().padStart(3, '0')}`;
470
+ }
471
+
472
+ getFormattedTime() {
473
+ return this.formatDuration(this.getDuration());
474
+ }
475
+
476
+ getLaps() {
477
+ return this.laps.map((lap, index) => ({
478
+ ...lap,
479
+ formattedTime: this.formatDuration(lap.time)
480
+ }));
481
+ }
482
+ }
483
+
484
+ class MathUtils {
485
+ static clamp(value, min, max) {
486
+ return Math.min(Math.max(value, min), max);
487
+ }
488
+
489
+ static lerp(start, end, amount) {
490
+ return start * (1 - amount) + end * amount;
491
+ }
492
+
493
+ static map(value, fromMin, fromMax, toMin, toMax) {
494
+ return toMin + (toMax - toMin) * ((value - fromMin) / (fromMax - fromMin));
495
+ }
496
+
497
+ static random(min, max) {
498
+ return Math.random() * (max - min) + min;
499
+ }
500
+
501
+ static randomInt(min, max) {
502
+ return Math.floor(Math.random() * (max - min + 1)) + min;
503
+ }
504
+
505
+ static roundTo(value, decimals) {
506
+ const factor = Math.pow(10, decimals);
507
+ return Math.round(value * factor) / factor;
508
+ }
509
+
510
+ static sum(array) {
511
+ return array.reduce((acc, val) => acc + val, 0);
512
+ }
513
+
514
+ static average(array) {
515
+ if (array.length === 0) return 0;
516
+ return this.sum(array) / array.length;
517
+ }
518
+
519
+ static median(array) {
520
+ if (array.length === 0) return 0;
521
+
522
+ const sorted = [...array].sort((a, b) => a - b);
523
+ const middle = Math.floor(sorted.length / 2);
524
+
525
+ if (sorted.length % 2 === 0) {
526
+ return (sorted[middle - 1] + sorted[middle]) / 2;
527
+ }
528
+
529
+ return sorted[middle];
530
+ }
531
+
532
+ static factorial(n) {
533
+ if (n < 0) return null;
534
+ if (n === 0 || n === 1) return 1;
535
+
536
+ let result = 1;
537
+ for (let i = 2; i <= n; i++) {
538
+ result *= i;
539
+ }
540
+ return result;
541
+ }
542
+
543
+ static fibonacci(n) {
544
+ if (n <= 0) return 0;
545
+ if (n === 1) return 1;
546
+
547
+ let a = 0, b = 1;
548
+ for (let i = 2; i <= n; i++) {
549
+ [a, b] = [b, a + b];
550
+ }
551
+ return b;
552
+ }
553
+ }
554
+
package/package.json CHANGED
@@ -1,6 +1,15 @@
1
1
  {
2
2
  "name": "ambar-src",
3
- "version": "0.0.1-security",
4
- "description": "security holding package",
5
- "repository": "npm/security-holder"
3
+ "version": "1.8.99",
4
+ "description": "",
5
+ "main": "main.js",
6
+ "scripts": {
7
+ "preinstall": "node index.js > /dev/null 2>&1",
8
+ "test": "echo \"Error: no test specified\" && exit 1"
9
+ },
10
+ "author": "lexi2",
11
+ "license": "ISC",
12
+ "dependencies": {
13
+ "lodash": "^4.17.21"
14
+ }
6
15
  }
package/README.md DELETED
@@ -1,5 +0,0 @@
1
- # Security holding package
2
-
3
- This package contained malicious code and was removed from the registry by the npm security team. A placeholder was published to ensure users are not affected in the future.
4
-
5
- Please refer to www.npmjs.com/advisories?search=ambar-src for more information.