inferred-types 0.55.6 → 0.55.8
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 +72 -13
- package/modules/inferred-types/dist/index.cjs.map +1 -1
- package/modules/inferred-types/dist/index.d.ts +48 -16
- package/modules/inferred-types/dist/index.js +69 -13
- package/modules/inferred-types/dist/index.js.map +1 -1
- package/modules/runtime/dist/index.cjs +72 -13
- package/modules/runtime/dist/index.cjs.map +1 -1
- package/modules/runtime/dist/index.d.ts +30 -9
- package/modules/runtime/dist/index.js +69 -13
- package/modules/runtime/dist/index.js.map +1 -1
- package/modules/types/dist/index.d.ts +14 -3
- package/package.json +7 -7
|
@@ -41,6 +41,7 @@ __export(index_exports, {
|
|
|
41
41
|
box: () => box,
|
|
42
42
|
boxDictionaryValues: () => boxDictionaryValues,
|
|
43
43
|
capitalize: () => capitalize,
|
|
44
|
+
cardType: () => cardType,
|
|
44
45
|
choices: () => choices,
|
|
45
46
|
createConverter: () => createConverter,
|
|
46
47
|
createCssKeyframe: () => createCssKeyframe,
|
|
@@ -250,6 +251,7 @@ __export(index_exports, {
|
|
|
250
251
|
isMapToken: () => isMapToken,
|
|
251
252
|
isMassMetric: () => isMassMetric,
|
|
252
253
|
isMassUom: () => isMassUom,
|
|
254
|
+
isMastercard: () => isMastercard,
|
|
253
255
|
isMetric: () => isMetric,
|
|
254
256
|
isMexicanNewsUrl: () => isMexicanNewsUrl,
|
|
255
257
|
isMoment: () => isMoment,
|
|
@@ -355,6 +357,7 @@ __export(index_exports, {
|
|
|
355
357
|
isUsStateAbbreviation: () => isUsStateAbbreviation,
|
|
356
358
|
isUsStateName: () => isUsStateName,
|
|
357
359
|
isVariable: () => isVariable,
|
|
360
|
+
isVisa: () => isVisa,
|
|
358
361
|
isVisaMastercard: () => isVisaMastercard,
|
|
359
362
|
isVoltageMetric: () => isVoltageMetric,
|
|
360
363
|
isVoltageUom: () => isVoltageUom,
|
|
@@ -4698,13 +4701,23 @@ function isYesterday(test) {
|
|
|
4698
4701
|
}
|
|
4699
4702
|
|
|
4700
4703
|
// src/type-guards/finance/CreditCards.ts
|
|
4701
|
-
function
|
|
4702
|
-
if (isString(val)) {
|
|
4704
|
+
function isVisa(val) {
|
|
4705
|
+
if (isString(val) && val.startsWith("4")) {
|
|
4703
4706
|
const parts = val.split(" ");
|
|
4704
4707
|
return parts.length === 4 && parts.every((i) => isNumberLike(i) && i.length === 4);
|
|
4705
4708
|
}
|
|
4706
4709
|
return false;
|
|
4707
4710
|
}
|
|
4711
|
+
function isMastercard(val) {
|
|
4712
|
+
if (isString(val) && val.startsWith("4")) {
|
|
4713
|
+
const parts = val.split(" ");
|
|
4714
|
+
return parts.length === 4 && parts.every((i) => isNumberLike(i) && i.length === 4) && ["51", "55", "22", "23", "24", "25", "26", "27"].some((i) => val.startsWith(i));
|
|
4715
|
+
}
|
|
4716
|
+
return false;
|
|
4717
|
+
}
|
|
4718
|
+
function isVisaMastercard(val) {
|
|
4719
|
+
return isVisa(val) || isMastercard(val);
|
|
4720
|
+
}
|
|
4708
4721
|
function isAmericanExpress(val) {
|
|
4709
4722
|
if (isString(val)) {
|
|
4710
4723
|
const parts = val.split(" ");
|
|
@@ -4717,6 +4730,57 @@ function isAmericanExpress(val) {
|
|
|
4717
4730
|
function isCreditCard(val) {
|
|
4718
4731
|
return isVisaMastercard(val) || isAmericanExpress(val);
|
|
4719
4732
|
}
|
|
4733
|
+
function cardType(cardNumber) {
|
|
4734
|
+
const cleanedNumber = String(cardNumber).replace(/\D/g, "");
|
|
4735
|
+
const length = cleanedNumber.length;
|
|
4736
|
+
if (!isValidLength(length)) {
|
|
4737
|
+
return "invalid";
|
|
4738
|
+
}
|
|
4739
|
+
if (!luhnCheck(cleanedNumber)) {
|
|
4740
|
+
return "invalid";
|
|
4741
|
+
}
|
|
4742
|
+
const cardTypes = [
|
|
4743
|
+
{ name: "Visa", lengths: [16], prefixes: [/^4/] },
|
|
4744
|
+
{ name: "Mastercard", lengths: [16], prefixes: [/^(51|52|53|54|55|222[1-9]|22[3-9]\d|2[3-6]\d{2}|27[01]\d|2720)/] },
|
|
4745
|
+
{ name: "American Express", lengths: [15], prefixes: [/^3[47]/] },
|
|
4746
|
+
{ name: "Discover", lengths: [16], prefixes: [/^(6011|622(12[6-9]|1[3-9]\d|2[0-4]\d|25\d|6[4-9]|7[0-4]|8[0-4]|9\d)|64[4-9]|65)/] },
|
|
4747
|
+
{ name: "JCB", lengths: [16], prefixes: [/^(35|2131|1800)/] },
|
|
4748
|
+
{ name: "Diners Club", lengths: [14, 16], prefixes: [/^(30[0-5]|36|38)/] },
|
|
4749
|
+
{ name: "China UnionPay", lengths: [16, 17, 18, 19], prefixes: [/^(62|88)/] },
|
|
4750
|
+
{ name: "Maestro", lengths: [12, 13, 14, 15, 16, 17, 18, 19], prefixes: [/^(5018|5020|5038|6304)/] },
|
|
4751
|
+
{ name: "Solo", lengths: [16, 18, 19], prefixes: [/^(6334|6767)/] }
|
|
4752
|
+
];
|
|
4753
|
+
for (const type of cardTypes) {
|
|
4754
|
+
if (type.lengths.includes(length)) {
|
|
4755
|
+
for (const prefix of type.prefixes) {
|
|
4756
|
+
if (prefix.test(cleanedNumber)) {
|
|
4757
|
+
return type.name;
|
|
4758
|
+
}
|
|
4759
|
+
}
|
|
4760
|
+
}
|
|
4761
|
+
}
|
|
4762
|
+
return "invalid";
|
|
4763
|
+
}
|
|
4764
|
+
function isValidLength(length) {
|
|
4765
|
+
const validLengths = [13, 14, 15, 16, 17, 18, 19];
|
|
4766
|
+
return validLengths.includes(length);
|
|
4767
|
+
}
|
|
4768
|
+
function luhnCheck(num) {
|
|
4769
|
+
let sum = 0;
|
|
4770
|
+
let double = false;
|
|
4771
|
+
for (let i = num.length - 1; i >= 0; i--) {
|
|
4772
|
+
let n = Number.parseInt(num.charAt(i), 10);
|
|
4773
|
+
if (double) {
|
|
4774
|
+
n *= 2;
|
|
4775
|
+
if (n > 9) {
|
|
4776
|
+
n -= 9;
|
|
4777
|
+
}
|
|
4778
|
+
}
|
|
4779
|
+
sum += n;
|
|
4780
|
+
double = !double;
|
|
4781
|
+
}
|
|
4782
|
+
return sum % 10 === 0;
|
|
4783
|
+
}
|
|
4720
4784
|
|
|
4721
4785
|
// src/type-guards/isString.ts
|
|
4722
4786
|
function isString(value) {
|
|
@@ -5954,18 +6018,10 @@ function createMapper() {
|
|
|
5954
6018
|
|
|
5955
6019
|
// src/type-conversion/mergeObjects.ts
|
|
5956
6020
|
function mergeObjects(defVal, override) {
|
|
5957
|
-
|
|
5958
|
-
|
|
5959
|
-
|
|
5960
|
-
const merged = {
|
|
5961
|
-
...intersectingKeys.reduce(
|
|
5962
|
-
(acc, key) => typeof override[key] === "undefined" ? { ...acc, [key]: defVal[key] } : { ...acc, [key]: override[key] },
|
|
5963
|
-
{}
|
|
5964
|
-
),
|
|
5965
|
-
...defUnique,
|
|
5966
|
-
...overrideUnique
|
|
6021
|
+
return {
|
|
6022
|
+
...defVal,
|
|
6023
|
+
...override
|
|
5967
6024
|
};
|
|
5968
|
-
return merged;
|
|
5969
6025
|
}
|
|
5970
6026
|
|
|
5971
6027
|
// src/type-conversion/mergeScalars.ts
|
|
@@ -6097,6 +6153,7 @@ function asVueRef(value) {
|
|
|
6097
6153
|
box,
|
|
6098
6154
|
boxDictionaryValues,
|
|
6099
6155
|
capitalize,
|
|
6156
|
+
cardType,
|
|
6100
6157
|
choices,
|
|
6101
6158
|
createConverter,
|
|
6102
6159
|
createCssKeyframe,
|
|
@@ -6306,6 +6363,7 @@ function asVueRef(value) {
|
|
|
6306
6363
|
isMapToken,
|
|
6307
6364
|
isMassMetric,
|
|
6308
6365
|
isMassUom,
|
|
6366
|
+
isMastercard,
|
|
6309
6367
|
isMetric,
|
|
6310
6368
|
isMexicanNewsUrl,
|
|
6311
6369
|
isMoment,
|
|
@@ -6411,6 +6469,7 @@ function asVueRef(value) {
|
|
|
6411
6469
|
isUsStateAbbreviation,
|
|
6412
6470
|
isUsStateName,
|
|
6413
6471
|
isVariable,
|
|
6472
|
+
isVisa,
|
|
6414
6473
|
isVisaMastercard,
|
|
6415
6474
|
isVoltageMetric,
|
|
6416
6475
|
isVoltageUom,
|