@zelgadis87/utils-core 4.7.0 → 4.9.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/esbuild/index.mjs CHANGED
@@ -626,6 +626,32 @@ function isFalse(x) {
626
626
  return x === false;
627
627
  }
628
628
 
629
+ // src/utils/css.ts
630
+ var newLine = "\n";
631
+ var tabulation = " ";
632
+ var colon = ":";
633
+ var semiColon = ";";
634
+ var space = " ";
635
+ var openBracket = "{";
636
+ var closeBracket = "}";
637
+ function cssDeclarationRulesDictionaryToCss(syleDeclarationRulesForSelectors) {
638
+ return Object.entries(syleDeclarationRulesForSelectors).map(([selector, styleDeclarationRules]) => {
639
+ const cssRules = cssSelectorDeclarationRulesDictionaryToCss(styleDeclarationRules);
640
+ if (!cssRules.length) return null;
641
+ return selector + space + openBracket + newLine + cssRules.map((rule) => tabulation + rule + semiColon).join(newLine) + newLine + closeBracket;
642
+ }).filter(Boolean).join(newLine + newLine);
643
+ }
644
+ function cssSelectorDeclarationRulesDictionaryToCss(styleDeclarationRulesProduceable) {
645
+ const styleDeclarationRules = produceableToValue(styleDeclarationRulesProduceable);
646
+ return Object.entries(styleDeclarationRules).map(([key, value]) => pascalCaseToKebabCase(key) + colon + space + produceableToValue(value));
647
+ }
648
+ function pascalCaseToKebabCase(s) {
649
+ return s.split(/([A-Z][a-z]*)/).filter(Boolean).map((n) => n.toLowerCase()).join("-");
650
+ }
651
+ function produceableToValue(t) {
652
+ return isFunction(t) ? t() : t;
653
+ }
654
+
629
655
  // src/utils/errors/withTryCatch.ts
630
656
  function withTryCatch(fn, errMapFn) {
631
657
  try {
@@ -789,6 +815,18 @@ function promiseSequence(...fns) {
789
815
  function delayPromise(duration) {
790
816
  return (result) => duration.promise().then(() => result);
791
817
  }
818
+ var TimeoutError = class extends Error {
819
+ };
820
+ async function awaitAtMost(p, t) {
821
+ return Promise.race([
822
+ p.then((value) => ({ status: "ok", value })),
823
+ t.promise().then(() => ({ status: "timeout" }))
824
+ ]).then(({ status, value }) => {
825
+ if (status === "ok")
826
+ return value;
827
+ throw new TimeoutError();
828
+ });
829
+ }
792
830
 
793
831
  // src/utils/random.ts
794
832
  var randomInterval = (min2, max2) => randomNumberInInterval(min2, max2);
@@ -905,6 +943,14 @@ var StringParts = class _StringParts {
905
943
  static fromParts = (...parts) => {
906
944
  return new _StringParts(...parts);
907
945
  };
946
+ /**
947
+ * Tries to convert a word in PascalCase to an array of words. Will not work if there are spaces or special characters. Does not cope well on uppercase abbreviations (eg, "CSS").
948
+ * @param s a string in PascalCase.
949
+ * @returns a StringParts where each sub-word in PascalCase is now a part.
950
+ */
951
+ static tryToParsePascalCaseWord(s) {
952
+ return new _StringParts(...s.split(/([A-Z][a-z]*)/).filter(Boolean).map((n) => n.toLowerCase()));
953
+ }
908
954
  };
909
955
 
910
956
  // src/utils/strings.ts
@@ -2661,12 +2707,14 @@ export {
2661
2707
  TimeInstant,
2662
2708
  TimeRange,
2663
2709
  TimeUnit,
2710
+ TimeoutError,
2664
2711
  alwaysFalse,
2665
2712
  alwaysTrue,
2666
2713
  and,
2667
2714
  asError,
2668
2715
  asPromise,
2669
2716
  average,
2717
+ awaitAtMost,
2670
2718
  capitalizeWord,
2671
2719
  clamp,
2672
2720
  constant,
@@ -2676,6 +2724,7 @@ export {
2676
2724
  constantTrue,
2677
2725
  constantZero,
2678
2726
  createSorterFor,
2727
+ cssDeclarationRulesDictionaryToCss,
2679
2728
  decrement,
2680
2729
  decrementBy,
2681
2730
  delayPromise,