@putkoff/abstract-utilities 1.0.29 → 1.0.32

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/dist/cjs/index.js CHANGED
@@ -1831,6 +1831,28 @@ function get_splitext(filePath) {
1831
1831
  const filename = pathBrowserify.basename(filePath, ext);
1832
1832
  return { filename, ext };
1833
1833
  }
1834
+ /**
1835
+ * Returns the path of `targetPath` relative to `basePath`.
1836
+ * Normalizes separators for consistent web and server environments.
1837
+ *
1838
+ * @param basePath - The base directory you want to compare from.
1839
+ * @param targetPath - The full path of the file/directory.
1840
+ * @returns A normalized relative path (e.g., "subdir/file.txt").
1841
+ */
1842
+ function get_relative_path(basePath, targetPath) {
1843
+ try {
1844
+ // Compute the relative path using Node's native path.relative
1845
+ let rel = pathBrowserify.relative(basePath, targetPath);
1846
+ // Normalize to POSIX-style slashes for consistency (especially on Windows)
1847
+ rel = rel.split(pathBrowserify.sep).join('/');
1848
+ // Avoid empty string (happens if both paths are identical)
1849
+ return rel || '.';
1850
+ }
1851
+ catch (err) {
1852
+ console.error(`[get_relative_path] Error computing relative path`, err);
1853
+ return targetPath;
1854
+ }
1855
+ }
1834
1856
  /**
1835
1857
  * Join multiple path segments, normalizing leading/trailing slashes.
1836
1858
  *
@@ -2018,7 +2040,6 @@ function exponential(i, k) {
2018
2040
  return i * (10 ** (k));
2019
2041
  }
2020
2042
 
2021
- // Time
2022
2043
  const SECOND = 1;
2023
2044
  const ZEPTOSECOND = exponential(SECOND, -21);
2024
2045
  const ATTOSECOND = exponential(SECOND, -18);
@@ -2042,66 +2063,147 @@ const SECONDS_PER_DAY = DAY;
2042
2063
  const PI = Math.PI;
2043
2064
  const PI2 = 2 * PI;
2044
2065
  // Distance
2045
- const M_IN_KM = 1000;
2046
- const M_IN_MI = 1609.34;
2047
- const M_IN_FT = 0.3048;
2048
- const KM_IN_M = 1 / M_IN_KM;
2049
- const MI_IN_M = 1 / M_IN_MI;
2050
- const FT_IN_M = 1 / M_IN_FT;
2066
+ const METERS_PER_KM = 1000;
2067
+ const METERS_PER_MILE = 1609.34;
2068
+ const METERS_PER_FOOT = 0.3048;
2069
+ const KMS_PER_METER = 1 / METERS_PER_KM;
2070
+ const MILES_PER_METER = 1 / METERS_PER_MILE;
2071
+ const FEET_PER_METER = 1 / METERS_PER_FOOT;
2051
2072
  const MIN_IN_S = 1 / MINUTE;
2052
2073
  const HOUR_IN_S = 1 / HOUR;
2053
2074
  const DAY_IN_S = 1 / DAY;
2054
2075
  const YEAR_IN_S = 1 / YEAR;
2055
2076
  const MONTH_IN_S = 1 / MONTH;
2056
- const MiPerH_TO_MPerS = M_IN_MI * HOUR_IN_S;
2077
+ const MiPerH_TO_MPerS = METERS_PER_MILE * HOUR_IN_S;
2057
2078
  const MPerS_TO_MiPerH = 1 / MiPerH_TO_MPerS;
2058
2079
 
2059
- // Conversion helpers
2060
- const toMeters = (v, unit) => {
2061
- switch (unit) {
2062
- case 'km': return v * M_IN_KM;
2063
- case 'mi': return v * M_IN_MI;
2064
- case 'ft': return v * M_IN_FT;
2065
- default: return v; // meters
2066
- }
2080
+ // conversions.ts
2081
+ /*───────────────────────────────────────────────────────────────
2082
+ 🧭 CANONICAL MAPPINGS
2083
+ ───────────────────────────────────────────────────────────────*/
2084
+ const DIST_ALIASES = {
2085
+ m: "m", meter: "m", meters: "m",
2086
+ km: "km", kms: "km", kilometer: "km", kilometers: "km",
2087
+ mi: "mi", mile: "mi", miles: "mi",
2088
+ ft: "ft", f: "ft", foot: "ft", feet: "ft",
2067
2089
  };
