@trackunit/shared-utils 1.11.9 → 1.11.12

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/index.cjs.js CHANGED
@@ -1409,6 +1409,25 @@ const uuidv4 = () => {
1409
1409
  */
1410
1410
  const uuidv5 = (name, namespace) => uuid.v5(name, namespace);
1411
1411
 
1412
+ /**
1413
+ * Parses the numeric value from a Tailwind arbitrary value class.
1414
+ * This is useful when you need both a static Tailwind class (for JIT compilation)
1415
+ * and a numeric value for runtime logic, keeping them in sync.
1416
+ *
1417
+ * @param className - A Tailwind class containing an arbitrary numeric value
1418
+ * @returns {number} The numeric value extracted from the class
1419
+ * @example
1420
+ * const MIN_WIDTH_CLASS = "min-w-[80px]";
1421
+ * const MIN_WIDTH_PX = parseTailwindArbitraryValue(MIN_WIDTH_CLASS); // 80
1422
+ */
1423
+ const parseTailwindArbitraryValue = (className) => {
1424
+ const match = className.match(/\[(-?\d+)/);
1425
+ if (match === null) {
1426
+ throw new Error(`Could not extract arbitrary value from: ${className}`);
1427
+ }
1428
+ return Number(match[1]);
1429
+ };
1430
+
1412
1431
  const METERS_PER_YARD = 0.9144; // 1 yard = 0.9144 meters
1413
1432
  const METERS_PER_KILOMETER = 1000; // 1 kilometer = 1000 meters
1414
1433
  const YARDS_PER_METER = 1.09361; // 1 meter = 1.09361 yards
@@ -1588,6 +1607,7 @@ exports.objectEntries = objectEntries;
1588
1607
  exports.objectFromEntries = objectFromEntries;
1589
1608
  exports.objectKeys = objectKeys;
1590
1609
  exports.objectValues = objectValues;
1610
+ exports.parseTailwindArbitraryValue = parseTailwindArbitraryValue;
1591
1611
  exports.pick = pick;
1592
1612
  exports.preload = preload;
1593
1613
  exports.removeLeftPadding = removeLeftPadding;
package/index.esm.js CHANGED
@@ -1407,6 +1407,25 @@ const uuidv4 = () => {
1407
1407
  */
1408
1408
  const uuidv5 = (name, namespace) => v5(name, namespace);
1409
1409
 
1410
+ /**
1411
+ * Parses the numeric value from a Tailwind arbitrary value class.
1412
+ * This is useful when you need both a static Tailwind class (for JIT compilation)
1413
+ * and a numeric value for runtime logic, keeping them in sync.
1414
+ *
1415
+ * @param className - A Tailwind class containing an arbitrary numeric value
1416
+ * @returns {number} The numeric value extracted from the class
1417
+ * @example
1418
+ * const MIN_WIDTH_CLASS = "min-w-[80px]";
1419
+ * const MIN_WIDTH_PX = parseTailwindArbitraryValue(MIN_WIDTH_CLASS); // 80
1420
+ */
1421
+ const parseTailwindArbitraryValue = (className) => {
1422
+ const match = className.match(/\[(-?\d+)/);
1423
+ if (match === null) {
1424
+ throw new Error(`Could not extract arbitrary value from: ${className}`);
1425
+ }
1426
+ return Number(match[1]);
1427
+ };
1428
+
1410
1429
  const METERS_PER_YARD = 0.9144; // 1 yard = 0.9144 meters
1411
1430
  const METERS_PER_KILOMETER = 1000; // 1 kilometer = 1000 meters
1412
1431
  const YARDS_PER_METER = 1.09361; // 1 meter = 1.09361 yards
@@ -1528,4 +1547,4 @@ const formatUsCustomaryDistance = (value) => {
1528
1547
  }
1529
1548
  };
1530
1549
 
1531
- export { DateTimeFormat, HoursAndMinutesFormat, UnitsOfMeasurementSI, UnitsOfMeasurementUSCustomary, align, alphabeticallySort, arrayLengthCompare, arrayNotEmpty, booleanCompare, calculateImageScaleRatio, capitalize, colorsFromStyleDeclaration, convertBlobToBase64, convertMetersToKilometers, convertMetersToYards, convertYardsToMeters, convertYardsToMiles, dateCompare, deleteUndefinedKeys, difference, doNothing, enumFromValue, enumFromValueTypesafe, enumOrUndefinedFromValue, exhaustiveCheck, fetchImageAsBase64, filterByMultiple, formatAddress, formatCoordinates, formatSiDistance, formatUsCustomaryDistance, fuzzySearch, getAllColors, getDifferenceBetweenDates, getEndOfDay, getFirstLevelObjectPropertyDifferences, getISOStringFromDate, getLoremIpsum, getMimeTypeFromDataURL, getResizedDimensions, getStartOfDay, groupBy, groupTinyDataToOthers, hourIntervals, intersection, isArrayEqual, isSorted, isUUID, isValidImage, loadSVGDimensions, nonNullable, numberCompare, numberCompareUnknownAfterHighest, objNotEmpty, objectEntries, objectFromEntries, objectKeys, objectValues, pick, preload, removeLeftPadding, removeProperties, removeProperty, replaceNullableNumbersWithZero, resizeBlob, resizeImage, rgb2hex, size, stringCompare, stringCompareFromKey, stringNaturalCompare, stripHiddenCharacters, svgToPNG, titleCase, toID, toIDs, toPNG, toUUID, trimIds, trimPath, truthy, unionArraysByKey, uuidv3, uuidv4, uuidv5 };
1550
+ export { DateTimeFormat, HoursAndMinutesFormat, UnitsOfMeasurementSI, UnitsOfMeasurementUSCustomary, align, alphabeticallySort, arrayLengthCompare, arrayNotEmpty, booleanCompare, calculateImageScaleRatio, capitalize, colorsFromStyleDeclaration, convertBlobToBase64, convertMetersToKilometers, convertMetersToYards, convertYardsToMeters, convertYardsToMiles, dateCompare, deleteUndefinedKeys, difference, doNothing, enumFromValue, enumFromValueTypesafe, enumOrUndefinedFromValue, exhaustiveCheck, fetchImageAsBase64, filterByMultiple, formatAddress, formatCoordinates, formatSiDistance, formatUsCustomaryDistance, fuzzySearch, getAllColors, getDifferenceBetweenDates, getEndOfDay, getFirstLevelObjectPropertyDifferences, getISOStringFromDate, getLoremIpsum, getMimeTypeFromDataURL, getResizedDimensions, getStartOfDay, groupBy, groupTinyDataToOthers, hourIntervals, intersection, isArrayEqual, isSorted, isUUID, isValidImage, loadSVGDimensions, nonNullable, numberCompare, numberCompareUnknownAfterHighest, objNotEmpty, objectEntries, objectFromEntries, objectKeys, objectValues, parseTailwindArbitraryValue, pick, preload, removeLeftPadding, removeProperties, removeProperty, replaceNullableNumbersWithZero, resizeBlob, resizeImage, rgb2hex, size, stringCompare, stringCompareFromKey, stringNaturalCompare, stripHiddenCharacters, svgToPNG, titleCase, toID, toIDs, toPNG, toUUID, trimIds, trimPath, truthy, unionArraysByKey, uuidv3, uuidv4, uuidv5 };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trackunit/shared-utils",
3
- "version": "1.11.9",
3
+ "version": "1.11.12",
4
4
  "repository": "https://github.com/Trackunit/manager",
5
5
  "engines": {
6
6
  "node": ">=24.x"
package/src/index.d.ts CHANGED
@@ -25,4 +25,5 @@ export * from "./svgTools";
25
25
  export * from "./translationUtils";
26
26
  export * from "./typeUtils";
27
27
  export * from "./UUID";
28
+ export * from "./tailwindUtils";
28
29
  export * from "./UnitOfMeasurementConverter";
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Represents a Tailwind CSS class with an arbitrary numeric value.
3
+ *
4
+ * @example "min-w-[80px]", "gap-[12rem]", "top-[-10px]"
5
+ */
6
+ export type TailwindArbitraryValueClass = `${string}[${number}${string}]` | `${string}[-${number}${string}]`;
7
+ /**
8
+ * Parses the numeric value from a Tailwind arbitrary value class.
9
+ * This is useful when you need both a static Tailwind class (for JIT compilation)
10
+ * and a numeric value for runtime logic, keeping them in sync.
11
+ *
12
+ * @param className - A Tailwind class containing an arbitrary numeric value
13
+ * @returns {number} The numeric value extracted from the class
14
+ * @example
15
+ * const MIN_WIDTH_CLASS = "min-w-[80px]";
16
+ * const MIN_WIDTH_PX = parseTailwindArbitraryValue(MIN_WIDTH_CLASS); // 80
17
+ */
18
+ export declare const parseTailwindArbitraryValue: (className: TailwindArbitraryValueClass) => number;