@zelgadis87/utils-core 4.6.2 → 4.8.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 {
@@ -905,6 +931,14 @@ var StringParts = class _StringParts {
905
931
  static fromParts = (...parts) => {
906
932
  return new _StringParts(...parts);
907
933
  };
934
+ /**
935
+ * 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").
936
+ * @param s a string in PascalCase.
937
+ * @returns a StringParts where each sub-word in PascalCase is now a part.
938
+ */
939
+ static tryToParsePascalCaseWord(s) {
940
+ return new _StringParts(...s.split(/([A-Z][a-z]*)/).filter(Boolean).map((n) => n.toLowerCase()));
941
+ }
908
942
  };
909
943
 
910
944
  // src/utils/strings.ts
@@ -1963,13 +1997,16 @@ var Optional = class _Optional {
1963
1997
  this._value = defined ? t : void 0;
1964
1998
  this._present = defined;
1965
1999
  }
1966
- get rawValue() {
2000
+ getRawValue() {
1967
2001
  return this._value;
1968
2002
  }
1969
2003
  get() {
2004
+ return this.getOrElseThrow(() => new ErrorGetEmptyOptional());
2005
+ }
2006
+ getOrElseThrow(errorProducer) {
1970
2007
  if (this.isEmpty())
1971
- throw new ErrorGetEmptyOptional();
1972
- return this.rawValue;
2008
+ throw errorProducer();
2009
+ return this._value;
1973
2010
  }
1974
2011
  set(t) {
1975
2012
  if (isNullOrUndefined(t))
@@ -1993,13 +2030,13 @@ var Optional = class _Optional {
1993
2030
  }
1994
2031
  ifPresent(callback) {
1995
2032
  if (this.isPresent())
1996
- callback(this.rawValue);
2033
+ callback(this.get());
1997
2034
  }
1998
2035
  apply(callbackIfPresent, callbackIfEmpty) {
1999
2036
  if (this.isEmpty()) {
2000
2037
  callbackIfEmpty();
2001
2038
  } else {
2002
- callbackIfPresent(this.rawValue);
2039
+ callbackIfPresent(this.get());
2003
2040
  }
2004
2041
  }
2005
2042
  orElse(newValue) {
@@ -2014,31 +2051,23 @@ var Optional = class _Optional {
2014
2051
  }
2015
2052
  return this;
2016
2053
  }
2017
- orElseThrow(produceError) {
2054
+ orElseThrow(errorProducer) {
2018
2055
  if (this.isEmpty())
2019
- throw produceError();
2056
+ throw errorProducer();
2020
2057
  return this;
2021
2058
  }
2022
2059
  mapTo(mapper) {
2023
2060
  return this.flatMapTo((t) => _Optional.ofNullable(mapper(t)));
2024
2061
  }
2025
2062
  flatMapTo(mapper) {
2026
- if (this.isPresent()) {
2027
- const newValue = mapper(this.rawValue);
2028
- return newValue;
2029
- }
2030
- return this;
2063
+ return this.isPresent() ? mapper(this.get()) : _Optional.empty();
2031
2064
  }
2032
2065
  filter(predicate) {
2033
- if (this.isPresent()) {
2034
- if (predicate(this.rawValue)) {
2035
- return this;
2036
- } else {
2037
- return _Optional.empty();
2038
- }
2039
- } else {
2066
+ if (this.isEmpty())
2040
2067
  return this;
2041
- }
2068
+ if (predicate(this.get()))
2069
+ return this;
2070
+ return _Optional.empty();
2042
2071
  }
2043
2072
  static empty() {
2044
2073
  return new _Optional(void 0);
@@ -2054,7 +2083,7 @@ var Optional = class _Optional {
2054
2083
  };
2055
2084
  var ErrorGetEmptyOptional = class extends Error {
2056
2085
  constructor() {
2057
- super("Cannot retrieve a value from an EmptyOptional.");
2086
+ super("Cannot retrieve a value from an empty Optional.");
2058
2087
  }
2059
2088
  };
2060
2089
  var ErrorSetEmptyOptional = class extends Error {
@@ -2681,6 +2710,7 @@ export {
2681
2710
  constantTrue,
2682
2711
  constantZero,
2683
2712
  createSorterFor,
2713
+ cssDeclarationRulesDictionaryToCss,
2684
2714
  decrement,
2685
2715
  decrementBy,
2686
2716
  delayPromise,