inferred-types 0.55.6 → 0.55.7
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 +69 -2
- package/modules/inferred-types/dist/index.cjs.map +1 -1
- package/modules/inferred-types/dist/index.d.ts +34 -5
- package/modules/inferred-types/dist/index.js +66 -2
- package/modules/inferred-types/dist/index.js.map +1 -1
- package/modules/runtime/dist/index.cjs +69 -2
- package/modules/runtime/dist/index.cjs.map +1 -1
- package/modules/runtime/dist/index.d.ts +21 -3
- package/modules/runtime/dist/index.js +66 -2
- package/modules/runtime/dist/index.js.map +1 -1
- package/modules/types/dist/index.d.ts +14 -3
- package/package.json +1 -1
|
@@ -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) {
|
|
@@ -6097,6 +6161,7 @@ function asVueRef(value) {
|
|
|
6097
6161
|
box,
|
|
6098
6162
|
boxDictionaryValues,
|
|
6099
6163
|
capitalize,
|
|
6164
|
+
cardType,
|
|
6100
6165
|
choices,
|
|
6101
6166
|
createConverter,
|
|
6102
6167
|
createCssKeyframe,
|
|
@@ -6306,6 +6371,7 @@ function asVueRef(value) {
|
|
|
6306
6371
|
isMapToken,
|
|
6307
6372
|
isMassMetric,
|
|
6308
6373
|
isMassUom,
|
|
6374
|
+
isMastercard,
|
|
6309
6375
|
isMetric,
|
|
6310
6376
|
isMexicanNewsUrl,
|
|
6311
6377
|
isMoment,
|
|
@@ -6411,6 +6477,7 @@ function asVueRef(value) {
|
|
|
6411
6477
|
isUsStateAbbreviation,
|
|
6412
6478
|
isUsStateName,
|
|
6413
6479
|
isVariable,
|
|
6480
|
+
isVisa,
|
|
6414
6481
|
isVisaMastercard,
|
|
6415
6482
|
isVoltageMetric,
|
|
6416
6483
|
isVoltageUom,
|