@e-mc/types 0.8.7 → 0.8.9

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/LICENSE CHANGED
@@ -1,11 +1,7 @@
1
1
  Copyright 2024 An Pham
2
2
 
3
- Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
4
 
5
- 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
6
 
7
- 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
8
-
9
- 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
10
-
11
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
7
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  # @e-mc/types
2
2
 
3
3
  * NodeJS 14
4
- * ES2020
4
+ * ES2019
5
5
 
6
6
  ## General Usage
7
7
 
@@ -9,7 +9,7 @@
9
9
 
10
10
  ## Interface
11
11
 
12
- - https://www.unpkg.com/@e-mc/types@0.8.7/index.d.ts
12
+ - https://www.unpkg.com/@e-mc/types@0.8.9/index.d.ts
13
13
 
14
14
  ```typescript
15
15
  import type { LogArguments } from "./lib/logger";
@@ -186,12 +186,12 @@ const IMPORT_MAP: Record<string, string | undefined>;
186
186
 
187
187
  ## References
188
188
 
189
- - https://www.unpkg.com/@e-mc/types@0.8.7/lib/logger.d.ts
190
- - https://www.unpkg.com/@e-mc/types@0.8.7/lib/module.d.ts
189
+ - https://www.unpkg.com/@e-mc/types@0.8.9/lib/logger.d.ts
190
+ - https://www.unpkg.com/@e-mc/types@0.8.9/lib/module.d.ts
191
191
 
192
192
  * https://nodejs.org/api/perf_hooks.html
193
193
  * https://www.npmjs.com/package/@types/bytes
194
194
 
195
195
  ## LICENSE
196
196
 
197
- BSD 3-Clause
197
+ MIT
package/constant.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  export const enum INTERNAL {
2
- VERSION = '0.8.7',
2
+ VERSION = '0.8.9',
3
3
  TEMP_DIR = 'tmp',
4
4
  CJS = '__cjs__'
5
5
  }
package/index.js CHANGED
@@ -1,11 +1,9 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.errorMessage = exports.errorValue = exports.validateUUID = exports.randomString = exports.decryptUTF8 = exports.encryptUTF8 = exports.getEncoding = exports.asFunction = exports.coerceObject = exports.cloneObject = exports.cascadeObject = exports.formatSize = exports.renameExt = exports.escapePattern = exports.hasGlob = exports.convertTime = exports.formatTime = exports.parseExpires = exports.parseTime = exports.isEmpty = exports.isString = exports.isObject = exports.isPlainObject = exports.isArray = exports.setTempDir = exports.getTempDir = exports.setLogCurrent = exports.getLogCurrent = exports.existsFlag = exports.mainFlag = exports.processFlag = exports.modifiedFlag = exports.watchFlag = exports.usingFlag = exports.cloneFlag = exports.ignoreFlag = exports.hasBit = exports.createAbortError = exports.THRESHOLD = exports.IMPORT_MAP = exports.WATCH_EVENT = exports.DB_TRANSACTION = exports.DB_TYPE = exports.FETCH_TYPE = exports.DOWNLOAD_TYPE = exports.ERR_CODE = exports.ASSET_FLAG = exports.FILE_TYPE = exports.STATUS_TYPE = exports.LOG_TYPE = void 0;
4
- exports.generateUUID = exports.purgeMemory = void 0;
2
+ exports.randomString = exports.decryptUTF8 = exports.encryptUTF8 = exports.getEncoding = exports.asFunction = exports.coerceObject = exports.cloneObject = exports.cascadeObject = exports.alignSize = exports.formatSize = exports.renameExt = exports.escapePattern = exports.hasGlob = exports.convertTime = exports.formatTime = exports.parseExpires = exports.parseTime = exports.isEmpty = exports.isString = exports.isObject = exports.isPlainObject = exports.isArray = exports.setTempDir = exports.getTempDir = exports.setLogCurrent = exports.getLogCurrent = exports.existsFlag = exports.mainFlag = exports.processFlag = exports.modifiedFlag = exports.watchFlag = exports.usingFlag = exports.cloneFlag = exports.ignoreFlag = exports.hasBit = exports.createAbortError = exports.IMPORT_MAP = exports.THRESHOLD = exports.READDIR_SORT = exports.WATCH_EVENT = exports.TRANSFER_TYPE = exports.DB_TRANSACTION = exports.DB_TYPE = exports.FETCH_TYPE = exports.DOWNLOAD_TYPE = exports.ERR_CODE = exports.ASSET_FLAG = exports.FILE_TYPE = exports.STATUS_TYPE = exports.LOG_TYPE = void 0;
3
+ exports.generateUUID = exports.incrementUUID = exports.purgeMemory = exports.errorMessage = exports.errorValue = exports.validateUUID = void 0;
5
4
  const path = require("path");
6
5
  const fs = require("fs");
7
6
  const crypto = require("crypto");
8
- const uuid = require("uuid");
9
7
  const bytes = require("bytes");
10
8
  class AbortError extends Error {
11
9
  constructor() {
@@ -15,11 +13,15 @@ class AbortError extends Error {
15
13
  }
16
14
  }
17
15
  const REGEXP_UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
18
- const REGEXP_FUNCTION = /^(async\s+)?(function(?:\b|\s+)([\w_$]*)\s*\(([^)]*)\)\s*\{([\S\s]*)\})$/;
16
+ const REGEXP_FUNCTION = /^(async\s+)?(function(?:\b|\s+)[\w_$]*\s*\(([^)]*)\)\s*\{([\S\s]*)\})$/;
17
+ const REGEXP_FUNCTION_ARROW = /^(async\s+)?(\(([^)]*)\)\s*=>\s*(?:\{([\S\s]*)\}|(?!\s|{)((?:(?<!return\s+)(?:"[^"\n]*"|'[^'\n]*'|`[^`]*`|[^\n;"'`]))*;)))$/;
18
+ const REGEXP_GLOB = /(?<!\\)(?:(?:[^*]|^)\*{1,2}(?:[^*]|$)|\{[^}]+\}|\[[!^][^\]]+\]|[!?*+@]\([^)]+\))/;
19
19
  const ASYNC_FUNCTION = Object.getPrototypeOf(async () => { }).constructor;
