@putkoff/abstract-utilities 1.0.31 → 1.0.34

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/esm/index.js CHANGED
@@ -2068,7 +2068,6 @@ function exponential(i, k) {
2068
2068
  return i * (10 ** (k));
2069
2069
  }
2070
2070
 
2071
- // Time
2072
2071
  const SECOND = 1;
2073
2072
  const ZEPTOSECOND = exponential(SECOND, -21);
2074
2073
  const ATTOSECOND = exponential(SECOND, -18);
@@ -2092,66 +2091,147 @@ const SECONDS_PER_DAY = DAY;
2092
2091
  const PI = Math.PI;
2093
2092
  const PI2 = 2 * PI;
2094
2093
  // Distance
2095
- const M_IN_KM = 1000;
2096
- const M_IN_MI = 1609.34;
2097
- const M_IN_FT = 0.3048;
2098
- const KM_IN_M = 1 / M_IN_KM;
2099
- const MI_IN_M = 1 / M_IN_MI;
2100
- const FT_IN_M = 1 / M_IN_FT;
2094
+ const METERS_PER_KM = 1000;
2095
+ const METERS_PER_MILE = 1609.34;
2096
+ const METERS_PER_FOOT = 0.3048;
2097
+ const KMS_PER_METER = 1 / METERS_PER_KM;
2098
+ const MILES_PER_METER = 1 / METERS_PER_MILE;
2099
+ const FEET_PER_METER = 1 / METERS_PER_FOOT;
2101
2100
  const MIN_IN_S = 1 / MINUTE;
2102
2101
  const HOUR_IN_S = 1 / HOUR;
2103
2102
  const DAY_IN_S = 1 / DAY;
2104
2103
  const YEAR_IN_S = 1 / YEAR;
2105
2104
  const MONTH_IN_S = 1 / MONTH;
2106
- const MiPerH_TO_MPerS = M_IN_MI * HOUR_IN_S;
2105
+ const MiPerH_TO_MPerS = METERS_PER_MILE * HOUR_IN_S;
2107
2106
  const MPerS_TO_MiPerH = 1 / MiPerH_TO_MPerS;
2108
2107
 