2068
- const toSeconds = (v, unit) => {
2069
- switch (unit) {
2070
- case 'min': return v * MINUTE;
2071
- case 'h': return v * HOUR;
2072
- case 'day': return v * DAY;
2073
- default: return v;
2074
- }
2090
+ const TIME_ALIASES = {
2091
+ s: "s", sec: "s", second: "s", seconds: "s",
2092
+ min: "min", m: "min", minute: "min", minutes: "min",
2093
+ h: "h", hr: "h", hour: "h", hours: "h",
2094
+ day: "day", d: "day", days: "day",
2075
2095
  };
2076
- const fromMeters = (d, unit) => {
2077
- switch (unit) {
2078
- case 'km': return d / M_IN_KM;
2079
- case 'mi': return d / M_IN_MI;
2080
- case 'ft': return d / M_IN_FT;
2081
- default: return d; // meters
2082
- }
2096
+ const DIST_FACTORS = {
2097
+ m: 1,
2098
+ km: METERS_PER_KM,
2099
+ mi: METERS_PER_MILE,
2100
+ ft: METERS_PER_FOOT,
2083
2101
  };
2084
- const velocityToMs = (value, unit) => {
2085
- switch (unit) {
2086
- case 'km/s': return value * M_IN_KM;
2087
- case 'mph': return value * MiPerH_TO_MPerS; // 1 mph = 0.44704 m/s
2088
- case 'ft/s': return value * M_IN_FT; // 1 ft/s = 0.3048 m/s
2089
- default: return value; // m/s
2090
- }
2102
+ const TIME_FACTORS = {
2103
+ s: 1,
2104
+ min: MINUTE,
2105
+ h: HOUR,
2106
+ day: DAY,
2091
2107
  };
2092
- const velocityFromMs = (value, unit) => {
2093
- switch (unit) {
2094
- case 'km/s': return value * KM_IN_M;
2095
- case 'mph': return value * MPerS_TO_MiPerH;
2096
- case 'ft/s': return value * FT_IN_M;
2097
- default: return value;
2098
- }
2108
+ /*───────────────────────────────────────────────────────────────
2109
+ 🔍 CANONICALIZATION HELPERS
2110
+ ───────────────────────────────────────────────────────────────*/
2111
+ function canonDist(u) {
2112
+ const key = (u !== null && u !== void 0 ? u : "m").toString().toLowerCase();
2113
+ const canon = DIST_ALIASES[key];
2114
+ if (!canon)
2115
+ throw new Error(`Unknown distance unit: ${u}`);
2116
+ return canon;
2117
+ }
2118
+ function canonTime(u) {
2119
+ const key = (u !== null && u !== void 0 ? u : "s").toString().toLowerCase();
2120
+ const canon = TIME_ALIASES[key];
2121
+ if (!canon)
2122
+ throw new Error(`Unknown time unit: ${u}`);
2123
+ return canon;
2124
+ }
2125
+ /*───────────────────────────────────────────────────────────────
2126
+ ⚖️ NORMALIZATION HELPERS
2127
+ ───────────────────────────────────────────────────────────────*/
2128
+ function distanceToMeters(d, unit) {
2129
+ const u = canonDist(unit);
2130
+ return safeMultiply(d, DIST_FACTORS[u]);
2131
+ }
2132
+ function metersToDistance(v, unit) {
2133
+ const u = canonDist(unit);
2134
+ return safeDivide(v, DIST_FACTORS[u]);
2135
+ }
2136
+ function timeToSeconds(t, unit) {
2137
+ const u = canonTime(unit);
2138
+ return safeMultiply(t, TIME_FACTORS[u]);
2139
+ }
2140
+ function secondsToTime(v, unit) {
2141
+ const u = canonTime(unit);
2142
+ return safeDivide(v, TIME_FACTORS[u]);
2143
+ }
2144
+ /*───────────────────────────────────────────────────────────────
2145
+ 🚀 SPEED CONVERSIONS (normalize / unnormalize)
2146
+ ───────────────────────────────────────────────────────────────*/
2147
+ function speedToMps(v, distUnit, timeUnit) {
2148
+ const du = canonDist(distUnit);
2149
+ const tu = canonTime(timeUnit);
2150
+ return v * (DIST_FACTORS[du] / TIME_FACTORS[tu]);
2151
+ }
2152
+ function mpsToSpeed(vMps, distUnit, timeUnit) {
2153
+ const du = canonDist(distUnit);
2154
+ const tu = canonTime(timeUnit);
2155
+ return vMps * (TIME_FACTORS[tu] / DIST_FACTORS[du]);
2156
+ }
2157
+ /*───────────────────────────────────────────────────────────────
2158
+ 🎯 UNIVERSAL CONVERTERS
2159
+ ───────────────────────────────────────────────────────────────*/
2160
+ function convertDistance({ d, fromDist, toDist, vOnly = true, }) {
2161
+ const m = distanceToMeters(d, fromDist);
2162
+ const D = canonDist(toDist !== null && toDist !== void 0 ? toDist : "m");
2163
+ const out = metersToDistance(m, D);
2164
+ return vOnly ? out : { d: out, D };
2165
+ }
2166
+ function convertTime({ t, fromTime, toTime, vOnly = true, }) {
2167
+ const sec = timeToSeconds(t, fromTime);
2168
+ const T = canonTime(toTime !== null && toTime !== void 0 ? toTime : "s");
2169
+ const out = secondsToTime(sec, T);
2170
+ return vOnly ? out : { t: out, T };
2171
+ }
2172
+ function convertSpeed({ v, fromDist, fromTime, toDist, toTime, vOnly = true, }) {
2173
+ const mps = speedToMps(v, fromDist, fromTime);
2174
+ const d = canonDist(toDist !== null && toDist !== void 0 ? toDist : "m");
2175
+ const t = canonTime(toTime !== null && toTime !== void 0 ? toTime : "s");
2176
+ const out = mpsToSpeed(mps, d, t);
2177
+ return vOnly ? out : { v: out, d, t };
2178
+ }
2179
+ const DistanceConverter = {
2180
+ normalize: distanceToMeters,
2181
+ unnormalize: metersToDistance,
2182
+ };
2183
+ const TimeConverter = {
2184
+ normalize: timeToSeconds,
2185
+ unnormalize: secondsToTime,
2099
2186
  };
2100
- const fromMps = (v, dist_unit, time_unit) => {
2101
- const dist_conv = toMeters(1, dist_unit);
2102
- const time_conv = toSeconds(1, time_unit);
2103
- return v * (time_conv / dist_conv);
2187
+ const SpeedConverter = {
2188
+ normalize: (v, [du, tu]) => speedToMps(v, du, tu),
2189
+ unnormalize: (v, [du, tu]) => mpsToSpeed(v, du, tu),
2104
2190
  };
2191
+ /*───────────────────────────────────────────────────────────────
2192
+ 🧩 COMPATIBILITY WRAPPERS (legacy aliases)
2193
+ ───────────────────────────────────────────────────────────────*/
2194
+ const toMeters = distanceToMeters;
2195
+ const fromMeters = metersToDistance;
2196
+ const toSeconds = timeToSeconds;
2197
+ const fromSeconds = secondsToTime;
2198
+ const velocityToMs = (value, unit) => speedToMps(value, unit, "s");
2199
+ const velocityFromMs = (value, unit) => mpsToSpeed(value, unit, "s");
2200
+ /** Non-canonical helper for arbitrary rate conversion, e.g. ft/day → m/s */
2201
+ const fromMps = (v, dist_unit, time_unit) => mpsToSpeed(v, dist_unit, time_unit);
2202
+ /*───────────────────────────────────────────────────────────────
2203
+ 📊 UTILITIES
2204
+ ───────────────────────────────────────────────────────────────*/
2205
+ const isFiniteNum = (x) => Number.isFinite(x);
2206
+ const fmt = (n, digits = 2) => isFiniteNum(n) ? n.toFixed(digits) : "N/A";
2105
2207
 
2106
2208
  function Button(_a) {
2107
2209
  var { children, color = 'gray', variant = 'default', className = '' } = _a, rest = __rest(_a, ["children", "color", "variant", "className"]);
@@ -2272,26 +2374,29 @@ exports.DAY = DAY;
2272
2374
  exports.DAY_IN_S = DAY_IN_S;
2273
2375
  exports.DECISECOND = DECISECOND;
2274
2376
  exports.DEV_PREFIX = DEV_PREFIX;
2377
+ exports.DIST_ALIASES = DIST_ALIASES;
2378
+ exports.DIST_FACTORS = DIST_FACTORS;
2275
2379
  exports.DOMAIN_NAME = DOMAIN_NAME;
2380
+ exports.DistanceConverter = DistanceConverter;
2381
+ exports.FEET_PER_METER = FEET_PER_METER;
2276
2382
  exports.FEMTOSECOND = FEMTOSECOND;
2277
- exports.FT_IN_M = FT_IN_M;
2278
2383
  exports.HOUR = HOUR;
2279
2384
  exports.HOUR_IN_S = HOUR_IN_S;
2280
2385
  exports.Input = Input;
2281
- exports.KM_IN_M = KM_IN_M;
2386
+ exports.KMS_PER_METER = KMS_PER_METER;
2282
2387
  exports.MEDIA_TYPES = MEDIA_TYPES;
2388
+ exports.METERS_PER_FOOT = METERS_PER_FOOT;
2389
+ exports.METERS_PER_KM = METERS_PER_KM;
2390
+ exports.METERS_PER_MILE = METERS_PER_MILE;
2283
2391
  exports.MICROSECOND = MICROSECOND;
2392
+ exports.MILES_PER_METER = MILES_PER_METER;
2284
2393
  exports.MILISECOND = MILISECOND;
2285
2394
  exports.MIME_TYPES = MIME_TYPES;
2286
2395
  exports.MINUTE = MINUTE;
2287
2396
  exports.MIN_IN_S = MIN_IN_S;
2288
- exports.MI_IN_M = MI_IN_M;
2289
2397
  exports.MONTH = MONTH;
2290
2398
  exports.MONTH_IN_S = MONTH_IN_S;
2291
2399
  exports.MPerS_TO_MiPerH = MPerS_TO_MiPerH;
2292
- exports.M_IN_FT = M_IN_FT;
2293
- exports.M_IN_KM = M_IN_KM;
2294
- exports.M_IN_MI = M_IN_MI;
2295
2400
  exports.MiPerH_TO_MPerS = MiPerH_TO_MPerS;
2296
2401
  exports.NANOSECOND = NANOSECOND;
2297
2402
  exports.PI = PI;
@@ -2304,7 +2409,11 @@ exports.SECONDS_PER_DAY = SECONDS_PER_DAY;
2304
2409
  exports.SECONDS_PER_HOUR = SECONDS_PER_HOUR;
2305
2410
  exports.SECONDS_PER_MINUTE = SECONDS_PER_MINUTE;
2306
2411
  exports.SUB_DIR = SUB_DIR;
2412
+ exports.SpeedConverter = SpeedConverter;
2307
2413
  exports.Spinner = Spinner;
2414
+ exports.TIME_ALIASES = TIME_ALIASES;
2415
+ exports.TIME_FACTORS = TIME_FACTORS;
2416
+ exports.TimeConverter = TimeConverter;
2308
2417
  exports.YEAR = YEAR;
2309
2418
  exports.YEAR_IN_S = YEAR_IN_S;
2310
2419
  exports.ZEPTOSECOND = ZEPTOSECOND;
@@ -2319,6 +2428,8 @@ exports.assure_number = assure_number;
2319
2428
  exports.assure_string = assure_string;
2320
2429
  exports.callStorage = callStorage;
2321
2430
  exports.callWindowMethod = callWindowMethod;
2431
+ exports.canonDist = canonDist;
2432
+ exports.canonTime = canonTime;
2322
2433
  exports.capitalize = capitalize;
2323
2434
  exports.capitalize_str = capitalize_str;
2324
2435
  exports.checkResponse = checkResponse;
@@ -2326,10 +2437,14 @@ exports.cleanArray = cleanArray;
2326
2437
  exports.cleanText = cleanText;
2327
2438
  exports.confirmType = confirmType;
2328
2439
  exports.confirm_type = confirm_type;
2440
+ exports.convertDistance = convertDistance;
2441
+ exports.convertSpeed = convertSpeed;
2442
+ exports.convertTime = convertTime;
2329
2443
  exports.create_list_string = create_list_string;
2330
2444
  exports.currentUsername = currentUsername;
2331
2445
  exports.currentUsernames = currentUsernames;
2332
2446
  exports.decodeJwt = decodeJwt;
2447
+ exports.distanceToMeters = distanceToMeters;
2333
2448
  exports.eatAll = eatAll;
2334
2449
  exports.eatEnd = eatEnd;
2335
2450
  exports.eatInner = eatInner;
@@ -2346,9 +2461,11 @@ exports.exponential = exponential;
2346
2461
  exports.fetchIndexHtml = fetchIndexHtml;
2347
2462
  exports.fetchIndexHtmlContainer = fetchIndexHtmlContainer;
2348
2463
  exports.fetchIt = fetchIt;
2464
+ exports.fmt = fmt;
2349
2465
  exports.formatNumber = formatNumber;
2350
2466
  exports.fromMeters = fromMeters;
2351
2467
  exports.fromMps = fromMps;
2468
+ exports.fromSeconds = fromSeconds;
2352
2469
  exports.geAuthsUtilsDirectory = geAuthsUtilsDirectory;
2353
2470
  exports.geBackupsUtilsDirectory = geBackupsUtilsDirectory;
2354
2471
  exports.geConstantsUtilsDirectory = geConstantsUtilsDirectory;
@@ -2416,11 +2533,13 @@ exports.get_keyword_string = get_keyword_string;
2416
2533
  exports.get_media_exts = get_media_exts;
2417
2534
  exports.get_media_map = get_media_map;
2418
2535
  exports.get_mime_type = get_mime_type;
2536
+ exports.get_relative_path = get_relative_path;
2419
2537
  exports.get_splitext = get_splitext;
2420
2538
  exports.get_window = get_window;
2421
2539
  exports.get_window_location = get_window_location;
2422
2540
  exports.get_window_parts = get_window_parts;
2423
2541
  exports.get_window_pathname = get_window_pathname;
2542
+ exports.isFiniteNum = isFiniteNum;
2424
2543
  exports.isLoggedIn = isLoggedIn;
2425
2544
  exports.isMediaType = isMediaType;
2426
2545
  exports.isNum = isNum;
@@ -2431,6 +2550,8 @@ exports.is_media_type = is_media_type;
2431
2550
  exports.loadConfig = loadConfig;
2432
2551
  exports.make_path = make_path;
2433
2552
  exports.make_sanitized_path = make_sanitized_path;
2553
+ exports.metersToDistance = metersToDistance;
2554
+ exports.mpsToSpeed = mpsToSpeed;
2434
2555
  exports.normalizeUrl = normalizeUrl;
2435
2556
  exports.parseResult = parseResult;
2436
2557
  exports.path_to_url = path_to_url;
@@ -2445,7 +2566,10 @@ exports.safeMultiply = safeMultiply;
2445
2566
  exports.safeNums = safeNums;
2446
2567
  exports.safeStorage = safeStorage;
2447
2568
  exports.sanitizeFilename = sanitizeFilename;
2569
+ exports.secondsToTime = secondsToTime;
2570
+ exports.speedToMps = speedToMps;
2448
2571
  exports.stripPrefixes = stripPrefixes;
2572
+ exports.timeToSeconds = timeToSeconds;
2449
2573
  exports.toMeters = toMeters;
2450
2574
  exports.toSeconds = toSeconds;
2451
2575
  exports.truncateString = truncateString;