inferred-types 0.54.2 → 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.
- package/modules/inferred-types/dist/index.cjs +326 -304
- package/modules/inferred-types/dist/index.cjs.map +1 -1
- package/modules/inferred-types/dist/index.d.ts +45 -3
- package/modules/inferred-types/dist/index.js +323 -304
- package/modules/inferred-types/dist/index.js.map +1 -1
- package/modules/runtime/dist/index.cjs +390 -362
- package/modules/runtime/dist/index.cjs.map +1 -1
- package/modules/runtime/dist/index.d.ts +35 -2
- package/modules/runtime/dist/index.js +387 -362
- package/modules/runtime/dist/index.js.map +1 -1
- package/modules/types/dist/index.d.ts +11 -2
- package/package.json +1 -1
|
@@ -2459,235 +2459,6 @@ function ensureTrailing(content, ensure) {
|
|
|
2459
2459
|
);
|
|
2460
2460
|
}
|
|
2461
2461
|
|
|
2462
|
-
// src/literals/identity.ts
|
|
2463
|
-
function identity(...values) {
|
|
2464
|
-
return values.length === 1 ? values[0] : values.length === 0 ? void 0 : values;
|
|
2465
|
-
}
|
|
2466
|
-
|
|
2467
|
-
// src/literals/ifLowercase.ts
|
|
2468
|
-
function ifLowercaseChar(ch, callbackForMatch, callbackForNoMatch) {
|
|
2469
|
-
if (ch.length !== 1) {
|
|
2470
|
-
throw new Error(`call to ifUppercaseChar received ${ch.length} characters but is only valid when one character is passed in!`);
|
|
2471
|
-
}
|
|
2472
|
-
return LOWER_ALPHA_CHARS.includes(ch) ? callbackForMatch(ch) : callbackForNoMatch(ch);
|
|
2473
|
-
}
|
|
2474
|
-
|
|
2475
|
-
// src/literals/ifUppercase.ts
|
|
2476
|
-
function ifUppercaseChar(ch, callbackForMatch, callbackForNoMatch) {
|
|
2477
|
-
if (ch.length !== 1) {
|
|
2478
|
-
throw new Error(`Invalid string length passed to ifUppercaseChar(ch); this function requires a single character but ${ch.length} were received`);
|
|
2479
|
-
}
|
|
2480
|
-
return LOWER_ALPHA_CHARS.includes(ch) ? callbackForMatch(ch) : callbackForNoMatch(ch);
|
|
2481
|
-
}
|
|
2482
|
-
|
|
2483
|
-
// src/literals/infer.ts
|
|
2484
|
-
function parseTemplate(template) {
|
|
2485
|
-
const pattern = /\{\{\s*infer\s+([A-Za-z_]\w*)\s*(?:as\s+(string|number|boolean)\s*)?\}\}/g;
|
|
2486
|
-
let lastIndex = 0;
|
|
2487
|
-
let match;
|
|
2488
|
-
const segments = [];
|
|
2489
|
-
do {
|
|
2490
|
-
match = pattern.exec(template);
|
|
2491
|
-
if (match) {
|
|
2492
|
-
const [fullMatch, varName, asType2] = match;
|
|
2493
|
-
const staticPart = template.slice(lastIndex, match.index);
|
|
2494
|
-
if (staticPart) {
|
|
2495
|
-
segments.push({ dynamic: false, text: staticPart });
|
|
2496
|
-
}
|
|
2497
|
-
segments.push({
|
|
2498
|
-
dynamic: true,
|
|
2499
|
-
varName,
|
|
2500
|
-
type: asType2 ? asType2 : "string"
|
|
2501
|
-
});
|
|
2502
|
-
lastIndex = match.index + fullMatch.length;
|
|
2503
|
-
}
|
|
2504
|
-
} while (match);
|
|
2505
|
-
const remainder = template.slice(lastIndex);
|
|
2506
|
-
if (remainder) {
|
|
2507
|
-
segments.push({ dynamic: false, text: remainder });
|
|
2508
|
-
}
|
|
2509
|
-
return segments;
|
|
2510
|
-
}
|
|
2511
|
-
function escapeRegex(str) {
|
|
2512
|
-
return str.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
2513
|
-
}
|
|
2514
|
-
function buildRegexPattern(segments) {
|
|
2515
|
-
let regexStr = "^";
|
|
2516
|
-
for (const seg of segments) {
|
|
2517
|
-
if (!seg.dynamic) {
|
|
2518
|
-
regexStr += escapeRegex(seg.text);
|
|
2519
|
-
} else {
|
|
2520
|
-
switch (seg.type) {
|
|
2521
|
-
case "string":
|
|
2522
|
-
regexStr += `(?<${seg.varName}>.*?)`;
|
|
2523
|
-
break;
|
|
2524
|
-
case "number":
|
|
2525
|
-
regexStr += `(?<${seg.varName}>\\d+)`;
|
|
2526
|
-
break;
|
|
2527
|
-
case "boolean":
|
|
2528
|
-
regexStr += `(?<${seg.varName}>(?:true|false))`;
|
|
2529
|
-
break;
|
|
2530
|
-
}
|
|
2531
|
-
}
|
|
2532
|
-
}
|
|
2533
|
-
regexStr += "$";
|
|
2534
|
-
return new RegExp(regexStr, "s");
|
|
2535
|
-
}
|
|
2536
|
-
function convertValue(type, value) {
|
|
2537
|
-
switch (type) {
|
|
2538
|
-
case "string":
|
|
2539
|
-
return value;
|
|
2540
|
-
case "number":
|
|
2541
|
-
return Number(value);
|
|
2542
|
-
case "boolean":
|
|
2543
|
-
return value === "true";
|
|
2544
|
-
}
|
|
2545
|
-
}
|
|
2546
|
-
function matchTemplate(inference, test) {
|
|
2547
|
-
const segments = parseTemplate(inference);
|
|
2548
|
-
const regex = buildRegexPattern(segments);
|
|
2549
|
-
const match = test.match(regex);
|
|
2550
|
-
if (!match)
|
|
2551
|
-
return false;
|
|
2552
|
-
const result2 = {};
|
|
2553
|
-
for (const seg of segments) {
|
|
2554
|
-
if (seg.dynamic) {
|
|
2555
|
-
const rawVal = match.groups?.[seg.varName];
|
|
2556
|
-
if (rawVal === void 0)
|
|
2557
|
-
return false;
|
|
2558
|
-
result2[seg.varName.toLowerCase()] = convertValue(seg.type, rawVal);
|
|
2559
|
-
}
|
|
2560
|
-
}
|
|
2561
|
-
return result2;
|
|
2562
|
-
}
|
|
2563
|
-
function infer(inference) {
|
|
2564
|
-
return (test) => {
|
|
2565
|
-
return matchTemplate(inference, test);
|
|
2566
|
-
};
|
|
2567
|
-
}
|
|
2568
|
-
|
|
2569
|
-
// src/literals/literal.ts
|
|
2570
|
-
function idLiteral(o) {
|
|
2571
|
-
return { ...o, id: o.id };
|
|
2572
|
-
}
|
|
2573
|
-
function nameLiteral(o) {
|
|
2574
|
-
return o;
|
|
2575
|
-
}
|
|
2576
|
-
function kindLiteral(o) {
|
|
2577
|
-
return o;
|
|
2578
|
-
}
|
|
2579
|
-
function idTypeGuard(_o) {
|
|
2580
|
-
return true;
|
|
2581
|
-
}
|
|
2582
|
-
function literal(obj) {
|
|
2583
|
-
return obj;
|
|
2584
|
-
}
|
|
2585
|
-
|
|
2586
|
-
// src/literals/lowercase.ts
|
|
2587
|
-
function lowercase(str) {
|
|
2588
|
-
return str.toLowerCase();
|
|
2589
|
-
}
|
|
2590
|
-
|
|
2591
|
-
// src/literals/narrow.ts
|
|
2592
|
-
function narrow(...values) {
|
|
2593
|
-
return values.length === 1 ? values[0] : values;
|
|
2594
|
-
}
|
|
2595
|
-
|
|
2596
|
-
// src/literals/pathJoin.ts
|
|
2597
|
-
function pathJoin(...segments) {
|
|
2598
|
-
const clean_path = segments.map((i) => stripTrailing(stripLeading(i, "/"), "/")).join("/");
|
|
2599
|
-
const original_path = segments.join("/");
|
|
2600
|
-
const pre = original_path.startsWith("/") ? "/" : "";
|
|
2601
|
-
const post = original_path.endsWith("/") ? "/" : "";
|
|
2602
|
-
return `${pre}${clean_path}${post}`;
|
|
2603
|
-
}
|
|
2604
|
-
|
|
2605
|
-
// src/literals/phone/asPhoneNumber.ts
|
|
2606
|
-
var asPhoneFormat = () => `NOT IMPLEMENTED`;
|
|
2607
|
-
|
|
2608
|
-
// src/literals/phone/getPhoneCountryCode.ts
|
|
2609
|
-
function getPhoneCountryCode(phone) {
|
|
2610
|
-
return phone.trim().startsWith("+") || phone.trim().startsWith("00") ? retainWhile(
|
|
2611
|
-
stripLeading(stripLeading(phone.trim(), "+"), "00"),
|
|
2612
|
-
...NUMERIC_CHAR
|
|
2613
|
-
) : "";
|
|
2614
|
-
}
|
|
2615
|
-
|
|
2616
|
-
// src/literals/phone/removePhoneCountryCode.ts
|
|
2617
|
-
function removePhoneCountryCode(phone) {
|
|
2618
|
-
const countryCode = getPhoneCountryCode(phone);
|
|
2619
|
-
return countryCode !== "" ? stripLeading(stripLeading(
|
|
2620
|
-
phone.trim(),
|
|
2621
|
-
"+",
|
|
2622
|
-
"00"
|
|
2623
|
-
), countryCode).trim() : phone.trim();
|
|
2624
|
-
}
|
|
2625
|
-
|
|
2626
|
-
// src/literals/pluralize.ts
|
|
2627
|
-
var isException = (word) => Object.keys(PLURAL_EXCEPTIONS).includes(word);
|
|
2628
|
-
function endingIn(word, postfix) {
|
|
2629
|
-
switch (postfix) {
|
|
2630
|
-
case "is":
|
|
2631
|
-
return word.endsWith(postfix) ? `${word}es` : void 0;
|
|
2632
|
-
case "singular-noun":
|
|
2633
|
-
return SINGULAR_NOUN_ENDINGS.some((i) => word.endsWith(i)) ? split(word).every((i) => [...ALPHA_CHARS].includes(i)) ? `${word}es` : void 0 : void 0;
|
|
2634
|
-
case "f":
|
|
2635
|
-
return word.endsWith("f") ? `${stripTrailing(word, "f")}ves` : word.endsWith("fe") ? `${stripTrailing(word, "fe")}ves` : void 0;
|
|
2636
|
-
case "y":
|
|
2637
|
-
return word.endsWith("y") ? `${stripTrailing(word, "y")}ies` : void 0;
|
|
2638
|
-
default:
|
|
2639
|
-
throw new Error(`endingIn received "${postfix}" as a postfix but this ending is not known!`);
|
|
2640
|
-
}
|
|
2641
|
-
}
|
|
2642
|
-
function pluralize(word) {
|
|
2643
|
-
const right = rightWhitespace(word);
|
|
2644
|
-
const w = word.trimEnd();
|
|
2645
|
-
const result2 = isException(w) ? PLURAL_EXCEPTIONS[w] : endingIn(w, "is") || endingIn(w, "singular-noun") || endingIn(w, "f") || endingIn(w, "y") || `${w}s`;
|
|
2646
|
-
return `${result2}${right}`;
|
|
2647
|
-
}
|
|
2648
|
-
|
|
2649
|
-
// src/literals/retainAfter.ts
|
|
2650
|
-
function retainAfter(content, ...find2) {
|
|
2651
|
-
const idx = Math.min(
|
|
2652
|
-
...find2.map((i) => content.indexOf(i)).filter((i) => i > -1)
|
|
2653
|
-
);
|
|
2654
|
-
const min = Math.min(...find2.map((i) => i.length));
|
|
2655
|
-
let len = Math.max(...find2.map((i) => i.length));
|
|
2656
|
-
if (min !== len) {
|
|
2657
|
-
if (!find2.includes(content.slice(idx, len))) {
|
|
2658
|
-
len = min;
|
|
2659
|
-
}
|
|
2660
|
-
}
|
|
2661
|
-
return idx && idx > 0 ? content.slice(idx + len) : "";
|
|
2662
|
-
}
|
|
2663
|
-
function retainAfterInclusive(content, ...find2) {
|
|
2664
|
-
const minFound = Math.min(
|
|
2665
|
-
...find2.map((i) => content.indexOf(i)).filter((i) => i > -1)
|
|
2666
|
-
);
|
|
2667
|
-
return minFound > 0 ? content.slice(minFound) : "";
|
|
2668
|
-
}
|
|
2669
|
-
|
|
2670
|
-
// src/type-conversion/asChars.ts
|
|
2671
|
-
function asChars(str) {
|
|
2672
|
-
return str.split("");
|
|
2673
|
-
}
|
|
2674
|
-
|
|
2675
|
-
// src/literals/retainChars.ts
|
|
2676
|
-
function retainChars(content, ...retain2) {
|
|
2677
|
-
const chars = asChars(content);
|
|
2678
|
-
return chars.filter((c) => retain2.includes(c)).join("");
|
|
2679
|
-
}
|
|
2680
|
-
|
|
2681
|
-
// src/type-conversion/asRecord.ts
|
|
2682
|
-
function asRecord(obj) {
|
|
2683
|
-
return obj;
|
|
2684
|
-
}
|
|
2685
|
-
|
|
2686
|
-
// src/type-conversion/asString.ts
|
|
2687
|
-
function asString(value) {
|
|
2688
|
-
return isString(value) ? value : isNumber(value) ? `${value}` : isBoolean(value) ? `${value}` : isArray(value) ? value.join("") : String(value);
|
|
2689
|
-
}
|
|
2690
|
-
|
|
2691
2462
|
// src/type-guards/isFunction.ts
|
|
2692
2463
|
function isFunction(value) {
|
|
2693
2464
|
return typeof value === "function";
|
|
@@ -3019,6 +2790,190 @@ function hasKeys(...props) {
|
|
|
3019
2790
|
};
|
|
3020
2791
|
}
|
|
3021
2792
|
|
|
2793
|
+
// src/type-conversion/asChars.ts
|
|
2794
|
+
function asChars(str) {
|
|
2795
|
+
return str.split("");
|
|
2796
|
+
}
|
|
2797
|
+
|
|
2798
|
+
// src/type-conversion/asRecord.ts
|
|
2799
|
+
function asRecord(obj) {
|
|
2800
|
+
return obj;
|
|
2801
|
+
}
|
|
2802
|
+
|
|
2803
|
+
// src/type-conversion/asString.ts
|
|
2804
|
+
function asString(value) {
|
|
2805
|
+
return isString(value) ? value : isNumber(value) ? `${value}` : isBoolean(value) ? `${value}` : isArray(value) ? value.join("") : String(value);
|
|
2806
|
+
}
|
|
2807
|
+
|
|
2808
|
+
// src/type-conversion/csv.ts
|
|
2809
|
+
function csv(csv2, format = `string-numeric-tuple`) {
|
|
2810
|
+
const tuple3 = [];
|
|
2811
|
+
csv2.split(/,\s?/).forEach((v) => {
|
|
2812
|
+
tuple3.push(
|
|
2813
|
+
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
|
|
2814
|
+
);
|
|
2815
|
+
});
|
|
2816
|
+
return tuple3;
|
|
2817
|
+
}
|
|
2818
|
+
|
|
2819
|
+
// src/type-conversion/intersect.ts
|
|
2820
|
+
function intersect(value, _intersectedWith) {
|
|
2821
|
+
return value;
|
|
2822
|
+
}
|
|
2823
|
+
|
|
2824
|
+
// src/literals/stripTrailing.ts
|
|
2825
|
+
function stripTrailing(content, ...strip2) {
|
|
2826
|
+
let output = String(content);
|
|
2827
|
+
for (const s of strip2) {
|
|
2828
|
+
if (output.endsWith(String(s))) {
|
|
2829
|
+
output = output.slice(0, -1 * String(s).length);
|
|
2830
|
+
}
|
|
2831
|
+
}
|
|
2832
|
+
return isNumber(content) ? Number(output) : output;
|
|
2833
|
+
}
|
|
2834
|
+
|
|
2835
|
+
// src/type-conversion/ip6GroupExpansion.ts
|
|
2836
|
+
function ip6GroupExpansion(ip) {
|
|
2837
|
+
return stripTrailing(ip.replaceAll("::", ":0000:"), ":");
|
|
2838
|
+
}
|
|
2839
|
+
|
|
2840
|
+
// src/type-conversion/json.ts
|
|
2841
|
+
function jsonValue(val) {
|
|
2842
|
+
return isNumberLike(val) ? Number(val) : val === "true" ? true : val === "false" ? false : `"${val}"`;
|
|
2843
|
+
}
|
|
2844
|
+
function jsonValues(...val) {
|
|
2845
|
+
return val.map((i) => jsonValue(i));
|
|
2846
|
+
}
|
|
2847
|
+
|
|
2848
|
+
// src/type-conversion/lookupCountry.ts
|
|
2849
|
+
function lookupAlpha2Code(code, prop) {
|
|
2850
|
+
const found = ISO3166_1.find((i) => i.alpha2 === code);
|
|
2851
|
+
return found ? found[prop] : void 0;
|
|
2852
|
+
}
|
|
2853
|
+
function lookupAlpha3Code(code, prop) {
|
|
2854
|
+
const found = ISO3166_1.find((i) => i.alpha3 === code);
|
|
2855
|
+
return found ? found[prop] : void 0;
|
|
2856
|
+
}
|
|
2857
|
+
function lookupName(name, prop) {
|
|
2858
|
+
const found = ISO3166_1.find((i) => i.name === name);
|
|
2859
|
+
return found ? found[prop] : void 0;
|
|
2860
|
+
}
|
|
2861
|
+
function lookupNumericCode(code, prop) {
|
|
2862
|
+
let num = isNumber(code) ? `${code}` : code;
|
|
2863
|
+
if (num.length === 1) {
|
|
2864
|
+
num = `00${num}`;
|
|
2865
|
+
} else if (num.length === 2) {
|
|
2866
|
+
num = `0${num}`;
|
|
2867
|
+
}
|
|
2868
|
+
const found = ISO3166_1.find((i) => i.countryCode === num);
|
|
2869
|
+
return found ? found[prop] : void 0;
|
|
2870
|
+
}
|
|
2871
|
+
function lookupCountryName(code) {
|
|
2872
|
+
const uc = uppercase(code);
|
|
2873
|
+
return isNumberLike(code) ? lookupNumericCode(code, "name") : isIso3166Alpha2(uc) ? lookupAlpha2Code(uc, "name") : isIso3166Alpha3(uc) ? lookupAlpha3Code(uc, "name") : void 0;
|
|
2874
|
+
}
|
|
2875
|
+
function lookupCountryAlpha2(code) {
|
|
2876
|
+
const uc = uppercase(code);
|
|
2877
|
+
return isNumberLike(code) ? lookupNumericCode(code, "alpha2") : isIso3166Alpha2(uc) ? lookupAlpha2Code(uc, "alpha2") : isIso3166Alpha3(uc) ? lookupAlpha3Code(uc, "alpha2") : isIso3166CountryName(code) ? lookupName(code, "alpha2") : void 0;
|
|
2878
|
+
}
|
|
2879
|
+
function lookupCountryAlpha3(token) {
|
|
2880
|
+
const uc = uppercase(token);
|
|
2881
|
+
return isNumberLike(token) ? lookupNumericCode(token, "alpha3") : isIso3166Alpha2(uc) ? lookupAlpha2Code(uc, "alpha3") : isIso3166Alpha3(uc) ? lookupAlpha3Code(uc, "alpha3") : isIso3166CountryName(token) ? lookupName(token, "alpha3") : void 0;
|
|
2882
|
+
}
|
|
2883
|
+
function lookupCountryCode(token) {
|
|
2884
|
+
const uc = uppercase(token);
|
|
2885
|
+
return isNumberLike(token) ? lookupNumericCode(token, "countryCode") : isIso3166Alpha2(uc) ? lookupAlpha2Code(uc, "countryCode") : isIso3166Alpha3(uc) ? lookupAlpha3Code(uc, "countryCode") : isIso3166CountryName(token) ? lookupName(token, "countryCode") : void 0;
|
|
2886
|
+
}
|
|
2887
|
+
|
|
2888
|
+
// src/type-conversion/mergeObjects.ts
|
|
2889
|
+
function mergeObjects(defVal, override) {
|
|
2890
|
+
const intersectingKeys = sharedKeys(defVal, override);
|
|
2891
|
+
const defUnique = withoutKeys(defVal, ...intersectingKeys);
|
|
2892
|
+
const overrideUnique = withoutKeys(defVal, ...intersectingKeys);
|
|
2893
|
+
const merged = {
|
|
2894
|
+
...intersectingKeys.reduce(
|
|
2895
|
+
(acc, key) => typeof override[key] === "undefined" ? { ...acc, [key]: defVal[key] } : { ...acc, [key]: override[key] },
|
|
2896
|
+
{}
|
|
2897
|
+
),
|
|
2898
|
+
...defUnique,
|
|
2899
|
+
...overrideUnique
|
|
2900
|
+
};
|
|
2901
|
+
return merged;
|
|
2902
|
+
}
|
|
2903
|
+
|
|
2904
|
+
// src/type-guards/isUndefined.ts
|
|
2905
|
+
function isUndefined(value) {
|
|
2906
|
+
return typeof value === "undefined";
|
|
2907
|
+
}
|
|
2908
|
+
|
|
2909
|
+
// src/type-conversion/mergeScalars.ts
|
|
2910
|
+
function mergeScalars(a, b) {
|
|
2911
|
+
return isUndefined(b) ? a : b;
|
|
2912
|
+
}
|
|
2913
|
+
|
|
2914
|
+
// src/type-conversion/mergeTuples.ts
|
|
2915
|
+
function mergeTuples(a, b) {
|
|
2916
|
+
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]);
|
|
2917
|
+
}
|
|
2918
|
+
|
|
2919
|
+
// src/type-conversion/never.ts
|
|
2920
|
+
function never(val) {
|
|
2921
|
+
return val;
|
|
2922
|
+
}
|
|
2923
|
+
|
|
2924
|
+
// src/type-conversion/optional.ts
|
|
2925
|
+
function optional(value) {
|
|
2926
|
+
return value;
|
|
2927
|
+
}
|
|
2928
|
+
function orNull(value) {
|
|
2929
|
+
return value;
|
|
2930
|
+
}
|
|
2931
|
+
function optionalOrNull(value) {
|
|
2932
|
+
return value;
|
|
2933
|
+
}
|
|
2934
|
+
|
|
2935
|
+
// src/type-conversion/stripParenthesis.ts
|
|
2936
|
+
function stripParenthesis(val) {
|
|
2937
|
+
return stripTrailing(stripLeading(val.trim(), "("), ")").trim();
|
|
2938
|
+
}
|
|
2939
|
+
|
|
2940
|
+
// src/type-conversion/toNumber.ts
|
|
2941
|
+
function convertScalar(val) {
|
|
2942
|
+
switch (typeof val) {
|
|
2943
|
+
case "number":
|
|
2944
|
+
return val;
|
|
2945
|
+
case "string":
|
|
2946
|
+
return Number(val);
|
|
2947
|
+
case "boolean":
|
|
2948
|
+
return val ? 1 : 0;
|
|
2949
|
+
default:
|
|
2950
|
+
throw new Error(`${typeof val} is an invalid scalar type to convert to a number!`);
|
|
2951
|
+
}
|
|
2952
|
+
}
|
|
2953
|
+
var convertList = (val) => val.map((i) => convertScalar(i));
|
|
2954
|
+
function toNumber(value) {
|
|
2955
|
+
return Array.isArray(value) ? convertList(value) : convertScalar(value);
|
|
2956
|
+
}
|
|
2957
|
+
|
|
2958
|
+
// src/type-conversion/tw-conversion.ts
|
|
2959
|
+
var MODS = TW_MODIFIERS.map((i) => `${i}:`);
|
|
2960
|
+
function removeTailwindModifiers(val) {
|
|
2961
|
+
return MODS.some((i) => val.startsWith(i)) ? removeTailwindModifiers(val.replace(MODS.find((i) => val.startsWith(i)), "")) : val;
|
|
2962
|
+
}
|
|
2963
|
+
function getTailwindModifiers(val) {
|
|
2964
|
+
return val.split(":").filter((i) => isTailwindModifier(i));
|
|
2965
|
+
}
|
|
2966
|
+
|
|
2967
|
+
// src/type-conversion/union.ts
|
|
2968
|
+
function union(..._options) {
|
|
2969
|
+
return (value) => value;
|
|
2970
|
+
}
|
|
2971
|
+
|
|
2972
|
+
// src/type-conversion/unionize.ts
|
|
2973
|
+
function unionize(value, _inUnionWith) {
|
|
2974
|
+
return value;
|
|
2975
|
+
}
|
|
2976
|
+
|
|
3022
2977
|
// src/type-guards/hasWhitespace.ts
|
|
3023
2978
|
function hasWhiteSpace(val) {
|
|
3024
2979
|
return isString(val) && asChars(val).some((c) => WHITESPACE_CHARS.includes(c));
|
|
@@ -3264,16 +3219,16 @@ function isTruthy(val) {
|
|
|
3264
3219
|
return !FALSY_VALUES.includes(val);
|
|
3265
3220
|
}
|
|
3266
3221
|
|
|
3222
|
+
// src/type-guards/isTypeSubtype.ts
|
|
3223
|
+
function isTypeSubtype(val) {
|
|
3224
|
+
return isString(val) && val.split("/").length === 2;
|
|
3225
|
+
}
|
|
3226
|
+
|
|
3267
3227
|
// src/type-guards/isTypeTuple.ts
|
|
3268
3228
|
function isTypeTuple(value) {
|
|
3269
3229
|
return Array.isArray(value) && value.length === 3 && typeof value[1] === "function";
|
|
3270
3230
|
}
|
|
3271
3231
|
|
|
3272
|
-
// src/type-guards/isUndefined.ts
|
|
3273
|
-
function isUndefined(value) {
|
|
3274
|
-
return typeof value === "undefined";
|
|
3275
|
-
}
|
|
3276
|
-
|
|
3277
3232
|
// src/type-guards/isUnset.ts
|
|
3278
3233
|
function isUnset(val) {
|
|
3279
3234
|
return isObject(val) && val.kind === "Unset";
|
|
@@ -3923,168 +3878,230 @@ function isYouTubeVideosInPlaylist(val) {
|
|
|
3923
3878
|
return isString(val) && (val.startsWith(`https://www.youtube.com/playlist?`) || val.startsWith(`https://youtube.com/playlist?`)) && hasUrlQueryParameter(val, "list");
|
|
3924
3879
|
}
|
|
3925
3880
|
|
|
3926
|
-
// src/
|
|
3927
|
-
function
|
|
3928
|
-
|
|
3929
|
-
|
|
3930
|
-
|
|
3931
|
-
|
|
3932
|
-
);
|
|
3933
|
-
|
|
3934
|
-
|
|
3881
|
+
// src/literals/getTypeSubtype.ts
|
|
3882
|
+
function getTypeSubtype(str) {
|
|
3883
|
+
if (isTypeSubtype(str)) {
|
|
3884
|
+
const [t, st] = str.split("/");
|
|
3885
|
+
return [t, st];
|
|
3886
|
+
} else {
|
|
3887
|
+
const err = new Error(`An invalid Type/Subtype was passed into getTypeSubtype(${str})`);
|
|
3888
|
+
err.name = "InvalidTypeSubtype";
|
|
3889
|
+
throw err;
|
|
3890
|
+
}
|
|
3891
|
+
}
|
|
3892
|
+
|
|
3893
|
+
// src/literals/identity.ts
|
|
3894
|
+
function identity(...values) {
|
|
3895
|
+
return values.length === 1 ? values[0] : values.length === 0 ? void 0 : values;
|
|
3896
|
+
}
|
|
3897
|
+
|
|
3898
|
+
// src/literals/ifLowercase.ts
|
|
3899
|
+
function ifLowercaseChar(ch, callbackForMatch, callbackForNoMatch) {
|
|
3900
|
+
if (ch.length !== 1) {
|
|
3901
|
+
throw new Error(`call to ifUppercaseChar received ${ch.length} characters but is only valid when one character is passed in!`);
|
|
3902
|
+
}
|
|
3903
|
+
return LOWER_ALPHA_CHARS.includes(ch) ? callbackForMatch(ch) : callbackForNoMatch(ch);
|
|
3904
|
+
}
|
|
3905
|
+
|
|
3906
|
+
// src/literals/ifUppercase.ts
|
|
3907
|
+
function ifUppercaseChar(ch, callbackForMatch, callbackForNoMatch) {
|
|
3908
|
+
if (ch.length !== 1) {
|
|
3909
|
+
throw new Error(`Invalid string length passed to ifUppercaseChar(ch); this function requires a single character but ${ch.length} were received`);
|
|
3910
|
+
}
|
|
3911
|
+
return LOWER_ALPHA_CHARS.includes(ch) ? callbackForMatch(ch) : callbackForNoMatch(ch);
|
|
3912
|
+
}
|
|
3913
|
+
|
|
3914
|
+
// src/literals/infer.ts
|
|
3915
|
+
function parseTemplate(template) {
|
|
3916
|
+
const pattern = /\{\{\s*infer\s+([A-Za-z_]\w*)\s*(?:as\s+(string|number|boolean)\s*)?\}\}/g;
|
|
3917
|
+
let lastIndex = 0;
|
|
3918
|
+
let match;
|
|
3919
|
+
const segments = [];
|
|
3920
|
+
do {
|
|
3921
|
+
match = pattern.exec(template);
|
|
3922
|
+
if (match) {
|
|
3923
|
+
const [fullMatch, varName, asType2] = match;
|
|
3924
|
+
const staticPart = template.slice(lastIndex, match.index);
|
|
3925
|
+
if (staticPart) {
|
|
3926
|
+
segments.push({ dynamic: false, text: staticPart });
|
|
3927
|
+
}
|
|
3928
|
+
segments.push({
|
|
3929
|
+
dynamic: true,
|
|
3930
|
+
varName,
|
|
3931
|
+
type: asType2 ? asType2 : "string"
|
|
3932
|
+
});
|
|
3933
|
+
lastIndex = match.index + fullMatch.length;
|
|
3934
|
+
}
|
|
3935
|
+
} while (match);
|
|
3936
|
+
const remainder = template.slice(lastIndex);
|
|
3937
|
+
if (remainder) {
|
|
3938
|
+
segments.push({ dynamic: false, text: remainder });
|
|
3939
|
+
}
|
|
3940
|
+
return segments;
|
|
3935
3941
|
}
|
|
3936
|
-
|
|
3937
|
-
|
|
3938
|
-
function intersect(value, _intersectedWith) {
|
|
3939
|
-
return value;
|
|
3942
|
+
function escapeRegex(str) {
|
|
3943
|
+
return str.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
3940
3944
|
}
|
|
3941
|
-
|
|
3942
|
-
|
|
3943
|
-
|
|
3944
|
-
|
|
3945
|
-
|
|
3946
|
-
|
|
3947
|
-
|
|
3945
|
+
function buildRegexPattern(segments) {
|
|
3946
|
+
let regexStr = "^";
|
|
3947
|
+
for (const seg of segments) {
|
|
3948
|
+
if (!seg.dynamic) {
|
|
3949
|
+
regexStr += escapeRegex(seg.text);
|
|
3950
|
+
} else {
|
|
3951
|
+
switch (seg.type) {
|
|
3952
|
+
case "string":
|
|
3953
|
+
regexStr += `(?<${seg.varName}>.*?)`;
|
|
3954
|
+
break;
|
|
3955
|
+
case "number":
|
|
3956
|
+
regexStr += `(?<${seg.varName}>\\d+)`;
|
|
3957
|
+
break;
|
|
3958
|
+
case "boolean":
|
|
3959
|
+
regexStr += `(?<${seg.varName}>(?:true|false))`;
|
|
3960
|
+
break;
|
|
3961
|
+
}
|
|
3948
3962
|
}
|
|
3949
3963
|
}
|
|
3950
|
-
|
|
3964
|
+
regexStr += "$";
|
|
3965
|
+
return new RegExp(regexStr, "s");
|
|
3951
3966
|
}
|
|
3952
|
-
|
|
3953
|
-
|
|
3954
|
-
|
|
3955
|
-
|
|
3967
|
+
function convertValue(type, value) {
|
|
3968
|
+
switch (type) {
|
|
3969
|
+
case "string":
|
|
3970
|
+
return value;
|
|
3971
|
+
case "number":
|
|
3972
|
+
return Number(value);
|
|
3973
|
+
case "boolean":
|
|
3974
|
+
return value === "true";
|
|
3975
|
+
}
|
|
3956
3976
|
}
|
|
3957
|
-
|
|
3958
|
-
|
|
3959
|
-
|
|
3960
|
-
|
|
3977
|
+
function matchTemplate(inference, test) {
|
|
3978
|
+
const segments = parseTemplate(inference);
|
|
3979
|
+
const regex = buildRegexPattern(segments);
|
|
3980
|
+
const match = test.match(regex);
|
|
3981
|
+
if (!match)
|
|
3982
|
+
return false;
|
|
3983
|
+
const result2 = {};
|
|
3984
|
+
for (const seg of segments) {
|
|
3985
|
+
if (seg.dynamic) {
|
|
3986
|
+
const rawVal = match.groups?.[seg.varName];
|
|
3987
|
+
if (rawVal === void 0)
|
|
3988
|
+
return false;
|
|
3989
|
+
result2[seg.varName.toLowerCase()] = convertValue(seg.type, rawVal);
|
|
3990
|
+
}
|
|
3991
|
+
}
|
|
3992
|
+
return result2;
|
|
3961
3993
|
}
|
|
3962
|
-
function
|
|
3963
|
-
return
|
|
3994
|
+
function infer(inference) {
|
|
3995
|
+
return (test) => {
|
|
3996
|
+
return matchTemplate(inference, test);
|
|
3997
|
+
};
|
|
3964
3998
|
}
|
|
3965
3999
|
|
|
3966
|
-
// src/
|
|
3967
|
-
function
|
|
3968
|
-
|
|
3969
|
-
return found ? found[prop] : void 0;
|
|
3970
|
-
}
|
|
3971
|
-
function lookupAlpha3Code(code, prop) {
|
|
3972
|
-
const found = ISO3166_1.find((i) => i.alpha3 === code);
|
|
3973
|
-
return found ? found[prop] : void 0;
|
|
3974
|
-
}
|
|
3975
|
-
function lookupName(name, prop) {
|
|
3976
|
-
const found = ISO3166_1.find((i) => i.name === name);
|
|
3977
|
-
return found ? found[prop] : void 0;
|
|
3978
|
-
}
|
|
3979
|
-
function lookupNumericCode(code, prop) {
|
|
3980
|
-
let num = isNumber(code) ? `${code}` : code;
|
|
3981
|
-
if (num.length === 1) {
|
|
3982
|
-
num = `00${num}`;
|
|
3983
|
-
} else if (num.length === 2) {
|
|
3984
|
-
num = `0${num}`;
|
|
3985
|
-
}
|
|
3986
|
-
const found = ISO3166_1.find((i) => i.countryCode === num);
|
|
3987
|
-
return found ? found[prop] : void 0;
|
|
4000
|
+
// src/literals/literal.ts
|
|
4001
|
+
function idLiteral(o) {
|
|
4002
|
+
return { ...o, id: o.id };
|
|
3988
4003
|
}
|
|
3989
|
-
function
|
|
3990
|
-
|
|
3991
|
-
return isNumberLike(code) ? lookupNumericCode(code, "name") : isIso3166Alpha2(uc) ? lookupAlpha2Code(uc, "name") : isIso3166Alpha3(uc) ? lookupAlpha3Code(uc, "name") : void 0;
|
|
4004
|
+
function nameLiteral(o) {
|
|
4005
|
+
return o;
|
|
3992
4006
|
}
|
|
3993
|
-
function
|
|
3994
|
-
|
|
3995
|
-
return isNumberLike(code) ? lookupNumericCode(code, "alpha2") : isIso3166Alpha2(uc) ? lookupAlpha2Code(uc, "alpha2") : isIso3166Alpha3(uc) ? lookupAlpha3Code(uc, "alpha2") : isIso3166CountryName(code) ? lookupName(code, "alpha2") : void 0;
|
|
4007
|
+
function kindLiteral(o) {
|
|
4008
|
+
return o;
|
|
3996
4009
|
}
|
|
3997
|
-
function
|
|
3998
|
-
|
|
3999
|
-
return isNumberLike(token) ? lookupNumericCode(token, "alpha3") : isIso3166Alpha2(uc) ? lookupAlpha2Code(uc, "alpha3") : isIso3166Alpha3(uc) ? lookupAlpha3Code(uc, "alpha3") : isIso3166CountryName(token) ? lookupName(token, "alpha3") : void 0;
|
|
4010
|
+
function idTypeGuard(_o) {
|
|
4011
|
+
return true;
|
|
4000
4012
|
}
|
|
4001
|
-
function
|
|
4002
|
-
|
|
4003
|
-
return isNumberLike(token) ? lookupNumericCode(token, "countryCode") : isIso3166Alpha2(uc) ? lookupAlpha2Code(uc, "countryCode") : isIso3166Alpha3(uc) ? lookupAlpha3Code(uc, "countryCode") : isIso3166CountryName(token) ? lookupName(token, "countryCode") : void 0;
|
|
4013
|
+
function literal(obj) {
|
|
4014
|
+
return obj;
|
|
4004
4015
|
}
|
|
4005
4016
|
|
|
4006
|
-
// src/
|
|
4007
|
-
function
|
|
4008
|
-
|
|
4009
|
-
const defUnique = withoutKeys(defVal, ...intersectingKeys);
|
|
4010
|
-
const overrideUnique = withoutKeys(defVal, ...intersectingKeys);
|
|
4011
|
-
const merged = {
|
|
4012
|
-
...intersectingKeys.reduce(
|
|
4013
|
-
(acc, key) => typeof override[key] === "undefined" ? { ...acc, [key]: defVal[key] } : { ...acc, [key]: override[key] },
|
|
4014
|
-
{}
|
|
4015
|
-
),
|
|
4016
|
-
...defUnique,
|
|
4017
|
-
...overrideUnique
|
|
4018
|
-
};
|
|
4019
|
-
return merged;
|
|
4017
|
+
// src/literals/lowercase.ts
|
|
4018
|
+
function lowercase(str) {
|
|
4019
|
+
return str.toLowerCase();
|
|
4020
4020
|
}
|
|
4021
4021
|
|
|
4022
|
-
// src/
|
|
4023
|
-
function
|
|
4024
|
-
return
|
|
4022
|
+
// src/literals/narrow.ts
|
|
4023
|
+
function narrow(...values) {
|
|
4024
|
+
return values.length === 1 ? values[0] : values;
|
|
4025
4025
|
}
|
|
4026
4026
|
|
|
4027
|
-
// src/
|
|
4028
|
-
function
|
|
4029
|
-
|
|
4027
|
+
// src/literals/pathJoin.ts
|
|
4028
|
+
function pathJoin(...segments) {
|
|
4029
|
+
const clean_path = segments.map((i) => stripTrailing(stripLeading(i, "/"), "/")).join("/");
|
|
4030
|
+
const original_path = segments.join("/");
|
|
4031
|
+
const pre = original_path.startsWith("/") ? "/" : "";
|
|
4032
|
+
const post = original_path.endsWith("/") ? "/" : "";
|
|
4033
|
+
return `${pre}${clean_path}${post}`;
|
|
4030
4034
|
}
|
|
4031
4035
|
|
|
4032
|
-
// src/
|
|
4033
|
-
|
|
4034
|
-
return val;
|
|
4035
|
-
}
|
|
4036
|
+
// src/literals/phone/asPhoneNumber.ts
|
|
4037
|
+
var asPhoneFormat = () => `NOT IMPLEMENTED`;
|
|
4036
4038
|
|
|
4037
|
-
// src/
|
|
4038
|
-
function
|
|
4039
|
-
return
|
|
4040
|
-
|
|
4041
|
-
|
|
4042
|
-
|
|
4043
|
-
}
|
|
4044
|
-
function optionalOrNull(value) {
|
|
4045
|
-
return value;
|
|
4039
|
+
// src/literals/phone/getPhoneCountryCode.ts
|
|
4040
|
+
function getPhoneCountryCode(phone) {
|
|
4041
|
+
return phone.trim().startsWith("+") || phone.trim().startsWith("00") ? retainWhile(
|
|
4042
|
+
stripLeading(stripLeading(phone.trim(), "+"), "00"),
|
|
4043
|
+
...NUMERIC_CHAR
|
|
4044
|
+
) : "";
|
|
4046
4045
|
}
|
|
4047
4046
|
|
|
4048
|
-
// src/
|
|
4049
|
-
function
|
|
4050
|
-
|
|
4047
|
+
// src/literals/phone/removePhoneCountryCode.ts
|
|
4048
|
+
function removePhoneCountryCode(phone) {
|
|
4049
|
+
const countryCode = getPhoneCountryCode(phone);
|
|
4050
|
+
return countryCode !== "" ? stripLeading(stripLeading(
|
|
4051
|
+
phone.trim(),
|
|
4052
|
+
"+",
|
|
4053
|
+
"00"
|
|
4054
|
+
), countryCode).trim() : phone.trim();
|
|
4051
4055
|
}
|
|
4052
4056
|
|
|
4053
|
-
// src/
|
|
4054
|
-
|
|
4055
|
-
|
|
4056
|
-
|
|
4057
|
-
|
|
4058
|
-
|
|
4059
|
-
|
|
4060
|
-
|
|
4061
|
-
|
|
4057
|
+
// src/literals/pluralize.ts
|
|
4058
|
+
var isException = (word) => Object.keys(PLURAL_EXCEPTIONS).includes(word);
|
|
4059
|
+
function endingIn(word, postfix) {
|
|
4060
|
+
switch (postfix) {
|
|
4061
|
+
case "is":
|
|
4062
|
+
return word.endsWith(postfix) ? `${word}es` : void 0;
|
|
4063
|
+
case "singular-noun":
|
|
4064
|
+
return SINGULAR_NOUN_ENDINGS.some((i) => word.endsWith(i)) ? split(word).every((i) => [...ALPHA_CHARS].includes(i)) ? `${word}es` : void 0 : void 0;
|
|
4065
|
+
case "f":
|
|
4066
|
+
return word.endsWith("f") ? `${stripTrailing(word, "f")}ves` : word.endsWith("fe") ? `${stripTrailing(word, "fe")}ves` : void 0;
|
|
4067
|
+
case "y":
|
|
4068
|
+
return word.endsWith("y") ? `${stripTrailing(word, "y")}ies` : void 0;
|
|
4062
4069
|
default:
|
|
4063
|
-
throw new Error(
|
|
4070
|
+
throw new Error(`endingIn received "${postfix}" as a postfix but this ending is not known!`);
|
|
4064
4071
|
}
|
|
4065
4072
|
}
|
|
4066
|
-
|
|
4067
|
-
|
|
4068
|
-
|
|
4073
|
+
function pluralize(word) {
|
|
4074
|
+
const right = rightWhitespace(word);
|
|
4075
|
+
const w = word.trimEnd();
|
|
4076
|
+
const result2 = isException(w) ? PLURAL_EXCEPTIONS[w] : endingIn(w, "is") || endingIn(w, "singular-noun") || endingIn(w, "f") || endingIn(w, "y") || `${w}s`;
|
|
4077
|
+
return `${result2}${right}`;
|
|
4069
4078
|
}
|
|
4070
4079
|
|
|
4071
|
-
// src/
|
|
4072
|
-
|
|
4073
|
-
|
|
4074
|
-
|
|
4075
|
-
|
|
4076
|
-
|
|
4077
|
-
|
|
4080
|
+
// src/literals/retainAfter.ts
|
|
4081
|
+
function retainAfter(content, ...find2) {
|
|
4082
|
+
const idx = Math.min(
|
|
4083
|
+
...find2.map((i) => content.indexOf(i)).filter((i) => i > -1)
|
|
4084
|
+
);
|
|
4085
|
+
const min = Math.min(...find2.map((i) => i.length));
|
|
4086
|
+
let len = Math.max(...find2.map((i) => i.length));
|
|
4087
|
+
if (min !== len) {
|
|
4088
|
+
if (!find2.includes(content.slice(idx, len))) {
|
|
4089
|
+
len = min;
|
|
4090
|
+
}
|
|
4091
|
+
}
|
|
4092
|
+
return idx && idx > 0 ? content.slice(idx + len) : "";
|
|
4078
4093
|
}
|
|
4079
|
-
|
|
4080
|
-
|
|
4081
|
-
|
|
4082
|
-
|
|
4094
|
+
function retainAfterInclusive(content, ...find2) {
|
|
4095
|
+
const minFound = Math.min(
|
|
4096
|
+
...find2.map((i) => content.indexOf(i)).filter((i) => i > -1)
|
|
4097
|
+
);
|
|
4098
|
+
return minFound > 0 ? content.slice(minFound) : "";
|
|
4083
4099
|
}
|
|
4084
4100
|
|
|
4085
|
-
// src/
|
|
4086
|
-
function
|
|
4087
|
-
|
|
4101
|
+
// src/literals/retainChars.ts
|
|
4102
|
+
function retainChars(content, ...retain2) {
|
|
4103
|
+
const chars = asChars(content);
|
|
4104
|
+
return chars.filter((c) => retain2.includes(c)).join("");
|
|
4088
4105
|
}
|
|
4089
4106
|
|
|
4090
4107
|
// src/literals/retainUntil.ts
|
|
@@ -4763,6 +4780,11 @@ function createTypeToken(kind) {
|
|
|
4763
4780
|
return isAtomicKind(kind) ? `<<${kind}>>` : isSingletonKind(kind) ? singletonApi(kind) : isSetBasedKind(kind) ? setApi(kind) : isFnBasedKind(kind) ? handleDoneFn(fnTokenClosure(kind, unset, unset)) : "<<never>>";
|
|
4764
4781
|
}
|
|
4765
4782
|
|
|
4783
|
+
// src/runtime-types/tokens/fromDefineObject.ts
|
|
4784
|
+
function fromDefineObject(defn) {
|
|
4785
|
+
return defn;
|
|
4786
|
+
}
|
|
4787
|
+
|
|
4766
4788
|
// src/runtime-types/tokens/getTokenKind.ts
|
|
4767
4789
|
function getTokenKind(token) {
|
|
4768
4790
|
const bare = stripSurround("<<", ">>")(token);
|
|
@@ -4863,6 +4885,7 @@ export {
|
|
|
4863
4885
|
filter,
|
|
4864
4886
|
find,
|
|
4865
4887
|
fnMeta,
|
|
4888
|
+
fromDefineObject,
|
|
4866
4889
|
get,
|
|
4867
4890
|
getDaysBetween,
|
|
4868
4891
|
getEach,
|
|
@@ -4871,6 +4894,7 @@ export {
|
|
|
4871
4894
|
getToday,
|
|
4872
4895
|
getTokenKind,
|
|
4873
4896
|
getTomorrow,
|
|
4897
|
+
getTypeSubtype,
|
|
4874
4898
|
getUrlPath,
|
|
4875
4899
|
getUrlPort,
|
|
4876
4900
|
getUrlProtocol,
|
|
@@ -5111,6 +5135,7 @@ export {
|
|
|
5111
5135
|
isTupleToken,
|
|
5112
5136
|
isTurkishNewsUrl,
|
|
5113
5137
|
isTypeOf,
|
|
5138
|
+
isTypeSubtype,
|
|
5114
5139
|
isTypeToken,
|
|
5115
5140
|
isTypeTokenKind,
|
|
5116
5141
|
isTypeTuple,
|