@mll-lab/js-utils 2.8.0 → 2.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.
@@ -15205,6 +15205,23 @@ function joinNonEmpty(maybeStrings, separator) {
15205
15205
  return maybeStrings.filter(Boolean).join(separator);
15206
15206
  }
15207
15207
 
15208
+ /**
15209
+ * Converts pixel value to number.
15210
+ *
15211
+ * @example "4px" to 4
15212
+ */
15213
+ function pxToNumber(pixels) {
15214
+ const count = (pixels.match(/px/g) || []).length;
15215
+ if (count > 1 || !pixels.endsWith('px')) {
15216
+ throw new Error(`'${pixels}' does not contain a single 'px'`);
15217
+ }
15218
+ const parsedValue = parseFloat(pixels);
15219
+ if (Number.isNaN(parsedValue)) {
15220
+ throw new Error(`'${pixels}' is not a valid single pixel-value`);
15221
+ }
15222
+ return parsedValue;
15223
+ }
15224
+
15208
15225
  exports.DOTLESS_DATE_FORMAT = DOTLESS_DATE_FORMAT;
15209
15226
  exports.EMAIL_REGEX = EMAIL_REGEX;
15210
15227
  exports.EMPTY_ARRAY = EMPTY_ARRAY;
@@ -15252,6 +15269,7 @@ exports.parseIsoDate = parseIsoDate;
15252
15269
  exports.parseIsoDateTime = parseIsoDateTime;
15253
15270
  exports.parseSecondlessDateTime = parseSecondlessDateTime;
15254
15271
  exports.pluralize = pluralize;
15272
+ exports.pxToNumber = pxToNumber;
15255
15273
  exports.round = round;
15256
15274
  exports.withoutIndex = withoutIndex;
15257
15275
  //# sourceMappingURL=index.common.js.map