2109
- // Conversion helpers
2110
- const toMeters = (v, unit) => {
2111
- switch (unit) {
2112
- case 'km': return v * M_IN_KM;
2113
- case 'mi': return v * M_IN_MI;
2114
- case 'ft': return v * M_IN_FT;
2115
- default: return v; // meters
2116
- }
2108
+ // conversions.ts
2109
+ /*───────────────────────────────────────────────────────────────
2110
+ 🧭 CANONICAL MAPPINGS
2111
+ ───────────────────────────────────────────────────────────────*/
2112
+ const DIST_ALIASES = {
2113
+ m: "m", meter: "m", meters: "m",
2114
+ km: "km", kms: "km", kilometer: "km", kilometers: "km",
2115
+ mi: "mi", mile: "mi", miles: "mi",
2116
+ ft: "ft", f: "ft", foot: "ft", feet: "ft",
2117
2117
  };
2118
- const toSeconds = (v, unit) => {
2119
- switch (unit) {
2120
- case 'min': return v * MINUTE;
2121
- case 'h': return v * HOUR;
2122
- case 'day': return v * DAY;
2123
- default: return v;
2124
- }
2118
+ const TIME_ALIASES = {
2119
+ s: "s", sec: "s", second: "s", seconds: "s",
2120
+ min: "min", m: "min", minute: "min", minutes: "min",
2121
+ h: "h", hr: "h", hour: "h", hours: "h",
2122
+ day: "day", d: "day", days: "day",
2125
2123
  };
2126
- const fromMeters = (d, unit) => {
2127
- switch (unit) {
2128
- case 'km': return d / M_IN_KM;
2129
- case 'mi': return d / M_IN_MI;
2130
- case 'ft': return d / M_IN_FT;
2131
- default: return d; // meters
2132
- }
2124
+ const DIST_FACTORS = {
2125
+ m: 1,
2126
+ km: METERS_PER_KM,
2127
+ mi: METERS_PER_MILE,
2128
+ ft: METERS_PER_FOOT,
2133
2129
  };
2134
- const velocityToMs = (value, unit) => {
2135
- switch (unit) {
2136
- case 'km/s': return value * M_IN_KM;
2137
- case 'mph': return value * MiPerH_TO_MPerS; // 1 mph = 0.44704 m/s
2138
- case 'ft/s': return value * M_IN_FT; // 1 ft/s = 0.3048 m/s
2139
- default: return value; // m/s
2140
- }
2130
+ const TIME_FACTORS = {
2131
+ s: 1,
2132
+ min: MINUTE,
2133
+ h: HOUR,
2134
+ day: DAY,
2141
2135
  };
2142
- const velocityFromMs = (value, unit) => {
2143
- switch (unit) {
2144
- case 'km/s': return value * KM_IN_M;
2145
- case 'mph': return value * MPerS_TO_MiPerH;
2146
- case 'ft/s': return value * FT_IN_M;
2147
- default: return value;
2148
- }
2136
+ /*───────────────────────────────────────────────────────────────
2137
+ 🔍 CANONICALIZATION HELPERS
2138
+ ───────────────────────────────────────────────────────────────*/
2139
+ function canonDist(u) {
2140
+ const key = (u !== null && u !== void 0 ? u : "m").toString().toLowerCase();
2141
+ const canon = DIST_ALIASES[key];
2142
+ if (!canon)
2143
+ throw new Error(`Unknown distance unit: ${u}`);
2144
+ return canon;
2145
+ }
2146
+ function canonTime(u) {
2147
+ const key = (u !== null && u !== void 0 ? u : "s").toString().toLowerCase();
2148
+ const canon = TIME_ALIASES[key];
2149
+ if (!canon)
2150
+ throw new Error(`Unknown time unit: ${u}`);
2151
+ return canon;
2152
+ }
2153
+ /*───────────────────────────────────────────────────────────────
2154
+ ⚖️ NORMALIZATION HELPERS
2155
+ ───────────────────────────────────────────────────────────────*/
2156
+ function distanceToMeters(d, unit) {
2157
+ const u = canonDist(unit);
2158
+ return safeMultiply(d, DIST_FACTORS[u]);
2159
+ }
2160
+ function metersToDistance(v, unit) {
2161
+ const u = canonDist(unit);
2162
+ return safeDivide(v, DIST_FACTORS[u]);
2163
+ }
2164
+ function timeToSeconds(t, unit) {
2165
+ const u = canonTime(unit);
2166
+ return safeMultiply(t, TIME_FACTORS[u]);
2167
+ }
2168
+ function secondsToTime(v, unit) {
2169
+ const u = canonTime(unit);
2170
+ return safeDivide(v, TIME_FACTORS[u]);
2171
+ }
2172
+ /*───────────────────────────────────────────────────────────────
2173
+ 🚀 SPEED CONVERSIONS (normalize / unnormalize)
2174
+ ───────────────────────────────────────────────────────────────*/
2175
+ function speedToMps(v, distUnit, timeUnit) {
2176
+ const du = canonDist(distUnit);
2177
+ const tu = canonTime(timeUnit);
2178
+ return v * (DIST_FACTORS[du] / TIME_FACTORS[tu]);
2179
+ }
2180
+ function mpsToSpeed(vMps, distUnit, timeUnit) {
2181
+ const du = canonDist(distUnit);
2182
+ const tu = canonTime(timeUnit);
2183
+ return vMps * (TIME_FACTORS[tu] / DIST_FACTORS[du]);
2184
+ }
2185
+ /*───────────────────────────────────────────────────────────────
2186
+ 🎯 UNIVERSAL CONVERTERS
2187
+ ───────────────────────────────────────────────────────────────*/
2188
+ function convertDistance({ d, fromDist, toDist, vOnly = true, }) {
2189
+ const m = distanceToMeters(d, fromDist);
2190
+ const D = canonDist(toDist !== null && toDist !== void 0 ? toDist : "m");
2191
+ const out = metersToDistance(m, D);
2192
+ return vOnly ? out : { d: out, D };
2193
+ }
2194
+ function convertTime({ t, fromTime, toTime, vOnly = true, }) {
2195
+ const sec = timeToSeconds(t, fromTime);
2196
+ const T = canonTime(toTime !== null && toTime !== void 0 ? toTime : "s");
2197
+ const out = secondsToTime(sec, T);
2198
+ return vOnly ? out : { t: out, T };
2199
+ }
2200
+ function convertSpeed({ v, fromDist, fromTime, toDist, toTime, vOnly = true, }) {
2201
+ const mps = speedToMps(v, fromDist, fromTime);
2202
+ const d = canonDist(toDist !== null && toDist !== void 0 ? toDist : "m");
2203
+ const t = canonTime(toTime !== null && toTime !== void 0 ? toTime : "s");
2204
+ const out = mpsToSpeed(mps, d, t);
2205
+ return vOnly ? out : { v: out, d, t };
2206
+ }
2207
+ const DistanceConverter = {
2208
+ normalize: distanceToMeters,
2209
+ unnormalize: metersToDistance,
2210
+ };
2211
+ const TimeConverter = {
2212
+ normalize: timeToSeconds,
2213
+ unnormalize: secondsToTime,
2149
2214
  };
2150
- const fromMps = (v, dist_unit, time_unit) => {
2151
- const dist_conv = toMeters(1, dist_unit);
2152
- const time_conv = toSeconds(1, time_unit);
2153
- return v * (time_conv / dist_conv);
2215
+ const SpeedConverter = {
2216
+ normalize: (v, [du, tu]) => speedToMps(v, du, tu),
2217
+ unnormalize: (v, [du, tu]) => mpsToSpeed(v, du, tu),
2154
2218
  };
2219
+ /*───────────────────────────────────────────────────────────────
2220
+ 🧩 COMPATIBILITY WRAPPERS (legacy aliases)
2221
+ ───────────────────────────────────────────────────────────────*/
2222
+ const toMeters = distanceToMeters;
2223
+ const fromMeters = metersToDistance;
2224
+ const toSeconds = timeToSeconds;
2225
+ const fromSeconds = secondsToTime;
2226
+ const velocityToMs = (value, unit) => speedToMps(value, unit, "s");
2227
+ const velocityFromMs = (value, unit) => mpsToSpeed(value, unit, "s");
2228
+ /** Non-canonical helper for arbitrary rate conversion, e.g. ft/day → m/s */
2229
+ const fromMps = (v, dist_unit, time_unit) => mpsToSpeed(v, dist_unit, time_unit);
2230
+ /*───────────────────────────────────────────────────────────────
2231
+ 📊 UTILITIES
2232
+ ───────────────────────────────────────────────────────────────*/
2233
+ const isFiniteNum = (x) => Number.isFinite(x);
2234
+ const fmt = (n, digits = 2) => isFiniteNum(n) ? n.toFixed(digits) : "N/A";
2155
2235
 
2156
2236
  function Button(_a) {
2157
2237
  var { children, color = 'gray', variant = 'default', className = '' } = _a, rest = __rest(_a, ["children", "color", "variant", "className"]);
@@ -2296,5 +2376,5 @@ function get_keyword_string(keywords) {
2296
2376
  return allString;
2297
2377
  }
2298
2378
 
2299
- export { API_PREFIX, ATTOSECOND, BASE_URL, Button, CENTISECOND, Checkbox, DAY, DAY_IN_S, DECISECOND, DEV_PREFIX, DOMAIN_NAME, FEMTOSECOND, FT_IN_M, HOUR, HOUR_IN_S, Input, KM_IN_M, MEDIA_TYPES, MICROSECOND, MILISECOND, MIME_TYPES, MINUTE, MIN_IN_S, MI_IN_M, MONTH, MONTH_IN_S, MPerS_TO_MiPerH, M_IN_FT, M_IN_KM, M_IN_MI, MiPerH_TO_MPerS, NANOSECOND, PI, PI2, PICOSECOND, PROD_PREFIX, PROTOCOL, SECOND, SECONDS_PER_DAY, SECONDS_PER_HOUR, SECONDS_PER_MINUTE, SUB_DIR, Spinner, YEAR, YEAR_IN_S, ZEPTOSECOND, alertit, assureArray, assureList, assureNumber, assureString, assure_array, assure_list, assure_number, assure_string, callStorage, callWindowMethod, capitalize, capitalize_str, checkResponse, cleanArray, cleanText, confirmType, confirm_type, create_list_string, currentUsername, currentUsernames, decodeJwt, eatAll, eatEnd, eatInner, eatOuter, ensureArray, ensureList, ensureNumber, ensureString, ensure_array, ensure_list, ensure_number, ensure_string, exponential, fetchIndexHtml, fetchIndexHtmlContainer, fetchIt, formatNumber, fromMeters, fromMps, geAuthsUtilsDirectory, geBackupsUtilsDirectory, geConstantsUtilsDirectory, geEnvUtilsDirectory, geFetchUtilsDirectory, geFileUtilsDirectory, gePathUtilsDirectory, geStaticDirectory, geStringUtilsDirectory, geTypeUtilsDirectory, get, getAbsDir, getAbsPath, getAllFileTypes, getAllFileTypesSync, getAlphaNum, getAlphas, getAuthorizationHeader, getBaseDir, getBody, getChar, getCleanArray, getComponentsUtilsDirectory, getConfig, getConfigContent, getConfigVar, getDbConfigsPath, getDistDir, getDocumentProp, getEnvDir, getEnvPath, getFetchVars, getFunctionsDir, getFunctionsUtilsDirectory, getHeaders, getHooksUtilsDirectory, getHtmlDirectory, getLibUtilsDirectory, getMediaExts, getMediaMap, getMethod, getMimeType, getNums, getPublicDir, getResult, getSafeDocument, getSafeLocalStorage, getSafeWindow, getSchemasDirPath, getSchemasPath, getSrcDir, getSubstring, getToken, getWindowHost, getWindowProp, get_all_file_types, get_basename, get_dirname, get_extname, get_filename, get_full_path, get_full_url, get_key_value, get_keyword_string, get_media_exts, get_media_map, get_mime_type, get_relative_path, get_splitext, get_window, get_window_location, get_window_parts, get_window_pathname, isLoggedIn, isMediaType, isNum, isStrInString, isTokenExpired, isType, is_media_type, loadConfig, make_path, make_sanitized_path, normalizeUrl, parseResult, path_to_url, processKeywords, readJsonFile, removeToken, requireToken, roundPercentage, safeDivide, safeGlobalProp, safeMultiply, safeNums, safeStorage, sanitizeFilename, stripPrefixes, toMeters, toSeconds, truncateString, tryParse, urlJoin, url_to_path, velocityFromMs, velocityToMs };
2379
+ export { API_PREFIX, ATTOSECOND, BASE_URL, Button, CENTISECOND, Checkbox, DAY, DAY_IN_S, DECISECOND, DEV_PREFIX, DIST_ALIASES, DIST_FACTORS, DOMAIN_NAME, DistanceConverter, FEET_PER_METER, FEMTOSECOND, HOUR, HOUR_IN_S, Input, KMS_PER_METER, MEDIA_TYPES, METERS_PER_FOOT, METERS_PER_KM, METERS_PER_MILE, MICROSECOND, MILES_PER_METER, MILISECOND, MIME_TYPES, MINUTE, MIN_IN_S, MONTH, MONTH_IN_S, MPerS_TO_MiPerH, MiPerH_TO_MPerS, NANOSECOND, PI, PI2, PICOSECOND, PROD_PREFIX, PROTOCOL, SECOND, SECONDS_PER_DAY, SECONDS_PER_HOUR, SECONDS_PER_MINUTE, SUB_DIR, SpeedConverter, Spinner, TIME_ALIASES, TIME_FACTORS, TimeConverter, YEAR, YEAR_IN_S, ZEPTOSECOND, alertit, assureArray, assureList, assureNumber, assureString, assure_array, assure_list, assure_number, assure_string, callStorage, callWindowMethod, canonDist, canonTime, capitalize, capitalize_str, checkResponse, cleanArray, cleanText, confirmType, confirm_type, convertDistance, convertSpeed, convertTime, create_list_string, currentUsername, currentUsernames, decodeJwt, distanceToMeters, eatAll, eatEnd, eatInner, eatOuter, ensureArray, ensureList, ensureNumber, ensureString, ensure_array, ensure_list, ensure_number, ensure_string, exponential, fetchIndexHtml, fetchIndexHtmlContainer, fetchIt, fmt, formatNumber, fromMeters, fromMps, fromSeconds, geAuthsUtilsDirectory, geBackupsUtilsDirectory, geConstantsUtilsDirectory, geEnvUtilsDirectory, geFetchUtilsDirectory, geFileUtilsDirectory, gePathUtilsDirectory, geStaticDirectory, geStringUtilsDirectory, geTypeUtilsDirectory, get, getAbsDir, getAbsPath, getAllFileTypes, getAllFileTypesSync, getAlphaNum, getAlphas, getAuthorizationHeader, getBaseDir, getBody, getChar, getCleanArray, getComponentsUtilsDirectory, getConfig, getConfigContent, getConfigVar, getDbConfigsPath, getDistDir, getDocumentProp, getEnvDir, getEnvPath, getFetchVars, getFunctionsDir, getFunctionsUtilsDirectory, getHeaders, getHooksUtilsDirectory, getHtmlDirectory, getLibUtilsDirectory, getMediaExts, getMediaMap, getMethod, getMimeType, getNums, getPublicDir, getResult, getSafeDocument, getSafeLocalStorage, getSafeWindow, getSchemasDirPath, getSchemasPath, getSrcDir, getSubstring, getToken, getWindowHost, getWindowProp, get_all_file_types, get_basename, get_dirname, get_extname, get_filename, get_full_path, get_full_url, get_key_value, get_keyword_string, get_media_exts, get_media_map, get_mime_type, get_relative_path, get_splitext, get_window, get_window_location, get_window_parts, get_window_pathname, isFiniteNum, isLoggedIn, isMediaType, isNum, isStrInString, isTokenExpired, isType, is_media_type, loadConfig, make_path, make_sanitized_path, metersToDistance, mpsToSpeed, normalizeUrl, parseResult, path_to_url, processKeywords, readJsonFile, removeToken, requireToken, roundPercentage, safeDivide, safeGlobalProp, safeMultiply, safeNums, safeStorage, sanitizeFilename, secondsToTime, speedToMps, stripPrefixes, timeToSeconds, toMeters, toSeconds, truncateString, tryParse, urlJoin, url_to_path, velocityFromMs, velocityToMs };
2300
2380
  //# sourceMappingURL=index.js.map