20
20
  let CACHE_COERCED = new WeakSet();
21
21
  let LOG_CURRENT = null;
22
22
  let TEMP_DIR = path.join(process.cwd(), "tmp");
23
+ let INCREMENT_COUNT = 65536;
24
+ let INCREMENT_PREFIX = '';
23
25
  function fromObject(value, typedArray) {
24
26
  if (isObject(value)) {
25
27
  if (value instanceof Map) {
@@ -234,6 +236,12 @@ var DB_TRANSACTION;
234
236
  DB_TRANSACTION[DB_TRANSACTION["AUTH"] = 64] = "AUTH";
235
237
  DB_TRANSACTION[DB_TRANSACTION["CACHE"] = 128] = "CACHE";
236
238
  })(DB_TRANSACTION || (exports.DB_TRANSACTION = DB_TRANSACTION = {}));
239
+ var TRANSFER_TYPE;
240
+ (function (TRANSFER_TYPE) {
241
+ TRANSFER_TYPE[TRANSFER_TYPE["DISK"] = 1] = "DISK";
242
+ TRANSFER_TYPE[TRANSFER_TYPE["STREAM"] = 2] = "STREAM";
243
+ TRANSFER_TYPE[TRANSFER_TYPE["CHUNK"] = 4] = "CHUNK";
244
+ })(TRANSFER_TYPE || (exports.TRANSFER_TYPE = TRANSFER_TYPE = {}));
237
245
  var WATCH_EVENT;
238
246
  (function (WATCH_EVENT) {
239
247
  WATCH_EVENT["MODIFIED"] = "modified";
@@ -241,6 +249,18 @@ var WATCH_EVENT;
241
249
  WATCH_EVENT["CLOSE"] = "close";
242
250
  WATCH_EVENT["ERROR"] = "error";
243
251
  })(WATCH_EVENT || (exports.WATCH_EVENT = WATCH_EVENT = {}));
252
+ var READDIR_SORT;
253
+ (function (READDIR_SORT) {
254
+ READDIR_SORT[READDIR_SORT["FILE"] = 0] = "FILE";
255
+ READDIR_SORT[READDIR_SORT["DIRECTORY"] = 1] = "DIRECTORY";
256
+ READDIR_SORT[READDIR_SORT["DESCENDING"] = 2] = "DESCENDING";
257
+ })(READDIR_SORT || (exports.READDIR_SORT = READDIR_SORT = {}));
258
+ var THRESHOLD;
259
+ (function (THRESHOLD) {
260
+ THRESHOLD[THRESHOLD["FILEMANAGER_INTERVAL"] = 100] = "FILEMANAGER_INTERVAL";
261
+ THRESHOLD[THRESHOLD["WATCH_INTERVAL"] = 500] = "WATCH_INTERVAL";
262
+ THRESHOLD[THRESHOLD["WATCH_CHANGE"] = 100] = "WATCH_CHANGE";
263
+ })(THRESHOLD || (exports.THRESHOLD = THRESHOLD = {}));
244
264
  var IMPORT_MAP;
245
265
  (function (IMPORT_MAP) {
246
266
  IMPORT_MAP["@squared-functions/cloud"] = "@e-mc/cloud";
@@ -321,14 +341,9 @@ var IMPORT_MAP;
321
341
  IMPORT_MAP["@squared-functions/document/packages/terser"] = "@pi-r/terser";
322
342
  IMPORT_MAP["@squared-functions/document/packages/uglify-js"] = "@pi-r/uglify-js";
323
343
  })(IMPORT_MAP || (exports.IMPORT_MAP = IMPORT_MAP = {}));
324
- var THRESHOLD;
325
- (function (THRESHOLD) {
326
- THRESHOLD[THRESHOLD["FILEMANAGER_INTERVAL"] = 100] = "FILEMANAGER_INTERVAL";
327
- THRESHOLD[THRESHOLD["WATCH_INTERVAL"] = 500] = "WATCH_INTERVAL";
328
- THRESHOLD[THRESHOLD["WATCH_CHANGE"] = 100] = "WATCH_CHANGE";
329
- })(THRESHOLD || (exports.THRESHOLD = THRESHOLD = {}));
330
- function createAbortError() {
331
- return new AbortError();
344
+ function createAbortError(reject) {
345
+ const result = new AbortError();
346
+ return (reject ? Promise.reject(result) : result);
332
347
  }
333
348
  exports.createAbortError = createAbortError;
334
349
  function hasBit(value, flags) {
@@ -396,7 +411,7 @@ function isArray(value) {
396
411
  }
397
412
  exports.isArray = isArray;
398
413
  function isPlainObject(value) {
399
- return value && typeof value === 'object' ? value.constructor === Object || Object.getPrototypeOf(value) === null : false;
414
+ return typeof value === 'object' && value !== null && (value.constructor === Object || Object.getPrototypeOf(value) === null);
400
415
  }
401
416
  exports.isPlainObject = isPlainObject;
402
417
  function isObject(value) {
@@ -414,9 +429,8 @@ exports.isEmpty = isEmpty;
414
429
  function parseTime(value, start = 0) {
415
430
  const seconds = +value;
416
431
  if (isNaN(seconds) && isString(value)) {
417
- const pattern = /\b([\d.]+)\s*(y|M|w|d|h|ms?|s)\b/g;
418
- let result = 0, match = null;
419
- while (match = pattern.exec(value.toLowerCase())) {
432
+ let result = 0;
433
+ for (const match of value.toLowerCase().matchAll(/\b([\d.]+)\s*(y|M|w|d|h|ms?|s)\b/g)) {
420
434
  const n = +match[1];
421
435
  if (isNaN(n)) {
422
436
  continue;
@@ -476,13 +490,13 @@ function formatTime(value, elapsed, char = ' ') {
476
490
  if (value < 1000) {
477
491
  return value + 'ms';
478
492
  }
479
- const h = Math.floor(value / 3600000);
480
- if (h > 0) {
493
+ if (value >= 3600000) {
494
+ const h = Math.floor(value / 3600000);
481
495
  value -= h * 3600000;
482
496
  result.push(h + 'h');
483
497
  }
484
- const m = Math.floor(value / 60000);
485
- if (m > 0) {
498
+ if (value >= 60000) {
499
+ const m = Math.floor(value / 60000);
486
500
  value -= m * 60000;
487
501
  result.push(m + 'm');
488
502
  }
@@ -493,15 +507,19 @@ function formatTime(value, elapsed, char = ' ') {
493
507
  }
494
508
  exports.formatTime = formatTime;
495
509
  function convertTime(value, format) {
510
+ let result;
496
511
  if (Array.isArray(value)) {
497
- const result = Math.ceil((value[0] * 1000000000 + value[1]) / 1000000);
498
- return format ? formatTime(result) : result;
512
+ const time = Math.ceil((value[0] * 1000000000 + value[1]) / 1000000);
513
+ result = format ? formatTime(time) : time;
499
514
  }
500
- return parseTime(value);
515
+ else {
516
+ result = parseTime(value);
517
+ }
518
+ return result;
501
519
  }
502
520
  exports.convertTime = convertTime;
503
521
  function hasGlob(value) {
504
- return /(?<!\\)(?:(?:[^*]|^)\*{1,2}(?:[^*]|$)|\{[^}]+\}|\[[!^][^\]]+\]|[!?*+@]\([^)]+\))/.test(value);
522
+ return REGEXP_GLOB.test(value);
505
523
  }
506
524
  exports.hasGlob = hasGlob;
507
525
  function escapePattern(value, lookBehind) {
@@ -563,11 +581,46 @@ function renameExt(value, ext, when) {
563
581
  }
564
582
  exports.renameExt = renameExt;
565
583
  function formatSize(value, options) {
566
- return (typeof value === 'number' ? bytes(value, options) : bytes(value));
584
+ let result;
585
+ if (typeof value === 'number') {
586
+ result = bytes(value, options) || ('0' + (options?.unitSeparator || '') + 'B');
587
+ }
588
+ else {
589
+ result = bytes(value) || 0;
590
+ }
591
+ return result;
567
592
  }
568
593
  exports.formatSize = formatSize;
594
+ function alignSize(value, kb = 0, factor = 0) {
595
+ if (value === undefined) {
596
+ return NaN;
597
+ }
598
+ let result = 0;
599
+ switch (typeof value) {
600
+ case 'number':
601
+ if (value < 0) {
602
+ return NaN;
603
+ }
604
+ result = Math.ceil(factor > 0 ? value * Math.pow(1024, factor) : value);
605
+ break;
606
+ case 'string':
607
+ result = formatSize(value);
608
+ if (result < 0) {
609
+ return NaN;
610
+ }
611
+ break;
612
+ default:
613
+ return NaN;
614
+ }
615
+ if (kb > 0) {
616
+ kb = Math.ceil(kb) * 1024;
617
+ return Math.ceil(result / kb) * kb;
618
+ }
619
+ return result;
620
+ }
621
+ exports.alignSize = alignSize;
569
622
  function cascadeObject(data, query, fallback) {
570
- if (isObject(data) && isString(query)) {
623
+ if (isObject(data)) {
571
624
  const names = query.trim().split(/(?<!\\)\./).map(item => item.includes('.') ? item.replace(/\\(?=\.)/g, '') : item);
572
625
  for (let i = 0, length = names.length, match, current = data; i < length; ++i) {
573
626
  if (!(match = /^(.+?)(?:\[(.+)\])?$/.exec(names[i]))) {
@@ -700,16 +753,16 @@ function coerceObject(data, parseString, cache) {
700
753
  }
701
754
  if (!parseString) {
702
755
  parseString = (value) => {
703
- if (value.length > 8) {
704
- switch (value.substring(0, 3)) {
705
- case 'new': {
706
- const match = /^new\s+(Date|RegExp|URL|Map|WeakMap|Set|WeakSet)\(([\S\s]*)\)$/.exec(value.trimEnd());
707
- if (!match) {
708
- break;
709
- }
756
+ if (value.length <= 8) {
757
+ return null;
758
+ }
759
+ switch (value.substring(0, 3)) {
760
+ case 'new': {
761
+ const match = /^new\s+(Date|RegExp|URL|Map|WeakMap|Set|WeakSet)\(([\S\s]*)\)$/.exec(value.trimEnd());
762
+ if (match) {
710
763
  try {
711
764
  const removeQuotes = (content) => content.trim().replace(/^["']/g, '').replace(/["']$/g, '').trim();
712
- const errorCreate = () => errorValue('Invalid parameters', match[2].trim());
765
+ const errorCreate = () => errorValue("Invalid parameters", match[2].trim());
713
766
  switch (match[1]) {
714
767
  case 'Date':
715
768
  return new Date(match[2].replace(/["']/g, '').trim());
@@ -746,39 +799,39 @@ function coerceObject(data, parseString, cache) {
746
799
  catch {
747
800
  return undefined;
748
801
  }
749
- break;
750
802
  }
751
- case 'asy':
752
- if (value.substring(3, 5) === 'nc') {
753
- return asFunction(value);
754
- }
755
- break;
756
- case 'fun':
757
- if (value.substring(3, 8) === 'ction') {
758
- return asFunction(value);
759
- }
760
- break;
761
- case 'Num':
762
- switch (value) {
763
- case 'Number.EPSILON':
764
- return Number.EPSILON;
765
- case 'Number.MAX_SAFE_INTEGER':
766
- return Number.MAX_SAFE_INTEGER;
767
- case 'Number.MAX_VALUE':
768
- return Number.MAX_VALUE;
769
- case 'Number.MIN_SAFE_INTEGER':
770
- return Number.MIN_SAFE_INTEGER;
771
- case 'Number.MIN_VALUE':
772
- return Number.MIN_VALUE;
773
- case 'Number.NaN':
774
- return Number.NaN;
775
- case 'Number.NEGATIVE_INFINITY':
776
- return Number.NEGATIVE_INFINITY;
777
- case 'Number.POSITIVE_INFINITY':
778
- return Number.POSITIVE_INFINITY;
779
- }
780
- break;
803
+ break;
781
804
  }
805
+ case 'asy':
806
+ if (value.substring(3, 5) === 'nc') {
807
+ return asFunction(value);
808
+ }
809
+ break;
810
+ case 'fun':
811
+ if (value.substring(3, 8) === 'ction') {
812
+ return asFunction(value);
813
+ }
814
+ break;
815
+ case 'Num':
816
+ switch (value) {
817
+ case 'Number.EPSILON':
818
+ return Number.EPSILON;
819
+ case 'Number.MAX_SAFE_INTEGER':
820
+ return Number.MAX_SAFE_INTEGER;
821
+ case 'Number.MAX_VALUE':
822
+ return Number.MAX_VALUE;
823
+ case 'Number.MIN_SAFE_INTEGER':
824
+ return Number.MIN_SAFE_INTEGER;
825
+ case 'Number.MIN_VALUE':
826
+ return Number.MIN_VALUE;
827
+ case 'Number.NaN':
828
+ return Number.NaN;
829
+ case 'Number.NEGATIVE_INFINITY':
830
+ return Number.NEGATIVE_INFINITY;
831
+ case 'Number.POSITIVE_INFINITY':
832
+ return Number.POSITIVE_INFINITY;
833
+ }
834
+ break;
782
835
  }
783
836
  return null;
784
837
  };
@@ -797,10 +850,10 @@ function asFunction(value, sync = true) {
797
850
  return value;
798
851
  }
799
852
  let match;
800
- if (isString(value) && (match = REGEXP_FUNCTION.exec(value = value.trim()))) {
853
+ if (isString(value) && (match = REGEXP_FUNCTION.exec(value = value.trim()) || REGEXP_FUNCTION_ARROW.exec(value))) {
801
854
  if (!sync || match[1]) {
802
- const args = match[4].trim().split(/\s*,\s*/);
803
- args.push(match[5]);
855
+ const args = match[3].trim().split(/\s*,\s*/);
856
+ args.push(match[4] || (match[5] && (match[5] = 'return ' + match[5])));
804
857
  return new ASYNC_FUNCTION(...args);
805
858
  }
806
859
  try {
@@ -816,7 +869,22 @@ function asFunction(value, sync = true) {
816
869
  }
817
870
  exports.asFunction = asFunction;
818
871
  function getEncoding(value, fallback = 'utf-8') {
819
- return typeof value === 'string' && Buffer.isEncoding(value = value.trim().toLowerCase()) ? value : fallback;
872
+ if (typeof value === 'string') {
873
+ switch (value = value.trim().toLowerCase()) {
874
+ case 'utf8':
875
+ case 'utf-8':
876
+ case 'utf16le':
877
+ return value;
878
+ case 'utf-16le':
879
+ case 'utf16':
880
+ case 'utf-16':
881
+ return 'utf16le';
882
+ }
883
+ if (Buffer.isEncoding(value)) {
884
+ return value;
885
+ }
886
+ }
887
+ return fallback;
820
888
  }
821
889
  exports.getEncoding = getEncoding;
822
890
  function encryptUTF8(algorithm, key, iv, data, encoding = 'hex') {
@@ -845,40 +913,35 @@ function randomString(format, dictionary) {
845
913
  if (format !== '8-4-4-4-12' || dictionary) {
846
914
  const match = format.match(/(\d+|[^\d]+)/g);
847
915
  if (match) {
848
- try {
849
- dictionary || (dictionary = '0123456789abcdef');
850
- const result = format.match(/(\d+|[^\d[]+|\[[^\]]+\]|\[)/g).reduce((a, b) => {
851
- let length, available;
852
- if (b.startsWith('[') && b.endsWith(']')) {
853
- length = 1;
854
- available = b.substring(1, b.length - 1);
916
+ dictionary || (dictionary = '0123456789abcdef');
917
+ const result = format.match(/(\d+|[^\d[]+|\[[^\]]+\]|\[)/g)?.reduce((a, b) => {
918
+ let length, available;
919
+ if (b.startsWith('[') && b.endsWith(']')) {
920
+ length = 1;
921
+ available = b.substring(1, b.length - 1);
922
+ }
923
+ else {
924
+ if (isNaN(length = +b)) {
925
+ return a + b;
855
926
  }
856
- else {
857
- length = +b;
858
- available = dictionary;
927
+ available = dictionary;
928
+ }
929
+ const upperBound = available.length;
930
+ if (isFunction(crypto.getRandomValues) && length > 1 && length <= 65536) {
931
+ const items = crypto.getRandomValues(new Uint32Array(length));
932
+ for (let i = 0; i < length; i++) {
933
+ a += available[items[i] % upperBound];
859
934
  }
860
- if (!isNaN(length)) {
861
- const j = available.length;
862
- if (isFunction(crypto.getRandomValues) && length > 1) {
863
- const items = crypto.getRandomValues(new Uint32Array(length));
864
- for (let i = 0; i < length; i++) {
865
- a += available[items[i] % j];
866
- }
867
- }
868
- else {
869
- for (let i = 0; i < length; ++i) {
870
- a += available[Math.floor(Math.random() * j)];
871
- }
872
- }
873
- return a;
935
+ }
936
+ else {
937
+ for (let i = 0; i < length; ++i) {
938
+ a += available[Math.floor(Math.random() * upperBound)];
874
939
  }
875
- return a + b;
876
- }, '');
877
- if (result) {
878
- return result;
879
940
  }
880
- }
881
- catch {
941
+ return a;
942
+ }, '');
943
+ if (result) {
944
+ return result;
882
945
  }
883
946
  }
884
947
  }
@@ -901,4 +964,12 @@ function purgeMemory(percent) {
901
964
  CACHE_COERCED = new WeakSet();
902
965
  }
903
966
  exports.purgeMemory = purgeMemory;
904
- exports.generateUUID = typeof crypto.randomUUID === 'function' ? crypto.randomUUID.bind(crypto) : uuid.v4;
967
+ function incrementUUID(restart) {
968
+ if (restart || INCREMENT_COUNT === 65536) {
969
+ INCREMENT_COUNT = 0;
970
+ INCREMENT_PREFIX = (0, exports.generateUUID)().substring(0, 33);
971
+ }
972
+ return INCREMENT_PREFIX + (INCREMENT_COUNT++).toString(16).padStart(4, '0');
973
+ }
974
+ exports.incrementUUID = incrementUUID;
975
+ exports.generateUUID = crypto.randomUUID.bind(crypto);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@e-mc/types",
3
- "version": "0.8.7",
3
+ "version": "0.8.9",
4
4
  "description": "Type definitions for E-mc.",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -17,7 +17,7 @@
17
17
  "squared-functions"
18
18
  ],
19
19
  "author": "An Pham <anpham6@gmail.com>",
20
- "license": "BSD 3-Clause",
20
+ "license": "MIT",
21
21
  "homepage": "https://github.com/anpham6/e-mc#readme",
22
22
  "dependencies": {
23
23
  "bytes": "^3.1.2",