inferred-types 0.54.3 → 0.54.4

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.
@@ -76,6 +76,7 @@ __export(src_exports, {
76
76
  getToday: () => getToday,
77
77
  getTokenKind: () => getTokenKind,
78
78
  getTomorrow: () => getTomorrow,
79
+ getTypeSubtype: () => getTypeSubtype,
79
80
  getUrlPath: () => getUrlPath,
80
81
  getUrlPort: () => getUrlPort,
81
82
  getUrlProtocol: () => getUrlProtocol,
@@ -316,6 +317,7 @@ __export(src_exports, {
316
317
  isTupleToken: () => isTupleToken,
317
318
  isTurkishNewsUrl: () => isTurkishNewsUrl,
318
319
  isTypeOf: () => isTypeOf,
320
+ isTypeSubtype: () => isTypeSubtype,
319
321
  isTypeToken: () => isTypeToken,
320
322
  isTypeTokenKind: () => isTypeTokenKind,
321
323
  isTypeTuple: () => isTypeTuple,
@@ -2919,235 +2921,6 @@ function ensureTrailing(content, ensure) {
2919
2921
  );
2920
2922
  }
2921
2923
 
2922
- // src/literals/identity.ts
2923
- function identity(...values) {
2924
- return values.length === 1 ? values[0] : values.length === 0 ? void 0 : values;
2925
- }
2926
-
2927
- // src/literals/ifLowercase.ts
2928
- function ifLowercaseChar(ch, callbackForMatch, callbackForNoMatch) {
2929
- if (ch.length !== 1) {
2930
- throw new Error(`call to ifUppercaseChar received ${ch.length} characters but is only valid when one character is passed in!`);
2931
- }
2932
- return LOWER_ALPHA_CHARS.includes(ch) ? callbackForMatch(ch) : callbackForNoMatch(ch);
2933
- }
2934
-
2935
- // src/literals/ifUppercase.ts
2936
- function ifUppercaseChar(ch, callbackForMatch, callbackForNoMatch) {
2937
- if (ch.length !== 1) {
2938
- throw new Error(`Invalid string length passed to ifUppercaseChar(ch); this function requires a single character but ${ch.length} were received`);
2939
- }
2940
- return LOWER_ALPHA_CHARS.includes(ch) ? callbackForMatch(ch) : callbackForNoMatch(ch);
2941
- }
2942
-
2943
- // src/literals/infer.ts
2944
- function parseTemplate(template) {
2945
- const pattern = /\{\{\s*infer\s+([A-Za-z_]\w*)\s*(?:as\s+(string|number|boolean)\s*)?\}\}/g;
2946
- let lastIndex = 0;
2947
- let match;
2948
- const segments = [];
2949
- do {
2950
- match = pattern.exec(template);
2951
- if (match) {
2952
- const [fullMatch, varName, asType2] = match;
2953
- const staticPart = template.slice(lastIndex, match.index);
2954
- if (staticPart) {
2955
- segments.push({ dynamic: false, text: staticPart });
2956
- }
2957
- segments.push({
2958
- dynamic: true,
2959
- varName,
2960
- type: asType2 ? asType2 : "string"
2961
- });
2962
- lastIndex = match.index + fullMatch.length;
2963
- }
2964
- } while (match);
2965
- const remainder = template.slice(lastIndex);
2966
- if (remainder) {
2967
- segments.push({ dynamic: false, text: remainder });
2968
- }
2969
- return segments;
2970
- }
2971
- function escapeRegex(str) {
2972
- return str.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
2973
- }
2974
- function buildRegexPattern(segments) {
2975
- let regexStr = "^";
2976
- for (const seg of segments) {
2977
- if (!seg.dynamic) {
2978
- regexStr += escapeRegex(seg.text);
2979
- } else {
2980
- switch (seg.type) {
2981
- case "string":
2982
- regexStr += `(?<${seg.varName}>.*?)`;
2983
- break;
2984
- case "number":
2985
- regexStr += `(?<${seg.varName}>\\d+)`;
2986
- break;
2987
- case "boolean":
2988
- regexStr += `(?<${seg.varName}>(?:true|false))`;
2989
- break;
2990
- }
2991
- }
2992
- }
2993
- regexStr += "$";
2994
- return new RegExp(regexStr, "s");
2995
- }
2996
- function convertValue(type, value) {
2997
- switch (type) {
2998
- case "string":
2999
- return value;
3000
- case "number":
3001
- return Number(value);
3002
- case "boolean":
3003
- return value === "true";
3004
- }
3005
- }
3006
- function matchTemplate(inference, test) {
3007
- const segments = parseTemplate(inference);
3008
- const regex = buildRegexPattern(segments);
3009
- const match = test.match(regex);
3010
- if (!match)
3011
- return false;
3012
- const result2 = {};
3013
- for (const seg of segments) {
3014
- if (seg.dynamic) {
3015
- const rawVal = match.groups?.[seg.varName];
3016
- if (rawVal === void 0)
3017
- return false;
3018
- result2[seg.varName.toLowerCase()] = convertValue(seg.type, rawVal);
3019
- }
3020
- }
3021
- return result2;
3022
- }
3023
- function infer(inference) {
3024
- return (test) => {
3025
- return matchTemplate(inference, test);
3026
- };
3027
- }
3028
-
3029
- // src/literals/literal.ts
3030
- function idLiteral(o) {
3031
- return { ...o, id: o.id };
3032
- }
3033
- function nameLiteral(o) {
3034
- return o;
3035
- }
3036
- function kindLiteral(o) {
3037
- return o;
3038
- }
3039
- function idTypeGuard(_o) {
3040
- return true;
3041
- }
3042
- function literal(obj) {
3043
- return obj;
3044
- }
3045
-
3046
- // src/literals/lowercase.ts
3047
- function lowercase(str) {
3048
- return str.toLowerCase();
3049
- }
3050
-
3051
- // src/literals/narrow.ts
3052
- function narrow(...values) {
3053
- return values.length === 1 ? values[0] : values;
3054
- }
3055
-
3056
- // src/literals/pathJoin.ts
3057
- function pathJoin(...segments) {
3058
- const clean_path = segments.map((i) => stripTrailing(stripLeading(i, "/"), "/")).join("/");
3059
- const original_path = segments.join("/");
3060
- const pre = original_path.startsWith("/") ? "/" : "";
3061
- const post = original_path.endsWith("/") ? "/" : "";
3062
- return `${pre}${clean_path}${post}`;
3063
- }
3064
-
3065
- // src/literals/phone/asPhoneNumber.ts
3066
- var asPhoneFormat = () => `NOT IMPLEMENTED`;
3067
-
3068
- // src/literals/phone/getPhoneCountryCode.ts
3069
- function getPhoneCountryCode(phone) {
3070
- return phone.trim().startsWith("+") || phone.trim().startsWith("00") ? retainWhile(
3071
- stripLeading(stripLeading(phone.trim(), "+"), "00"),
3072
- ...NUMERIC_CHAR
3073
- ) : "";
3074
- }
3075
-
3076
- // src/literals/phone/removePhoneCountryCode.ts
3077
- function removePhoneCountryCode(phone) {
3078
- const countryCode = getPhoneCountryCode(phone);
3079
- return countryCode !== "" ? stripLeading(stripLeading(
3080
- phone.trim(),
3081
- "+",
3082
- "00"
3083
- ), countryCode).trim() : phone.trim();
3084
- }
3085
-
3086
- // src/literals/pluralize.ts
3087
- var isException = (word) => Object.keys(PLURAL_EXCEPTIONS).includes(word);
3088
- function endingIn(word, postfix) {
3089
- switch (postfix) {
3090
- case "is":
3091
- return word.endsWith(postfix) ? `${word}es` : void 0;
3092
- case "singular-noun":
3093
- return SINGULAR_NOUN_ENDINGS.some((i) => word.endsWith(i)) ? split(word).every((i) => [...ALPHA_CHARS].includes(i)) ? `${word}es` : void 0 : void 0;
3094
- case "f":
3095
- return word.endsWith("f") ? `${stripTrailing(word, "f")}ves` : word.endsWith("fe") ? `${stripTrailing(word, "fe")}ves` : void 0;
3096
- case "y":
3097
- return word.endsWith("y") ? `${stripTrailing(word, "y")}ies` : void 0;
3098
- default:
3099
- throw new Error(`endingIn received "${postfix}" as a postfix but this ending is not known!`);
3100
- }
3101
- }
3102
- function pluralize(word) {
3103
- const right = rightWhitespace(word);
3104
- const w = word.trimEnd();
3105
- const result2 = isException(w) ? PLURAL_EXCEPTIONS[w] : endingIn(w, "is") || endingIn(w, "singular-noun") || endingIn(w, "f") || endingIn(w, "y") || `${w}s`;
3106
- return `${result2}${right}`;
3107
- }
3108
-
3109
- // src/literals/retainAfter.ts
3110
- function retainAfter(content, ...find2) {
3111
- const idx = Math.min(
3112
- ...find2.map((i) => content.indexOf(i)).filter((i) => i > -1)
3113
- );
3114
- const min = Math.min(...find2.map((i) => i.length));
3115
- let len = Math.max(...find2.map((i) => i.length));
3116
- if (min !== len) {
3117
- if (!find2.includes(content.slice(idx, len))) {
3118
- len = min;
3119
- }
3120
- }
3121
- return idx && idx > 0 ? content.slice(idx + len) : "";
3122
- }
3123
- function retainAfterInclusive(content, ...find2) {
3124
- const minFound = Math.min(
3125
- ...find2.map((i) => content.indexOf(i)).filter((i) => i > -1)
3126
- );
3127
- return minFound > 0 ? content.slice(minFound) : "";
3128
- }
3129
-
3130
- // src/type-conversion/asChars.ts
3131
- function asChars(str) {
3132
- return str.split("");
3133
- }
3134
-
3135
- // src/literals/retainChars.ts
3136
- function retainChars(content, ...retain2) {
3137
- const chars = asChars(content);
3138
- return chars.filter((c) => retain2.includes(c)).join("");
3139
- }
3140
-
3141
- // src/type-conversion/asRecord.ts
3142
- function asRecord(obj) {
3143
- return obj;
3144
- }
3145
-
3146
- // src/type-conversion/asString.ts
3147
- function asString(value) {
3148
- return isString(value) ? value : isNumber(value) ? `${value}` : isBoolean(value) ? `${value}` : isArray(value) ? value.join("") : String(value);
3149
- }
3150
-
3151
2924
  // src/type-guards/isFunction.ts
3152
2925
  function isFunction(value) {
3153
2926
  return typeof value === "function";
@@ -3479,30 +3252,214 @@ function hasKeys(...props) {
3479
3252
  };
3480
3253
  }
3481
3254
 
3482
- // src/type-guards/hasWhitespace.ts
3483
- function hasWhiteSpace(val) {
3484
- return isString(val) && asChars(val).some((c) => WHITESPACE_CHARS.includes(c));
3485
- }
3486
-
3487
- // src/type-guards/higher-order/endsWith.ts
3488
- function endsWith(endingIn2) {
3489
- return (val) => {
3490
- return isString(val) ? !!val.endsWith(endingIn2) : isNumber(val) ? !!String(val).endsWith(endingIn2) : false;
3491
- };
3255
+ // src/type-conversion/asChars.ts
3256
+ function asChars(str) {
3257
+ return str.split("");
3492
3258
  }
3493
3259
 
3494
- // src/type-guards/higher-order/isEqual.ts
3495
- function isEqual(base) {
3496
- return (value) => isSameTypeOf(base)(value) ? value === base : false;
3260
+ // src/type-conversion/asRecord.ts
3261
+ function asRecord(obj) {
3262
+ return obj;
3497
3263
  }
3498
3264
 
3499
- // src/type-guards/higher-order/isLength.ts
3500
- function isLength(value, len) {
3501
- return isArray(value) ? !!isEqual(value.length)(len) : isString(value) ? !!isEqual(value.length)(len) : isObject(value) ? !!isEqual(keysOf(value))(len) : false;
3265
+ // src/type-conversion/asString.ts
3266
+ function asString(value) {
3267
+ return isString(value) ? value : isNumber(value) ? `${value}` : isBoolean(value) ? `${value}` : isArray(value) ? value.join("") : String(value);
3502
3268
  }
3503
3269
 
3504
- // src/type-guards/higher-order/isSameTypeOf.ts
3505
- function isSameTypeOf(base) {
3270
+ // src/type-conversion/csv.ts
3271
+ function csv(csv2, format = `string-numeric-tuple`) {
3272
+ const tuple3 = [];
3273
+ csv2.split(/,\s?/).forEach((v) => {
3274
+ tuple3.push(
3275
+ format === "string-numeric-tuple" ? isNumberLike(v) ? Number(v) : v : format === "json-tuple" ? isNumberLike(v) ? Number(v) : v === "true" ? true : v === "false" ? false : `"${v}"` : format === "string-tuple" ? `${v}` : Never
3276
+ );
3277
+ });
3278
+ return tuple3;
3279
+ }
3280
+
3281
+ // src/type-conversion/intersect.ts
3282
+ function intersect(value, _intersectedWith) {
3283
+ return value;
3284
+ }
3285
+
3286
+ // src/literals/stripTrailing.ts
3287
+ function stripTrailing(content, ...strip2) {
3288
+ let output = String(content);
3289
+ for (const s of strip2) {
3290
+ if (output.endsWith(String(s))) {
3291
+ output = output.slice(0, -1 * String(s).length);
3292
+ }
3293
+ }
3294
+ return isNumber(content) ? Number(output) : output;
3295
+ }
3296
+
3297
+ // src/type-conversion/ip6GroupExpansion.ts
3298
+ function ip6GroupExpansion(ip) {
3299
+ return stripTrailing(ip.replaceAll("::", ":0000:"), ":");
3300
+ }
3301
+
3302
+ // src/type-conversion/json.ts
3303
+ function jsonValue(val) {
3304
+ return isNumberLike(val) ? Number(val) : val === "true" ? true : val === "false" ? false : `"${val}"`;
3305
+ }
3306
+ function jsonValues(...val) {
3307
+ return val.map((i) => jsonValue(i));
3308
+ }
3309
+
3310
+ // src/type-conversion/lookupCountry.ts
3311
+ function lookupAlpha2Code(code, prop) {
3312
+ const found = ISO3166_1.find((i) => i.alpha2 === code);
3313
+ return found ? found[prop] : void 0;
3314
+ }
3315
+ function lookupAlpha3Code(code, prop) {
3316
+ const found = ISO3166_1.find((i) => i.alpha3 === code);
3317
+ return found ? found[prop] : void 0;
3318
+ }
3319
+ function lookupName(name, prop) {
3320
+ const found = ISO3166_1.find((i) => i.name === name);
3321
+ return found ? found[prop] : void 0;
3322
+ }
3323
+ function lookupNumericCode(code, prop) {
3324
+ let num = isNumber(code) ? `${code}` : code;
3325
+ if (num.length === 1) {
3326
+ num = `00${num}`;
3327
+ } else if (num.length === 2) {
3328
+ num = `0${num}`;
3329
+ }
3330
+ const found = ISO3166_1.find((i) => i.countryCode === num);
3331
+ return found ? found[prop] : void 0;
3332
+ }
3333
+ function lookupCountryName(code) {
3334
+ const uc = uppercase(code);
3335
+ return isNumberLike(code) ? lookupNumericCode(code, "name") : isIso3166Alpha2(uc) ? lookupAlpha2Code(uc, "name") : isIso3166Alpha3(uc) ? lookupAlpha3Code(uc, "name") : void 0;
3336
+ }
3337
+ function lookupCountryAlpha2(code) {
3338
+ const uc = uppercase(code);
3339
+ return isNumberLike(code) ? lookupNumericCode(code, "alpha2") : isIso3166Alpha2(uc) ? lookupAlpha2Code(uc, "alpha2") : isIso3166Alpha3(uc) ? lookupAlpha3Code(uc, "alpha2") : isIso3166CountryName(code) ? lookupName(code, "alpha2") : void 0;
3340
+ }
3341
+ function lookupCountryAlpha3(token) {
3342
+ const uc = uppercase(token);
3343
+ return isNumberLike(token) ? lookupNumericCode(token, "alpha3") : isIso3166Alpha2(uc) ? lookupAlpha2Code(uc, "alpha3") : isIso3166Alpha3(uc) ? lookupAlpha3Code(uc, "alpha3") : isIso3166CountryName(token) ? lookupName(token, "alpha3") : void 0;
3344
+ }
3345
+ function lookupCountryCode(token) {
3346
+ const uc = uppercase(token);
3347
+ return isNumberLike(token) ? lookupNumericCode(token, "countryCode") : isIso3166Alpha2(uc) ? lookupAlpha2Code(uc, "countryCode") : isIso3166Alpha3(uc) ? lookupAlpha3Code(uc, "countryCode") : isIso3166CountryName(token) ? lookupName(token, "countryCode") : void 0;
3348
+ }
3349
+
3350
+ // src/type-conversion/mergeObjects.ts
3351
+ function mergeObjects(defVal, override) {
3352
+ const intersectingKeys = sharedKeys(defVal, override);
3353
+ const defUnique = withoutKeys(defVal, ...intersectingKeys);
3354
+ const overrideUnique = withoutKeys(defVal, ...intersectingKeys);
3355
+ const merged = {
3356
+ ...intersectingKeys.reduce(
3357
+ (acc, key) => typeof override[key] === "undefined" ? { ...acc, [key]: defVal[key] } : { ...acc, [key]: override[key] },
3358
+ {}
3359
+ ),
3360
+ ...defUnique,
3361
+ ...overrideUnique
3362
+ };
3363
+ return merged;
3364
+ }
3365
+
3366
+ // src/type-guards/isUndefined.ts
3367
+ function isUndefined(value) {
3368
+ return typeof value === "undefined";
3369
+ }
3370
+
3371
+ // src/type-conversion/mergeScalars.ts
3372
+ function mergeScalars(a, b) {
3373
+ return isUndefined(b) ? a : b;
3374
+ }
3375
+
3376
+ // src/type-conversion/mergeTuples.ts
3377
+ function mergeTuples(a, b) {
3378
+ return b.length > a.length ? b.map((v, idx) => v !== void 0 ? v : a[idx]) : [...b, ...a.slice(b.length)].map((v, idx) => v !== void 0 ? v : a[idx]);
3379
+ }
3380
+
3381
+ // src/type-conversion/never.ts
3382
+ function never(val) {
3383
+ return val;
3384
+ }
3385
+
3386
+ // src/type-conversion/optional.ts
3387
+ function optional(value) {
3388
+ return value;
3389
+ }
3390
+ function orNull(value) {
3391
+ return value;
3392
+ }
3393
+ function optionalOrNull(value) {
3394
+ return value;
3395
+ }
3396
+
3397
+ // src/type-conversion/stripParenthesis.ts
3398
+ function stripParenthesis(val) {
3399
+ return stripTrailing(stripLeading(val.trim(), "("), ")").trim();
3400
+ }
3401
+
3402
+ // src/type-conversion/toNumber.ts
3403
+ function convertScalar(val) {
3404
+ switch (typeof val) {
3405
+ case "number":
3406
+ return val;
3407
+ case "string":
3408
+ return Number(val);
3409
+ case "boolean":
3410
+ return val ? 1 : 0;
3411
+ default:
3412
+ throw new Error(`${typeof val} is an invalid scalar type to convert to a number!`);
3413
+ }
3414
+ }
3415
+ var convertList = (val) => val.map((i) => convertScalar(i));
3416
+ function toNumber(value) {
3417
+ return Array.isArray(value) ? convertList(value) : convertScalar(value);
3418
+ }
3419
+
3420
+ // src/type-conversion/tw-conversion.ts
3421
+ var MODS = TW_MODIFIERS.map((i) => `${i}:`);
3422
+ function removeTailwindModifiers(val) {
3423
+ return MODS.some((i) => val.startsWith(i)) ? removeTailwindModifiers(val.replace(MODS.find((i) => val.startsWith(i)), "")) : val;
3424
+ }
3425
+ function getTailwindModifiers(val) {
3426
+ return val.split(":").filter((i) => isTailwindModifier(i));
3427
+ }
3428
+
3429
+ // src/type-conversion/union.ts
3430
+ function union(..._options) {
3431
+ return (value) => value;
3432
+ }
3433
+
3434
+ // src/type-conversion/unionize.ts
3435
+ function unionize(value, _inUnionWith) {
3436
+ return value;
3437
+ }
3438
+
3439
+ // src/type-guards/hasWhitespace.ts
3440
+ function hasWhiteSpace(val) {
3441
+ return isString(val) && asChars(val).some((c) => WHITESPACE_CHARS.includes(c));
3442
+ }
3443
+
3444
+ // src/type-guards/higher-order/endsWith.ts
3445
+ function endsWith(endingIn2) {
3446
+ return (val) => {
3447
+ return isString(val) ? !!val.endsWith(endingIn2) : isNumber(val) ? !!String(val).endsWith(endingIn2) : false;
3448
+ };
3449
+ }
3450
+
3451
+ // src/type-guards/higher-order/isEqual.ts
3452
+ function isEqual(base) {
3453
+ return (value) => isSameTypeOf(base)(value) ? value === base : false;
3454
+ }
3455
+
3456
+ // src/type-guards/higher-order/isLength.ts
3457
+ function isLength(value, len) {
3458
+ return isArray(value) ? !!isEqual(value.length)(len) : isString(value) ? !!isEqual(value.length)(len) : isObject(value) ? !!isEqual(keysOf(value))(len) : false;
3459
+ }
3460
+
3461
+ // src/type-guards/higher-order/isSameTypeOf.ts
3462
+ function isSameTypeOf(base) {
3506
3463
  return (compare) => {
3507
3464
  return typeof base === typeof compare;
3508
3465
  };
@@ -3724,16 +3681,16 @@ function isTruthy(val) {
3724
3681
  return !FALSY_VALUES.includes(val);
3725
3682
  }
3726
3683
 
3684
+ // src/type-guards/isTypeSubtype.ts
3685
+ function isTypeSubtype(val) {
3686
+ return isString(val) && val.split("/").length === 2;
3687
+ }
3688
+
3727
3689
  // src/type-guards/isTypeTuple.ts
3728
3690
  function isTypeTuple(value) {
3729
3691
  return Array.isArray(value) && value.length === 3 && typeof value[1] === "function";
3730
3692
  }
3731
3693
 
3732
- // src/type-guards/isUndefined.ts
3733
- function isUndefined(value) {
3734
- return typeof value === "undefined";
3735
- }
3736
-
3737
3694
  // src/type-guards/isUnset.ts
3738
3695
  function isUnset(val) {
3739
3696
  return isObject(val) && val.kind === "Unset";
@@ -4383,168 +4340,230 @@ function isYouTubeVideosInPlaylist(val) {
4383
4340
  return isString(val) && (val.startsWith(`https://www.youtube.com/playlist?`) || val.startsWith(`https://youtube.com/playlist?`)) && hasUrlQueryParameter(val, "list");
4384
4341
  }
4385
4342
 
4386
- // src/type-conversion/csv.ts
4387
- function csv(csv2, format = `string-numeric-tuple`) {
4388
- const tuple3 = [];
4389
- csv2.split(/,\s?/).forEach((v) => {
4390
- tuple3.push(
4391
- format === "string-numeric-tuple" ? isNumberLike(v) ? Number(v) : v : format === "json-tuple" ? isNumberLike(v) ? Number(v) : v === "true" ? true : v === "false" ? false : `"${v}"` : format === "string-tuple" ? `${v}` : Never
4392
- );
4393
- });
4394
- return tuple3;
4343
+ // src/literals/getTypeSubtype.ts
4344
+ function getTypeSubtype(str) {
4345
+ if (isTypeSubtype(str)) {
4346
+ const [t, st] = str.split("/");
4347
+ return [t, st];
4348
+ } else {
4349
+ const err = new Error(`An invalid Type/Subtype was passed into getTypeSubtype(${str})`);
4350
+ err.name = "InvalidTypeSubtype";
4351
+ throw err;
4352
+ }
4395
4353
  }
4396
4354
 
4397
- // src/type-conversion/intersect.ts
4398
- function intersect(value, _intersectedWith) {
4399
- return value;
4355
+ // src/literals/identity.ts
4356
+ function identity(...values) {
4357
+ return values.length === 1 ? values[0] : values.length === 0 ? void 0 : values;
4400
4358
  }
4401
4359
 
4402
- // src/literals/stripTrailing.ts
4403
- function stripTrailing(content, ...strip2) {
4404
- let output = String(content);
4405
- for (const s of strip2) {
4406
- if (output.endsWith(String(s))) {
4407
- output = output.slice(0, -1 * String(s).length);
4408
- }
4360
+ // src/literals/ifLowercase.ts
4361
+ function ifLowercaseChar(ch, callbackForMatch, callbackForNoMatch) {
4362
+ if (ch.length !== 1) {
4363
+ throw new Error(`call to ifUppercaseChar received ${ch.length} characters but is only valid when one character is passed in!`);
4409
4364
  }
4410
- return isNumber(content) ? Number(output) : output;
4365
+ return LOWER_ALPHA_CHARS.includes(ch) ? callbackForMatch(ch) : callbackForNoMatch(ch);
4411
4366
  }
4412
4367
 
4413
- // src/type-conversion/ip6GroupExpansion.ts
4414
- function ip6GroupExpansion(ip) {
4415
- return stripTrailing(ip.replaceAll("::", ":0000:"), ":");
4368
+ // src/literals/ifUppercase.ts
4369
+ function ifUppercaseChar(ch, callbackForMatch, callbackForNoMatch) {
4370
+ if (ch.length !== 1) {
4371
+ throw new Error(`Invalid string length passed to ifUppercaseChar(ch); this function requires a single character but ${ch.length} were received`);
4372
+ }
4373
+ return LOWER_ALPHA_CHARS.includes(ch) ? callbackForMatch(ch) : callbackForNoMatch(ch);
4416
4374
  }
4417
4375
 
4418
- // src/type-conversion/json.ts
4419
- function jsonValue(val) {
4420
- return isNumberLike(val) ? Number(val) : val === "true" ? true : val === "false" ? false : `"${val}"`;
4421
- }
4422
- function jsonValues(...val) {
4423
- return val.map((i) => jsonValue(i));
4376
+ // src/literals/infer.ts
4377
+ function parseTemplate(template) {
4378
+ const pattern = /\{\{\s*infer\s+([A-Za-z_]\w*)\s*(?:as\s+(string|number|boolean)\s*)?\}\}/g;
4379
+ let lastIndex = 0;
4380
+ let match;
4381
+ const segments = [];
4382
+ do {
4383
+ match = pattern.exec(template);
4384
+ if (match) {
4385
+ const [fullMatch, varName, asType2] = match;
4386
+ const staticPart = template.slice(lastIndex, match.index);
4387
+ if (staticPart) {
4388
+ segments.push({ dynamic: false, text: staticPart });
4389
+ }
4390
+ segments.push({
4391
+ dynamic: true,
4392
+ varName,
4393
+ type: asType2 ? asType2 : "string"
4394
+ });
4395
+ lastIndex = match.index + fullMatch.length;
4396
+ }
4397
+ } while (match);
4398
+ const remainder = template.slice(lastIndex);
4399
+ if (remainder) {
4400
+ segments.push({ dynamic: false, text: remainder });
4401
+ }
4402
+ return segments;
4424
4403
  }
4425
-
4426
- // src/type-conversion/lookupCountry.ts
4427
- function lookupAlpha2Code(code, prop) {
4428
- const found = ISO3166_1.find((i) => i.alpha2 === code);
4429
- return found ? found[prop] : void 0;
4404
+ function escapeRegex(str) {
4405
+ return str.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
4430
4406
  }
4431
- function lookupAlpha3Code(code, prop) {
4432
- const found = ISO3166_1.find((i) => i.alpha3 === code);
4433
- return found ? found[prop] : void 0;
4407
+ function buildRegexPattern(segments) {
4408
+ let regexStr = "^";
4409
+ for (const seg of segments) {
4410
+ if (!seg.dynamic) {
4411
+ regexStr += escapeRegex(seg.text);
4412
+ } else {
4413
+ switch (seg.type) {
4414
+ case "string":
4415
+ regexStr += `(?<${seg.varName}>.*?)`;
4416
+ break;
4417
+ case "number":
4418
+ regexStr += `(?<${seg.varName}>\\d+)`;
4419
+ break;
4420
+ case "boolean":
4421
+ regexStr += `(?<${seg.varName}>(?:true|false))`;
4422
+ break;
4423
+ }
4424
+ }
4425
+ }
4426
+ regexStr += "$";
4427
+ return new RegExp(regexStr, "s");
4434
4428
  }
4435
- function lookupName(name, prop) {
4436
- const found = ISO3166_1.find((i) => i.name === name);
4437
- return found ? found[prop] : void 0;
4429
+ function convertValue(type, value) {
4430
+ switch (type) {
4431
+ case "string":
4432
+ return value;
4433
+ case "number":
4434
+ return Number(value);
4435
+ case "boolean":
4436
+ return value === "true";
4437
+ }
4438
4438
  }
4439
- function lookupNumericCode(code, prop) {
4440
- let num = isNumber(code) ? `${code}` : code;
4441
- if (num.length === 1) {
4442
- num = `00${num}`;
4443
- } else if (num.length === 2) {
4444
- num = `0${num}`;
4439
+ function matchTemplate(inference, test) {
4440
+ const segments = parseTemplate(inference);
4441
+ const regex = buildRegexPattern(segments);
4442
+ const match = test.match(regex);
4443
+ if (!match)
4444
+ return false;
4445
+ const result2 = {};
4446
+ for (const seg of segments) {
4447
+ if (seg.dynamic) {
4448
+ const rawVal = match.groups?.[seg.varName];
4449
+ if (rawVal === void 0)
4450
+ return false;
4451
+ result2[seg.varName.toLowerCase()] = convertValue(seg.type, rawVal);
4452
+ }
4445
4453
  }
4446
- const found = ISO3166_1.find((i) => i.countryCode === num);
4447
- return found ? found[prop] : void 0;
4454
+ return result2;
4448
4455
  }
4449
- function lookupCountryName(code) {
4450
- const uc = uppercase(code);
4451
- return isNumberLike(code) ? lookupNumericCode(code, "name") : isIso3166Alpha2(uc) ? lookupAlpha2Code(uc, "name") : isIso3166Alpha3(uc) ? lookupAlpha3Code(uc, "name") : void 0;
4456
+ function infer(inference) {
4457
+ return (test) => {
4458
+ return matchTemplate(inference, test);
4459
+ };
4452
4460
  }
4453
- function lookupCountryAlpha2(code) {
4454
- const uc = uppercase(code);
4455
- return isNumberLike(code) ? lookupNumericCode(code, "alpha2") : isIso3166Alpha2(uc) ? lookupAlpha2Code(uc, "alpha2") : isIso3166Alpha3(uc) ? lookupAlpha3Code(uc, "alpha2") : isIso3166CountryName(code) ? lookupName(code, "alpha2") : void 0;
4461
+
4462
+ // src/literals/literal.ts
4463
+ function idLiteral(o) {
4464
+ return { ...o, id: o.id };
4456
4465
  }
4457
- function lookupCountryAlpha3(token) {
4458
- const uc = uppercase(token);
4459
- return isNumberLike(token) ? lookupNumericCode(token, "alpha3") : isIso3166Alpha2(uc) ? lookupAlpha2Code(uc, "alpha3") : isIso3166Alpha3(uc) ? lookupAlpha3Code(uc, "alpha3") : isIso3166CountryName(token) ? lookupName(token, "alpha3") : void 0;
4466
+ function nameLiteral(o) {
4467
+ return o;
4460
4468
  }
4461
- function lookupCountryCode(token) {
4462
- const uc = uppercase(token);
4463
- return isNumberLike(token) ? lookupNumericCode(token, "countryCode") : isIso3166Alpha2(uc) ? lookupAlpha2Code(uc, "countryCode") : isIso3166Alpha3(uc) ? lookupAlpha3Code(uc, "countryCode") : isIso3166CountryName(token) ? lookupName(token, "countryCode") : void 0;
4469
+ function kindLiteral(o) {
4470
+ return o;
4464
4471
  }
4465
-
4466
- // src/type-conversion/mergeObjects.ts
4467
- function mergeObjects(defVal, override) {
4468
- const intersectingKeys = sharedKeys(defVal, override);
4469
- const defUnique = withoutKeys(defVal, ...intersectingKeys);
4470
- const overrideUnique = withoutKeys(defVal, ...intersectingKeys);
4471
- const merged = {
4472
- ...intersectingKeys.reduce(
4473
- (acc, key) => typeof override[key] === "undefined" ? { ...acc, [key]: defVal[key] } : { ...acc, [key]: override[key] },
4474
- {}
4475
- ),
4476
- ...defUnique,
4477
- ...overrideUnique
4478
- };
4479
- return merged;
4472
+ function idTypeGuard(_o) {
4473
+ return true;
4480
4474
  }
4481
-
4482
- // src/type-conversion/mergeScalars.ts
4483
- function mergeScalars(a, b) {
4484
- return isUndefined(b) ? a : b;
4475
+ function literal(obj) {
4476
+ return obj;
4485
4477
  }
4486
4478
 
4487
- // src/type-conversion/mergeTuples.ts
4488
- function mergeTuples(a, b) {
4489
- return b.length > a.length ? b.map((v, idx) => v !== void 0 ? v : a[idx]) : [...b, ...a.slice(b.length)].map((v, idx) => v !== void 0 ? v : a[idx]);
4479
+ // src/literals/lowercase.ts
4480
+ function lowercase(str) {
4481
+ return str.toLowerCase();
4490
4482
  }
4491
4483
 
4492
- // src/type-conversion/never.ts
4493
- function never(val) {
4494
- return val;
4484
+ // src/literals/narrow.ts
4485
+ function narrow(...values) {
4486
+ return values.length === 1 ? values[0] : values;
4495
4487
  }
4496
4488
 
4497
- // src/type-conversion/optional.ts
4498
- function optional(value) {
4499
- return value;
4500
- }
4501
- function orNull(value) {
4502
- return value;
4489
+ // src/literals/pathJoin.ts
4490
+ function pathJoin(...segments) {
4491
+ const clean_path = segments.map((i) => stripTrailing(stripLeading(i, "/"), "/")).join("/");
4492
+ const original_path = segments.join("/");
4493
+ const pre = original_path.startsWith("/") ? "/" : "";
4494
+ const post = original_path.endsWith("/") ? "/" : "";
4495
+ return `${pre}${clean_path}${post}`;
4503
4496
  }
4504
- function optionalOrNull(value) {
4505
- return value;
4497
+
4498
+ // src/literals/phone/asPhoneNumber.ts
4499
+ var asPhoneFormat = () => `NOT IMPLEMENTED`;
4500
+
4501
+ // src/literals/phone/getPhoneCountryCode.ts
4502
+ function getPhoneCountryCode(phone) {
4503
+ return phone.trim().startsWith("+") || phone.trim().startsWith("00") ? retainWhile(
4504
+ stripLeading(stripLeading(phone.trim(), "+"), "00"),
4505
+ ...NUMERIC_CHAR
4506
+ ) : "";
4506
4507
  }
4507
4508
 
4508
- // src/type-conversion/stripParenthesis.ts
4509
- function stripParenthesis(val) {
4510
- return stripTrailing(stripLeading(val.trim(), "("), ")").trim();
4509
+ // src/literals/phone/removePhoneCountryCode.ts
4510
+ function removePhoneCountryCode(phone) {
4511
+ const countryCode = getPhoneCountryCode(phone);
4512
+ return countryCode !== "" ? stripLeading(stripLeading(
4513
+ phone.trim(),
4514
+ "+",
4515
+ "00"
4516
+ ), countryCode).trim() : phone.trim();
4511
4517
  }
4512
4518
 
4513
- // src/type-conversion/toNumber.ts
4514
- function convertScalar(val) {
4515
- switch (typeof val) {
4516
- case "number":
4517
- return val;
4518
- case "string":
4519
- return Number(val);
4520
- case "boolean":
4521
- return val ? 1 : 0;
4519
+ // src/literals/pluralize.ts
4520
+ var isException = (word) => Object.keys(PLURAL_EXCEPTIONS).includes(word);
4521
+ function endingIn(word, postfix) {
4522
+ switch (postfix) {
4523
+ case "is":
4524
+ return word.endsWith(postfix) ? `${word}es` : void 0;
4525
+ case "singular-noun":
4526
+ return SINGULAR_NOUN_ENDINGS.some((i) => word.endsWith(i)) ? split(word).every((i) => [...ALPHA_CHARS].includes(i)) ? `${word}es` : void 0 : void 0;
4527
+ case "f":
4528
+ return word.endsWith("f") ? `${stripTrailing(word, "f")}ves` : word.endsWith("fe") ? `${stripTrailing(word, "fe")}ves` : void 0;
4529
+ case "y":
4530
+ return word.endsWith("y") ? `${stripTrailing(word, "y")}ies` : void 0;
4522
4531
  default:
4523
- throw new Error(`${typeof val} is an invalid scalar type to convert to a number!`);
4532
+ throw new Error(`endingIn received "${postfix}" as a postfix but this ending is not known!`);
4524
4533
  }
4525
4534
  }
4526
- var convertList = (val) => val.map((i) => convertScalar(i));
4527
- function toNumber(value) {
4528
- return Array.isArray(value) ? convertList(value) : convertScalar(value);
4535
+ function pluralize(word) {
4536
+ const right = rightWhitespace(word);
4537
+ const w = word.trimEnd();
4538
+ const result2 = isException(w) ? PLURAL_EXCEPTIONS[w] : endingIn(w, "is") || endingIn(w, "singular-noun") || endingIn(w, "f") || endingIn(w, "y") || `${w}s`;
4539
+ return `${result2}${right}`;
4529
4540
  }
4530
4541
 
4531
- // src/type-conversion/tw-conversion.ts
4532
- var MODS = TW_MODIFIERS.map((i) => `${i}:`);
4533
- function removeTailwindModifiers(val) {
4534
- return MODS.some((i) => val.startsWith(i)) ? removeTailwindModifiers(val.replace(MODS.find((i) => val.startsWith(i)), "")) : val;
4535
- }
4536
- function getTailwindModifiers(val) {
4537
- return val.split(":").filter((i) => isTailwindModifier(i));
4542
+ // src/literals/retainAfter.ts
4543
+ function retainAfter(content, ...find2) {
4544
+ const idx = Math.min(
4545
+ ...find2.map((i) => content.indexOf(i)).filter((i) => i > -1)
4546
+ );
4547
+ const min = Math.min(...find2.map((i) => i.length));
4548
+ let len = Math.max(...find2.map((i) => i.length));
4549
+ if (min !== len) {
4550
+ if (!find2.includes(content.slice(idx, len))) {
4551
+ len = min;
4552
+ }
4553
+ }
4554
+ return idx && idx > 0 ? content.slice(idx + len) : "";
4538
4555
  }
4539
-
4540
- // src/type-conversion/union.ts
4541
- function union(..._options) {
4542
- return (value) => value;
4556
+ function retainAfterInclusive(content, ...find2) {
4557
+ const minFound = Math.min(
4558
+ ...find2.map((i) => content.indexOf(i)).filter((i) => i > -1)
4559
+ );
4560
+ return minFound > 0 ? content.slice(minFound) : "";
4543
4561
  }
4544
4562
 
4545
- // src/type-conversion/unionize.ts
4546
- function unionize(value, _inUnionWith) {
4547
- return value;
4563
+ // src/literals/retainChars.ts
4564
+ function retainChars(content, ...retain2) {
4565
+ const chars = asChars(content);
4566
+ return chars.filter((c) => retain2.includes(c)).join("");
4548
4567
  }
4549
4568
 
4550
4569
  // src/literals/retainUntil.ts
@@ -5338,6 +5357,7 @@ function asVueRef(value) {
5338
5357
  getToday,
5339
5358
  getTokenKind,
5340
5359
  getTomorrow,
5360
+ getTypeSubtype,
5341
5361
  getUrlPath,
5342
5362
  getUrlPort,
5343
5363
  getUrlProtocol,
@@ -5578,6 +5598,7 @@ function asVueRef(value) {
5578
5598
  isTupleToken,
5579
5599
  isTurkishNewsUrl,
5580
5600
  isTypeOf,
5601
+ isTypeSubtype,
5581
5602
  isTypeToken,
5582
5603
  isTypeTokenKind,
5583
5604
  isTypeTuple,