@encodeagent/platform-helper-util 1.2603.1221241 → 1.2603.1311450
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 +277 -153
- package/dist/api.d.ts +38 -0
- package/dist/api.d.ts.map +1 -1
- package/dist/api.js +38 -2
- package/dist/api.js.map +1 -1
- package/dist/auth.d.ts +93 -0
- package/dist/auth.d.ts.map +1 -1
- package/dist/auth.js +93 -2
- package/dist/auth.js.map +1 -1
- package/dist/colors.d.ts +41 -0
- package/dist/colors.d.ts.map +1 -1
- package/dist/colors.js +41 -0
- package/dist/colors.js.map +1 -1
- package/dist/core.d.ts +262 -0
- package/dist/core.d.ts.map +1 -1
- package/dist/core.js +264 -2
- package/dist/core.js.map +1 -1
- package/dist/cost.d.ts +26 -0
- package/dist/cost.d.ts.map +1 -1
- package/dist/cost.js +27 -1
- package/dist/cost.js.map +1 -1
- package/dist/file.d.ts +38 -0
- package/dist/file.d.ts.map +1 -1
- package/dist/file.js +42 -2
- package/dist/file.js.map +1 -1
- package/dist/html.d.ts +83 -0
- package/dist/html.d.ts.map +1 -1
- package/dist/html.js +88 -35
- package/dist/html.js.map +1 -1
- package/dist/logger.d.ts +17 -0
- package/dist/logger.d.ts.map +1 -1
- package/dist/logger.js +28 -2
- package/dist/logger.js.map +1 -1
- package/dist/markdown.d.ts +20 -0
- package/dist/markdown.d.ts.map +1 -1
- package/dist/markdown.js +20 -0
- package/dist/markdown.js.map +1 -1
- package/dist/metadata.js +1 -1
- package/dist/metadata.js.map +1 -1
- package/dist/record.d.ts +137 -5
- package/dist/record.d.ts.map +1 -1
- package/dist/record.js +184 -19
- package/dist/record.js.map +1 -1
- package/dist/shortid.d.ts +21 -8
- package/dist/shortid.d.ts.map +1 -1
- package/dist/shortid.js +9 -5
- package/dist/shortid.js.map +1 -1
- package/dist/slug.d.ts +10 -0
- package/dist/slug.d.ts.map +1 -1
- package/dist/slug.js +10 -0
- package/dist/slug.js.map +1 -1
- package/dist/token.d.ts +1 -1
- package/dist/tree.d.ts +43 -0
- package/dist/tree.d.ts.map +1 -1
- package/dist/tree.js +43 -5
- package/dist/tree.js.map +1 -1
- package/dist/value-of-object.d.ts +41 -0
- package/dist/value-of-object.d.ts.map +1 -1
- package/dist/value-of-object.js +59 -17
- package/dist/value-of-object.js.map +1 -1
- package/dist/web-content.d.ts +52 -0
- package/dist/web-content.d.ts.map +1 -1
- package/dist/web-content.js +52 -0
- package/dist/web-content.js.map +1 -1
- package/dist/web.d.ts +51 -0
- package/dist/web.d.ts.map +1 -1
- package/dist/web.js +54 -1
- package/dist/web.js.map +1 -1
- package/package.json +20 -15
package/dist/core.js
CHANGED
|
@@ -484,6 +484,13 @@ const ttl = (mins = 60) => {
|
|
|
484
484
|
return (0, exports.unixTimestamp)() + mins * 60;
|
|
485
485
|
};
|
|
486
486
|
exports.ttl = ttl;
|
|
487
|
+
/**
|
|
488
|
+
* Evaluates a JS expression string against `props` using the caller-supplied
|
|
489
|
+
* `props.jsEvalFunction` compiler. Returns true when the expression or the
|
|
490
|
+
* function it produces is truthy.
|
|
491
|
+
* @param js - JavaScript expression string to evaluate
|
|
492
|
+
* @param props - Context object; must provide `jsEvalFunction(js)` to compile `js`
|
|
493
|
+
*/
|
|
487
494
|
const checkToTrue = (js, props) => {
|
|
488
495
|
if (!(0, lodash_1.isObject)(props))
|
|
489
496
|
props = {};
|
|
@@ -506,6 +513,12 @@ const checkToTrue = (js, props) => {
|
|
|
506
513
|
return false;
|
|
507
514
|
};
|
|
508
515
|
exports.checkToTrue = checkToTrue;
|
|
516
|
+
/**
|
|
517
|
+
* Validates whether a string is a correctly formatted email address.
|
|
518
|
+
* Leading/trailing whitespace and `+` characters are stripped before matching.
|
|
519
|
+
* @param s - Value to validate
|
|
520
|
+
* @param allowNilEmpty - When true, null/empty values are considered valid
|
|
521
|
+
*/
|
|
509
522
|
const isEmail = (s, allowNilEmpty) => {
|
|
510
523
|
if (allowNilEmpty && !(0, exports.isNonEmptyString)(s))
|
|
511
524
|
return true;
|
|
@@ -518,6 +531,13 @@ const isEmail = (s, allowNilEmpty) => {
|
|
|
518
531
|
return pattern.test(email);
|
|
519
532
|
};
|
|
520
533
|
exports.isEmail = isEmail;
|
|
534
|
+
/**
|
|
535
|
+
* Validates a password against configurable complexity rules. Defaults are
|
|
536
|
+
* sourced from `DEFAULT_PASSWORD_RULE` and can be overridden via `settings`.
|
|
537
|
+
* @param s - Password string to validate
|
|
538
|
+
* @param settings - Complexity overrides (minLen, needDigit, needUpperCaseLetter, etc.)
|
|
539
|
+
* @returns true when all active rules pass
|
|
540
|
+
*/
|
|
521
541
|
const isPassword = (s, settings) => {
|
|
522
542
|
if (!(0, lodash_1.isObject)(settings))
|
|
523
543
|
settings = {};
|
|
@@ -560,14 +580,29 @@ const isPassword = (s, settings) => {
|
|
|
560
580
|
return result;
|
|
561
581
|
};
|
|
562
582
|
exports.isPassword = isPassword;
|
|
583
|
+
/**
|
|
584
|
+
* Returns a Unix-epoch millisecond timestamp.
|
|
585
|
+
* Uses the provided date when given, otherwise returns the current time.
|
|
586
|
+
* @param dt - Optional date to convert (defaults to `new Date()`)
|
|
587
|
+
*/
|
|
563
588
|
const getTimestamp = (dt) => {
|
|
564
589
|
return dt ? new Date(dt).getTime() : new Date().getTime();
|
|
565
590
|
};
|
|
566
591
|
exports.getTimestamp = getTimestamp;
|
|
592
|
+
/**
|
|
593
|
+
* Returns the maximum representable UTC timestamp in milliseconds (year 9999).
|
|
594
|
+
* Useful as a sentinel "no expiry" value in date-range queries.
|
|
595
|
+
*/
|
|
567
596
|
const getMaxTimestamp = () => {
|
|
568
597
|
return new Date("9999-12-31T23:59:59.999Z").getTime();
|
|
569
598
|
};
|
|
570
599
|
exports.getMaxTimestamp = getMaxTimestamp;
|
|
600
|
+
/**
|
|
601
|
+
* Returns an ISO 8601 UTC string for a given date, optionally shifted by `minutesDiff` minutes.
|
|
602
|
+
* Defaults to the current time when `dt` is omitted.
|
|
603
|
+
* @param dt - Base date (defaults to `new Date()`)
|
|
604
|
+
* @param minutesDiff - Minutes to add or subtract from the base date
|
|
605
|
+
*/
|
|
571
606
|
const getUTCISOString = (dt, minutesDiff) => {
|
|
572
607
|
if (!dt)
|
|
573
608
|
dt = new Date();
|
|
@@ -578,10 +613,20 @@ const getUTCISOString = (dt, minutesDiff) => {
|
|
|
578
613
|
return dt.toISOString();
|
|
579
614
|
};
|
|
580
615
|
exports.getUTCISOString = getUTCISOString;
|
|
616
|
+
/**
|
|
617
|
+
* Returns the maximum representable UTC datetime as an ISO 8601 string ("9999-12-31T23:59:59.999Z").
|
|
618
|
+
* Use as a "no expiry" sentinel in time-bounded queries.
|
|
619
|
+
*/
|
|
581
620
|
const getUTCMaxISOString = () => {
|
|
582
621
|
return (0, exports.getUTCISOString)(new Date("9999-12-31T23:59:59.999Z"), 0);
|
|
583
622
|
};
|
|
584
623
|
exports.getUTCMaxISOString = getUTCMaxISOString;
|
|
624
|
+
/**
|
|
625
|
+
* Simple positional string formatter. The first argument is the template; each
|
|
626
|
+
* subsequent argument replaces the next `{0}` placeholder in the template.
|
|
627
|
+
* Returns `null` when no arguments are provided.
|
|
628
|
+
* @example formatString('Hello {0}!', 'World') // 'Hello World!'
|
|
629
|
+
*/
|
|
585
630
|
const formatString = (...args) => {
|
|
586
631
|
if (args.length == 0)
|
|
587
632
|
return null;
|
|
@@ -592,16 +637,29 @@ const formatString = (...args) => {
|
|
|
592
637
|
return s;
|
|
593
638
|
};
|
|
594
639
|
exports.formatString = formatString;
|
|
640
|
+
/**
|
|
641
|
+
* Truncates `s` to `l` characters, appending ` ...` when the string exceeds the limit.
|
|
642
|
+
* Returns `s` unchanged when it is already within the limit.
|
|
643
|
+
*/
|
|
595
644
|
const shortenString = (s, l) => {
|
|
596
645
|
return s.length <= l ? s : `${s.substring(0, l)} ...`;
|
|
597
646
|
};
|
|
598
647
|
exports.shortenString = shortenString;
|
|
599
|
-
//
|
|
600
|
-
//this
|
|
648
|
+
// TypeScript-safe wrapper — lodash's isObject causes TS type-narrowing errors
|
|
649
|
+
// when the result is used as a boolean; this wrapper avoids that by always returning boolean.
|
|
650
|
+
/**
|
|
651
|
+
* Returns `true` when `v` is any non-primitive value (object, array, function).
|
|
652
|
+
* Wraps lodash `isObject` in a way that avoids TypeScript type-narrowing issues.
|
|
653
|
+
*/
|
|
601
654
|
const isObject = (v) => {
|
|
602
655
|
return (0, lodash_1.isObject)(v) ? true : false;
|
|
603
656
|
};
|
|
604
657
|
exports.isObject = isObject;
|
|
658
|
+
/**
|
|
659
|
+
* Returns `true` when `s` is a valid JSON string that parses without error.
|
|
660
|
+
* Note: this accepts any valid JSON value (string, number, array, object).
|
|
661
|
+
* Use `isGoodJSON` for a nil-safe alternative.
|
|
662
|
+
*/
|
|
605
663
|
const isObjectString = (s) => {
|
|
606
664
|
try {
|
|
607
665
|
JSON.parse(s);
|
|
@@ -612,6 +670,13 @@ const isObjectString = (s) => {
|
|
|
612
670
|
}
|
|
613
671
|
};
|
|
614
672
|
exports.isObjectString = isObjectString;
|
|
673
|
+
/**
|
|
674
|
+
* Recursively removes properties with `null` or `undefined` values from an object or array.
|
|
675
|
+
* When `removeEmptyString` is true, empty string values are also removed.
|
|
676
|
+
* Mutates the input object/array in place and also returns it.
|
|
677
|
+
* @param data - Object or array to clean
|
|
678
|
+
* @param removeEmptyString - Whether to remove `""` values in addition to null/undefined
|
|
679
|
+
*/
|
|
615
680
|
const removeNoValueProperty = (data, removeEmptyString) => {
|
|
616
681
|
if ((0, lodash_1.isArray)(data)) {
|
|
617
682
|
return (0, lodash_1.without)((0, lodash_1.map)(data, (r) => {
|
|
@@ -651,6 +716,16 @@ const removeNoValueProperty = (data, removeEmptyString) => {
|
|
|
651
716
|
return data;
|
|
652
717
|
};
|
|
653
718
|
exports.removeNoValueProperty = removeNoValueProperty;
|
|
719
|
+
/**
|
|
720
|
+
* Groups an array of items under their corresponding group definitions.
|
|
721
|
+
* Each group in the result gains a `data` property containing its items,
|
|
722
|
+
* sorted by `propNameForItemSort` (default: `"fullName"`).
|
|
723
|
+
* Items whose group property does not match any group are omitted.
|
|
724
|
+
* @param data - Flat list of items to group
|
|
725
|
+
* @param groups - Group definitions (each must have an `id` field)
|
|
726
|
+
* @param propNameForItemGroup - Property on each item that identifies its group id (default: `"group"`)
|
|
727
|
+
* @param propNameForItemSort - Property used to sort items within each group (default: `"fullName"`)
|
|
728
|
+
*/
|
|
654
729
|
const groupItems = (data, groups, propNameForItemGroup, propNameForItemSort) => {
|
|
655
730
|
if (!((0, lodash_1.isArray)(data) && data.length > 0))
|
|
656
731
|
return [];
|
|
@@ -676,6 +751,12 @@ const groupItems = (data, groups, propNameForItemGroup, propNameForItemSort) =>
|
|
|
676
751
|
return result;
|
|
677
752
|
};
|
|
678
753
|
exports.groupItems = groupItems;
|
|
754
|
+
/**
|
|
755
|
+
* Formats a large number with a compact suffix (K, M, B, T, P, E).
|
|
756
|
+
* @param num - Number to format
|
|
757
|
+
* @param fractionDigits - Decimal places to show (default: 1, clamped to ≥ 0)
|
|
758
|
+
* @example shortenNumber(1500) // '1.5K'
|
|
759
|
+
*/
|
|
679
760
|
const shortenNumber = (num, fractionDigits) => {
|
|
680
761
|
if (!(0, lodash_1.isNumber)(fractionDigits) ||
|
|
681
762
|
((0, lodash_1.isNumber)(fractionDigits) && fractionDigits < 0))
|
|
@@ -701,6 +782,13 @@ const shortenNumber = (num, fractionDigits) => {
|
|
|
701
782
|
: "0";
|
|
702
783
|
};
|
|
703
784
|
exports.shortenNumber = shortenNumber;
|
|
785
|
+
/**
|
|
786
|
+
* Collection of `Intl.NumberFormat`-based formatting functions for the US locale.
|
|
787
|
+
* - `number` — decimal number with optional compact notation
|
|
788
|
+
* - `currency` — monetary value with currency symbol (default USD)
|
|
789
|
+
* - `unit` — plain decimal (no currency/percent)
|
|
790
|
+
* - `percentage` — percent with sign prefix for positive values
|
|
791
|
+
*/
|
|
704
792
|
exports.formatters = {
|
|
705
793
|
number: ({ number, minFractionDigits = 0, maxFractionDigits = 2, compact = false }) => new Intl.NumberFormat("en-US", {
|
|
706
794
|
minimumFractionDigits: minFractionDigits,
|
|
@@ -730,6 +818,14 @@ exports.formatters = {
|
|
|
730
818
|
return `${symbol}${formattedNumber}`;
|
|
731
819
|
}
|
|
732
820
|
};
|
|
821
|
+
/**
|
|
822
|
+
* Transforms `text` according to the chosen `format` mode:
|
|
823
|
+
* - `"lower"` / `"upper"` — case conversion
|
|
824
|
+
* - `"capital"` / `"capital-first"` — capitalises the first word
|
|
825
|
+
* - `"capital-all"` — capitalises every word
|
|
826
|
+
* - `"camel"` — converts to camelCase
|
|
827
|
+
* - `"initials"` — first character of each space-separated word
|
|
828
|
+
*/
|
|
733
829
|
const formatText = (text, format) => {
|
|
734
830
|
switch (format) {
|
|
735
831
|
case "lower":
|
|
@@ -750,6 +846,10 @@ const formatText = (text, format) => {
|
|
|
750
846
|
}
|
|
751
847
|
};
|
|
752
848
|
exports.formatText = formatText;
|
|
849
|
+
/**
|
|
850
|
+
* Converts a raw byte count into a human-readable size string (e.g. "1.5 MB").
|
|
851
|
+
* Returns an empty string when the input is not a number.
|
|
852
|
+
*/
|
|
753
853
|
const readableFileSize = (fileSizeInBytes) => {
|
|
754
854
|
if (!(0, lodash_1.isNumber)(fileSizeInBytes))
|
|
755
855
|
return "";
|
|
@@ -762,6 +862,11 @@ const readableFileSize = (fileSizeInBytes) => {
|
|
|
762
862
|
return Math.max(fileSizeInBytes, 0.1).toFixed(1) + byteUnits[i];
|
|
763
863
|
};
|
|
764
864
|
exports.readableFileSize = readableFileSize;
|
|
865
|
+
/**
|
|
866
|
+
* Pretty-prints a JSON string with 4-space indentation.
|
|
867
|
+
* Parses the input first; if the parse produces a non-serialisable value,
|
|
868
|
+
* falls back to compact `JSON.stringify`.
|
|
869
|
+
*/
|
|
765
870
|
const formatJSONString = (c) => {
|
|
766
871
|
const jsonValue = (0, exports.isNonEmptyString)(c) ? JSON.parse(c) : c;
|
|
767
872
|
try {
|
|
@@ -773,6 +878,11 @@ const formatJSONString = (c) => {
|
|
|
773
878
|
return JSON.stringify(jsonValue);
|
|
774
879
|
};
|
|
775
880
|
exports.formatJSONString = formatJSONString;
|
|
881
|
+
/**
|
|
882
|
+
* Recursively flattens a deeply nested array into a single flat array.
|
|
883
|
+
* @param array - Potentially nested array to flatten
|
|
884
|
+
* @example deepFlatten([1, [2, [3, [4]]]]) // [1, 2, 3, 4]
|
|
885
|
+
*/
|
|
776
886
|
const deepFlatten = (array) => {
|
|
777
887
|
let result = [];
|
|
778
888
|
array.forEach(function (elem) {
|
|
@@ -786,6 +896,12 @@ const deepFlatten = (array) => {
|
|
|
786
896
|
return result;
|
|
787
897
|
};
|
|
788
898
|
exports.deepFlatten = deepFlatten;
|
|
899
|
+
/**
|
|
900
|
+
* Looks up a country by its ISO 2-letter code, ISO 3-letter code, or full name (case-insensitive).
|
|
901
|
+
* Returns `undefined` when no match is found.
|
|
902
|
+
* @param codeOrName - ISO alpha-2/3 code or country name to search for
|
|
903
|
+
* @param resultFormat - `"PicklistOption"` returns `{ text, value }` for UI dropdowns; default returns the raw country object
|
|
904
|
+
*/
|
|
789
905
|
const findCountry = (codeOrName, resultFormat) => {
|
|
790
906
|
const country = (0, lodash_1.find)(constants_1.COUNTRIES, (c) => {
|
|
791
907
|
return (c.name.toLocaleLowerCase() == codeOrName.toLowerCase() ||
|
|
@@ -807,6 +923,11 @@ const findCountry = (codeOrName, resultFormat) => {
|
|
|
807
923
|
}
|
|
808
924
|
};
|
|
809
925
|
exports.findCountry = findCountry;
|
|
926
|
+
/**
|
|
927
|
+
* Looks up a gender entry by its display text or value (case-insensitive).
|
|
928
|
+
* Returns `undefined` when no match is found.
|
|
929
|
+
* @param textOrValue - Gender text label or value to search for
|
|
930
|
+
*/
|
|
810
931
|
const findGender = (textOrValue) => {
|
|
811
932
|
return (0, lodash_1.find)(constants_1.GENDERS, (c) => {
|
|
812
933
|
return (c.text.toLowerCase() == textOrValue.toLowerCase() ||
|
|
@@ -814,6 +935,12 @@ const findGender = (textOrValue) => {
|
|
|
814
935
|
});
|
|
815
936
|
};
|
|
816
937
|
exports.findGender = findGender;
|
|
938
|
+
/**
|
|
939
|
+
* Looks up a language by its ISO code or name (case-insensitive, comma-separated names supported).
|
|
940
|
+
* Returns `undefined` when no match is found.
|
|
941
|
+
* @param codeOrName - Language ISO code or name to search for
|
|
942
|
+
* @param resultFormat - `"PicklistOption"` returns `{ text, value }` for UI dropdowns; default returns the raw language object
|
|
943
|
+
*/
|
|
817
944
|
const findLanguage = (codeOrName, resultFormat) => {
|
|
818
945
|
const language = (0, lodash_1.find)(constants_1.LANGUAGES, (c) => {
|
|
819
946
|
let found = c.name.toLowerCase() == codeOrName.trim().toLowerCase() ||
|
|
@@ -844,6 +971,13 @@ const findLanguage = (codeOrName, resultFormat) => {
|
|
|
844
971
|
}
|
|
845
972
|
};
|
|
846
973
|
exports.findLanguage = findLanguage;
|
|
974
|
+
/**
|
|
975
|
+
* Retrieves a value from the in-memory global cache.
|
|
976
|
+
* Returns `defaultValue` when the key is absent. When a TTL was set during
|
|
977
|
+
* `setCache`, expired entries are evicted before the value is returned.
|
|
978
|
+
* @param key - Cache key to look up
|
|
979
|
+
* @param defaultValue - Fallback value when the key is missing or expired
|
|
980
|
+
*/
|
|
847
981
|
const getCache = (key, defaultValue) => {
|
|
848
982
|
if (!(0, exports.isNonEmptyString)(key))
|
|
849
983
|
return undefined;
|
|
@@ -865,6 +999,13 @@ const getCache = (key, defaultValue) => {
|
|
|
865
999
|
: undefined;
|
|
866
1000
|
};
|
|
867
1001
|
exports.getCache = getCache;
|
|
1002
|
+
/**
|
|
1003
|
+
* Stores a value in the in-memory global cache.
|
|
1004
|
+
* Passing `null` or `undefined` as `data` removes the key (delegates to `removeCache`).
|
|
1005
|
+
* @param key - Cache key
|
|
1006
|
+
* @param data - Value to store; null/undefined removes the entry
|
|
1007
|
+
* @param expireMinutes - Optional TTL in minutes; omit for no expiry
|
|
1008
|
+
*/
|
|
868
1009
|
const setCache = (key, data, expireMinutes) => {
|
|
869
1010
|
const g = (0, exports.getGlobalObject)();
|
|
870
1011
|
if (!(0, exports.isNonEmptyString)(key))
|
|
@@ -886,6 +1027,10 @@ const setCache = (key, data, expireMinutes) => {
|
|
|
886
1027
|
}
|
|
887
1028
|
};
|
|
888
1029
|
exports.setCache = setCache;
|
|
1030
|
+
/**
|
|
1031
|
+
* Removes a single entry from the in-memory global cache.
|
|
1032
|
+
* No-ops when the key does not exist.
|
|
1033
|
+
*/
|
|
889
1034
|
const removeCache = (key) => {
|
|
890
1035
|
const g = (0, exports.getGlobalObject)();
|
|
891
1036
|
if (!(0, exports.isObject)(g.localCache))
|
|
@@ -893,27 +1038,46 @@ const removeCache = (key) => {
|
|
|
893
1038
|
delete g.localCache[key];
|
|
894
1039
|
};
|
|
895
1040
|
exports.removeCache = removeCache;
|
|
1041
|
+
/**
|
|
1042
|
+
* Removes the entire group cache entry for `groupId`, clearing all sub-keys stored under it.
|
|
1043
|
+
*/
|
|
896
1044
|
const resetCacheByGroupId = (groupId) => {
|
|
897
1045
|
(0, exports.removeCache)(groupId);
|
|
898
1046
|
};
|
|
899
1047
|
exports.resetCacheByGroupId = resetCacheByGroupId;
|
|
1048
|
+
/**
|
|
1049
|
+
* Stores a `key → value` pair inside the group cache identified by `groupId`.
|
|
1050
|
+
* The group itself is stored as a single cache entry (an object of sub-keys).
|
|
1051
|
+
*/
|
|
900
1052
|
const setCacheByGroupId = (groupId, key, value) => {
|
|
901
1053
|
const groupCache = (0, exports.getCache)(groupId) ?? {};
|
|
902
1054
|
groupCache[key] = value;
|
|
903
1055
|
(0, exports.setCache)(groupId, groupCache);
|
|
904
1056
|
};
|
|
905
1057
|
exports.setCacheByGroupId = setCacheByGroupId;
|
|
1058
|
+
/**
|
|
1059
|
+
* Retrieves a `key` from within the group cache identified by `groupId`.
|
|
1060
|
+
* Returns `undefined` when the group or key does not exist.
|
|
1061
|
+
*/
|
|
906
1062
|
const getCacheByGroupId = (groupId, key) => {
|
|
907
1063
|
const groupCache = (0, exports.getCache)(groupId) ?? {};
|
|
908
1064
|
return groupCache[key];
|
|
909
1065
|
};
|
|
910
1066
|
exports.getCacheByGroupId = getCacheByGroupId;
|
|
1067
|
+
/**
|
|
1068
|
+
* Removes a single `key` from within the group cache identified by `groupId`.
|
|
1069
|
+
* The group entry itself remains; only the specified sub-key is deleted.
|
|
1070
|
+
*/
|
|
911
1071
|
const removeCacheByGroupId = (groupId, key) => {
|
|
912
1072
|
const groupCache = (0, exports.getCache)(groupId) ?? {};
|
|
913
1073
|
delete groupCache[key];
|
|
914
1074
|
(0, exports.setCache)(groupId, groupCache);
|
|
915
1075
|
};
|
|
916
1076
|
exports.removeCacheByGroupId = removeCacheByGroupId;
|
|
1077
|
+
/**
|
|
1078
|
+
* Normalises a GUID string by removing curly braces, converting underscores to hyphens,
|
|
1079
|
+
* trimming whitespace, and lowercasing. Returns `""` for falsy input.
|
|
1080
|
+
*/
|
|
917
1081
|
const cleanGuid = (v) => {
|
|
918
1082
|
return !v
|
|
919
1083
|
? ""
|
|
@@ -925,14 +1089,28 @@ const cleanGuid = (v) => {
|
|
|
925
1089
|
.toLowerCase();
|
|
926
1090
|
};
|
|
927
1091
|
exports.cleanGuid = cleanGuid;
|
|
1092
|
+
/**
|
|
1093
|
+
* Returns `true` when two GUID strings represent the same identifier after normalisation.
|
|
1094
|
+
* Comparison is case- and formatting-insensitive (braces, underscores, casing all ignored).
|
|
1095
|
+
*/
|
|
928
1096
|
const sameGuid = (a, b) => {
|
|
929
1097
|
return (0, exports.cleanGuid)(a) === (0, exports.cleanGuid)(b);
|
|
930
1098
|
};
|
|
931
1099
|
exports.sameGuid = sameGuid;
|
|
1100
|
+
/**
|
|
1101
|
+
* Returns `true` when `v` equals the all-zeros empty GUID (`00000000-0000-0000-0000-000000000000`).
|
|
1102
|
+
*/
|
|
932
1103
|
const isEmptyGuid = (v) => {
|
|
933
1104
|
return (0, exports.sameGuid)(v, constants_1.GUID_EMPTY);
|
|
934
1105
|
};
|
|
935
1106
|
exports.isEmptyGuid = isEmptyGuid;
|
|
1107
|
+
/**
|
|
1108
|
+
* Converts a TypeScript numeric enum into an array of `{ key, value }` pairs.
|
|
1109
|
+
* TypeScript numeric enums produce double-keyed entries (name ↔ number);
|
|
1110
|
+
* this function returns only the name → value direction.
|
|
1111
|
+
* @param thisEnum - A TypeScript enum object (must be a numeric enum)
|
|
1112
|
+
* @example convertEnumToArray(Direction) // [{ key: 'Up', value: 0 }, ...]
|
|
1113
|
+
*/
|
|
936
1114
|
const convertEnumToArray = (thisEnum) => {
|
|
937
1115
|
let result = [];
|
|
938
1116
|
let i = Object.keys(thisEnum).length / 2;
|
|
@@ -944,6 +1122,11 @@ const convertEnumToArray = (thisEnum) => {
|
|
|
944
1122
|
return result;
|
|
945
1123
|
};
|
|
946
1124
|
exports.convertEnumToArray = convertEnumToArray;
|
|
1125
|
+
/**
|
|
1126
|
+
* Returns `true` when `s` can be parsed as a finite number (integer or float).
|
|
1127
|
+
* Uses type coercion to reject strings with non-numeric trailing characters.
|
|
1128
|
+
* @param allowNilEmpty - When true, null/empty values are treated as valid
|
|
1129
|
+
*/
|
|
947
1130
|
const isNumberString = (s, allowNilEmpty) => {
|
|
948
1131
|
if (allowNilEmpty && !(0, exports.isNonEmptyString)(s))
|
|
949
1132
|
return true;
|
|
@@ -953,6 +1136,10 @@ const isNumberString = (s, allowNilEmpty) => {
|
|
|
953
1136
|
);
|
|
954
1137
|
};
|
|
955
1138
|
exports.isNumberString = isNumberString;
|
|
1139
|
+
/**
|
|
1140
|
+
* Returns `true` when `s` is exactly `"true"` or `"false"` (case-insensitive).
|
|
1141
|
+
* @param allowNilEmpty - When true, null/empty values are treated as valid
|
|
1142
|
+
*/
|
|
956
1143
|
const isBooleanString = (s, allowNilEmpty) => {
|
|
957
1144
|
if (allowNilEmpty && !(0, exports.isNonEmptyString)(s))
|
|
958
1145
|
return true;
|
|
@@ -960,6 +1147,11 @@ const isBooleanString = (s, allowNilEmpty) => {
|
|
|
960
1147
|
return v.toLowerCase() == "true" || v.toLowerCase() == "false";
|
|
961
1148
|
};
|
|
962
1149
|
exports.isBooleanString = isBooleanString;
|
|
1150
|
+
/**
|
|
1151
|
+
* Returns `true` when `s` represents a whole integer (no decimal point).
|
|
1152
|
+
* Rejects floats like `"1.5"` even though they are numeric.
|
|
1153
|
+
* @param allowNilEmpty - When true, null/empty values are treated as valid
|
|
1154
|
+
*/
|
|
963
1155
|
const isIntegerString = (s, allowNilEmpty) => {
|
|
964
1156
|
if (allowNilEmpty && !(0, exports.isNonEmptyString)(s))
|
|
965
1157
|
return true;
|
|
@@ -969,6 +1161,10 @@ const isIntegerString = (s, allowNilEmpty) => {
|
|
|
969
1161
|
return !(0, lodash_1.isNaN)(parseInt(v)) && /^-?\d+?$/.test(v);
|
|
970
1162
|
};
|
|
971
1163
|
exports.isIntegerString = isIntegerString;
|
|
1164
|
+
/**
|
|
1165
|
+
* Returns `true` when `s` represents a floating-point number (may or may not have a decimal point).
|
|
1166
|
+
* @param allowNilEmpty - When true, null/empty values are treated as valid
|
|
1167
|
+
*/
|
|
972
1168
|
const isFloatString = (s, allowNilEmpty) => {
|
|
973
1169
|
if (allowNilEmpty && !(0, exports.isNonEmptyString)(s))
|
|
974
1170
|
return true;
|
|
@@ -978,6 +1174,11 @@ const isFloatString = (s, allowNilEmpty) => {
|
|
|
978
1174
|
return !(0, lodash_1.isNaN)(parseFloat(v)) && /^-?\d+(?:[.]\d*?)?$/.test(v);
|
|
979
1175
|
};
|
|
980
1176
|
exports.isFloatString = isFloatString;
|
|
1177
|
+
/**
|
|
1178
|
+
* Returns the timestamp (ms) of the Sunday that begins the week containing `ts`.
|
|
1179
|
+
* @param ts - Unix-epoch millisecond timestamp to query
|
|
1180
|
+
* @param setToFirstSecond - When true, sets the time to 00:00:00.000 of that Sunday
|
|
1181
|
+
*/
|
|
981
1182
|
const getFirstDayOfTheWeek = (ts, setToFirstSecond) => {
|
|
982
1183
|
const dt = new Date(ts);
|
|
983
1184
|
dt.setDate(dt.getDate() - dt.getDay());
|
|
@@ -987,6 +1188,11 @@ const getFirstDayOfTheWeek = (ts, setToFirstSecond) => {
|
|
|
987
1188
|
return dt.getTime();
|
|
988
1189
|
};
|
|
989
1190
|
exports.getFirstDayOfTheWeek = getFirstDayOfTheWeek;
|
|
1191
|
+
/**
|
|
1192
|
+
* Returns the timestamp (ms) of the Saturday that ends the week containing `ts`.
|
|
1193
|
+
* @param ts - Unix-epoch millisecond timestamp to query
|
|
1194
|
+
* @param setToLastSecond - When true, sets the time to 23:59:59.059 of that Saturday
|
|
1195
|
+
*/
|
|
990
1196
|
const getLastDayOfTheWeek = (ts, setToLastSecond) => {
|
|
991
1197
|
const dt = new Date(ts);
|
|
992
1198
|
dt.setDate(dt.getDate() + 6 - dt.getDay());
|
|
@@ -996,6 +1202,10 @@ const getLastDayOfTheWeek = (ts, setToLastSecond) => {
|
|
|
996
1202
|
return dt.getTime();
|
|
997
1203
|
};
|
|
998
1204
|
exports.getLastDayOfTheWeek = getLastDayOfTheWeek;
|
|
1205
|
+
/**
|
|
1206
|
+
* Removes leading and trailing newline (`\n`) characters from a string.
|
|
1207
|
+
* Only newlines at the very beginning and end are stripped; internal newlines are untouched.
|
|
1208
|
+
*/
|
|
999
1209
|
const trimNewLine = (content) => {
|
|
1000
1210
|
const chars = content.split("");
|
|
1001
1211
|
while (chars[0] == "\n") {
|
|
@@ -1007,6 +1217,12 @@ const trimNewLine = (content) => {
|
|
|
1007
1217
|
return chars.join("");
|
|
1008
1218
|
};
|
|
1009
1219
|
exports.trimNewLine = trimNewLine;
|
|
1220
|
+
/**
|
|
1221
|
+
* Collapses multi-line text into a single paragraph.
|
|
1222
|
+
* Leading/trailing newlines are stripped, consecutive blank lines are compressed
|
|
1223
|
+
* to a single newline, then all newlines are replaced with spaces, and multiple
|
|
1224
|
+
* spaces are reduced to one.
|
|
1225
|
+
*/
|
|
1010
1226
|
const convertToOneParagraph = (content) => {
|
|
1011
1227
|
return (0, exports.trimNewLine)(content)
|
|
1012
1228
|
.replace(new RegExp(`(\n){2,}`, "g"), "\n")
|
|
@@ -1040,6 +1256,14 @@ const calculateSurcharge = (value, surcharge) => {
|
|
|
1040
1256
|
: surcharge.value;
|
|
1041
1257
|
};
|
|
1042
1258
|
exports.calculateSurcharge = calculateSurcharge;
|
|
1259
|
+
/**
|
|
1260
|
+
* Splits `list` into sequential sub-arrays (batches) of up to `size` items each.
|
|
1261
|
+
* An optional `func` transform is applied to each element before batching.
|
|
1262
|
+
* @param list - Source array to batch
|
|
1263
|
+
* @param size - Maximum items per batch
|
|
1264
|
+
* @param func - Optional mapping function applied to each item before batching
|
|
1265
|
+
* @example generateBatchArray([1,2,3,4,5], 2) // [[1,2],[3,4],[5]]
|
|
1266
|
+
*/
|
|
1043
1267
|
const generateBatchArray = (list, size, func) => {
|
|
1044
1268
|
const result = [];
|
|
1045
1269
|
const items = (0, lodash_1.map)(list, (c) => {
|
|
@@ -1052,6 +1276,14 @@ const generateBatchArray = (list, size, func) => {
|
|
|
1052
1276
|
return result;
|
|
1053
1277
|
};
|
|
1054
1278
|
exports.generateBatchArray = generateBatchArray;
|
|
1279
|
+
/**
|
|
1280
|
+
* Auto-detects and converts a string to its native type.
|
|
1281
|
+
* - `"true"` / `"false"` (case-insensitive) → `boolean`
|
|
1282
|
+
* - Numeric strings → `number`
|
|
1283
|
+
* - Everything else → original `string`
|
|
1284
|
+
* @example parseString("42") // 42
|
|
1285
|
+
* @example parseString("true") // true
|
|
1286
|
+
*/
|
|
1055
1287
|
const parseString = (input) => {
|
|
1056
1288
|
// Check if the input is a boolean
|
|
1057
1289
|
if (input.toLowerCase() === "true") {
|
|
@@ -1069,14 +1301,31 @@ const parseString = (input) => {
|
|
|
1069
1301
|
return input;
|
|
1070
1302
|
};
|
|
1071
1303
|
exports.parseString = parseString;
|
|
1304
|
+
/**
|
|
1305
|
+
* Returns `true` when `json` is a non-null string that parses as valid JSON without errors.
|
|
1306
|
+
* Uses lodash `attempt` to avoid throwing on invalid input.
|
|
1307
|
+
*/
|
|
1072
1308
|
const isGoodJSON = (json) => {
|
|
1073
1309
|
return !(0, lodash_1.isNil)(json) && !(0, lodash_1.isError)((0, lodash_1.attempt)(JSON.parse, json));
|
|
1074
1310
|
};
|
|
1075
1311
|
exports.isGoodJSON = isGoodJSON;
|
|
1312
|
+
/**
|
|
1313
|
+
* Returns a Promise that resolves after `ms` milliseconds.
|
|
1314
|
+
* Use with `await` to introduce a non-blocking delay.
|
|
1315
|
+
* @param ms - Delay duration in milliseconds
|
|
1316
|
+
*/
|
|
1076
1317
|
const wait = (ms) => {
|
|
1077
1318
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
1078
1319
|
};
|
|
1079
1320
|
exports.wait = wait;
|
|
1321
|
+
/**
|
|
1322
|
+
* Recursively computes the difference between two plain objects.
|
|
1323
|
+
* Returns an array of change descriptors with `type` of `"added"`, `"removed"`, or `"changed"`,
|
|
1324
|
+
* each containing the full dot-notation `key` and the affected value(s).
|
|
1325
|
+
* @param obj1 - Base object
|
|
1326
|
+
* @param obj2 - Comparison object
|
|
1327
|
+
* @param path - Internal dot-notation path prefix (used in recursive calls; leave empty at call site)
|
|
1328
|
+
*/
|
|
1080
1329
|
const getObjsDifference = (obj1, obj2, path = "") => {
|
|
1081
1330
|
let diffs = [];
|
|
1082
1331
|
const allKeys = new Set([
|
|
@@ -1111,6 +1360,12 @@ const getObjsDifference = (obj1, obj2, path = "") => {
|
|
|
1111
1360
|
return diffs;
|
|
1112
1361
|
};
|
|
1113
1362
|
exports.getObjsDifference = getObjsDifference;
|
|
1363
|
+
/**
|
|
1364
|
+
* Converts a string to AP-style title case.
|
|
1365
|
+
* Minor words (a, an, and, as, at, but, by, for, in, nor, of, on, or, so, the, to, up, yet)
|
|
1366
|
+
* are kept lowercase unless they are the first word.
|
|
1367
|
+
* @example toTitle("the quick brown fox") // "The Quick Brown Fox"
|
|
1368
|
+
*/
|
|
1114
1369
|
const toTitle = (str) => {
|
|
1115
1370
|
const minorWords = new Set([
|
|
1116
1371
|
"a",
|
|
@@ -1148,10 +1403,17 @@ const toTitle = (str) => {
|
|
|
1148
1403
|
return result.join(" ");
|
|
1149
1404
|
};
|
|
1150
1405
|
exports.toTitle = toTitle;
|
|
1406
|
+
/**
|
|
1407
|
+
* Generates a new RFC 4122 v4 UUID string.
|
|
1408
|
+
* @returns A lowercase hyphenated UUID, e.g. `"550e8400-e29b-41d4-a716-446655440000"`
|
|
1409
|
+
*/
|
|
1151
1410
|
const newGuid = () => {
|
|
1152
1411
|
return (0, uuid_1.v4)();
|
|
1153
1412
|
};
|
|
1154
1413
|
exports.newGuid = newGuid;
|
|
1414
|
+
/**
|
|
1415
|
+
* Returns the current time as a Unix timestamp in seconds (integer, floor-truncated).
|
|
1416
|
+
*/
|
|
1155
1417
|
const unixTimestamp = () => {
|
|
1156
1418
|
return Math.floor(Date.now() / 1000);
|
|
1157
1419
|
};
|