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
|
@@ -242,6 +242,7 @@ __export(index_exports, {
|
|
|
242
242
|
box: () => box,
|
|
243
243
|
boxDictionaryValues: () => boxDictionaryValues,
|
|
244
244
|
capitalize: () => capitalize,
|
|
245
|
+
cardType: () => cardType,
|
|
245
246
|
choices: () => choices,
|
|
246
247
|
createConstant: () => createConstant,
|
|
247
248
|
createConverter: () => createConverter,
|
|
@@ -452,6 +453,7 @@ __export(index_exports, {
|
|
|
452
453
|
isMapToken: () => isMapToken,
|
|
453
454
|
isMassMetric: () => isMassMetric,
|
|
454
455
|
isMassUom: () => isMassUom,
|
|
456
|
+
isMastercard: () => isMastercard,
|
|
455
457
|
isMetric: () => isMetric,
|
|
456
458
|
isMexicanNewsUrl: () => isMexicanNewsUrl,
|
|
457
459
|
isMoment: () => isMoment,
|
|
@@ -557,6 +559,7 @@ __export(index_exports, {
|
|
|
557
559
|
isUsStateAbbreviation: () => isUsStateAbbreviation,
|
|
558
560
|
isUsStateName: () => isUsStateName,
|
|
559
561
|
isVariable: () => isVariable,
|
|
562
|
+
isVisa: () => isVisa,
|
|
560
563
|
isVisaMastercard: () => isVisaMastercard,
|
|
561
564
|
isVoltageMetric: () => isVoltageMetric,
|
|
562
565
|
isVoltageUom: () => isVoltageUom,
|
|
@@ -7160,13 +7163,23 @@ function isYesterday(test) {
|
|
|
7160
7163
|
}
|
|
7161
7164
|
return false;
|
|
7162
7165
|
}
|
|
7163
|
-
function
|
|
7164
|
-
if (isString(val)) {
|
|
7166
|
+
function isVisa(val) {
|
|
7167
|
+
if (isString(val) && val.startsWith("4")) {
|
|
7165
7168
|
const parts = val.split(" ");
|
|
7166
7169
|
return parts.length === 4 && parts.every((i) => isNumberLike(i) && i.length === 4);
|
|
7167
7170
|
}
|
|
7168
7171
|
return false;
|
|
7169
7172
|
}
|
|
7173
|
+
function isMastercard(val) {
|
|
7174
|
+
if (isString(val) && val.startsWith("4")) {
|
|
7175
|
+
const parts = val.split(" ");
|
|
7176
|
+
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));
|
|
7177
|
+
}
|
|
7178
|
+
return false;
|
|
7179
|
+
}
|
|
7180
|
+
function isVisaMastercard(val) {
|
|
7181
|
+
return isVisa(val) || isMastercard(val);
|
|
7182
|
+
}
|
|
7170
7183
|
function isAmericanExpress(val) {
|
|
7171
7184
|
if (isString(val)) {
|
|
7172
7185
|
const parts = val.split(" ");
|
|
@@ -7179,6 +7192,57 @@ function isAmericanExpress(val) {
|
|
|
7179
7192
|
function isCreditCard(val) {
|
|
7180
7193
|
return isVisaMastercard(val) || isAmericanExpress(val);
|
|
7181
7194
|
}
|
|
7195
|
+
function cardType(cardNumber) {
|
|
7196
|
+
const cleanedNumber = String(cardNumber).replace(/\D/g, "");
|
|
7197
|
+
const length = cleanedNumber.length;
|
|
7198
|
+
if (!isValidLength(length)) {
|
|
7199
|
+
return "invalid";
|
|
7200
|
+
}
|
|
7201
|
+
if (!luhnCheck(cleanedNumber)) {
|
|
7202
|
+
return "invalid";
|
|
7203
|
+
}
|
|
7204
|
+
const cardTypes = [
|
|
7205
|
+
{ name: "Visa", lengths: [16], prefixes: [/^4/] },
|
|
7206
|
+
{ 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)/] },
|
|
7207
|
+
{ name: "American Express", lengths: [15], prefixes: [/^3[47]/] },
|
|
7208
|
+
{ 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)/] },
|
|
7209
|
+
{ name: "JCB", lengths: [16], prefixes: [/^(35|2131|1800)/] },
|
|
7210
|
+
{ name: "Diners Club", lengths: [14, 16], prefixes: [/^(30[0-5]|36|38)/] },
|
|
7211
|
+
{ name: "China UnionPay", lengths: [16, 17, 18, 19], prefixes: [/^(62|88)/] },
|
|
7212
|
+
{ name: "Maestro", lengths: [12, 13, 14, 15, 16, 17, 18, 19], prefixes: [/^(5018|5020|5038|6304)/] },
|
|
7213
|
+
{ name: "Solo", lengths: [16, 18, 19], prefixes: [/^(6334|6767)/] }
|
|
7214
|
+
];
|
|
7215
|
+
for (const type of cardTypes) {
|
|
7216
|
+
if (type.lengths.includes(length)) {
|
|
7217
|
+
for (const prefix of type.prefixes) {
|
|
7218
|
+
if (prefix.test(cleanedNumber)) {
|
|
7219
|
+
return type.name;
|
|
7220
|
+
}
|
|
7221
|
+
}
|
|
7222
|
+
}
|
|
7223
|
+
}
|
|
7224
|
+
return "invalid";
|
|
7225
|
+
}
|
|
7226
|
+
function isValidLength(length) {
|
|
7227
|
+
const validLengths = [13, 14, 15, 16, 17, 18, 19];
|
|
7228
|
+
return validLengths.includes(length);
|
|
7229
|
+
}
|
|
7230
|
+
function luhnCheck(num) {
|
|
7231
|
+
let sum = 0;
|
|
7232
|
+
let double = false;
|
|
7233
|
+
for (let i = num.length - 1; i >= 0; i--) {
|
|
7234
|
+
let n = Number.parseInt(num.charAt(i), 10);
|
|
7235
|
+
if (double) {
|
|
7236
|
+
n *= 2;
|
|
7237
|
+
if (n > 9) {
|
|
7238
|
+
n -= 9;
|
|
7239
|
+
}
|
|
7240
|
+
}
|
|
7241
|
+
sum += n;
|
|
7242
|
+
double = !double;
|
|
7243
|
+
}
|
|
7244
|
+
return sum % 10 === 0;
|
|
7245
|
+
}
|
|
7182
7246
|
function isString(value) {
|
|
7183
7247
|
return typeof value === "string";
|
|
7184
7248
|
}
|
|
@@ -8186,18 +8250,10 @@ function createMapper() {
|
|
|
8186
8250
|
};
|
|
8187
8251
|
}
|
|
8188
8252
|
function mergeObjects(defVal, override) {
|
|
8189
|
-
|
|
8190
|
-
|
|
8191
|
-
|
|
8192
|
-
const merged = {
|
|
8193
|
-
...intersectingKeys.reduce(
|
|
8194
|
-
(acc, key) => typeof override[key] === "undefined" ? { ...acc, [key]: defVal[key] } : { ...acc, [key]: override[key] },
|
|
8195
|
-
{}
|
|
8196
|
-
),
|
|
8197
|
-
...defUnique,
|
|
8198
|
-
...overrideUnique
|
|
8253
|
+
return {
|
|
8254
|
+
...defVal,
|
|
8255
|
+
...override
|
|
8199
8256
|
};
|
|
8200
|
-
return merged;
|
|
8201
8257
|
}
|
|
8202
8258
|
function mergeScalars(a, b) {
|
|
8203
8259
|
return isUndefined(b) ? a : b;
|
|
@@ -8697,6 +8753,7 @@ var ExifSaturation = /* @__PURE__ */ ((ExifSaturation2) => {
|
|
|
8697
8753
|
box,
|
|
8698
8754
|
boxDictionaryValues,
|
|
8699
8755
|
capitalize,
|
|
8756
|
+
cardType,
|
|
8700
8757
|
choices,
|
|
8701
8758
|
createConstant,
|
|
8702
8759
|
createConverter,
|
|
@@ -8907,6 +8964,7 @@ var ExifSaturation = /* @__PURE__ */ ((ExifSaturation2) => {
|
|
|
8907
8964
|
isMapToken,
|
|
8908
8965
|
isMassMetric,
|
|
8909
8966
|
isMassUom,
|
|
8967
|
+
isMastercard,
|
|
8910
8968
|
isMetric,
|
|
8911
8969
|
isMexicanNewsUrl,
|
|
8912
8970
|
isMoment,
|
|
@@ -9012,6 +9070,7 @@ var ExifSaturation = /* @__PURE__ */ ((ExifSaturation2) => {
|
|
|
9012
9070
|
isUsStateAbbreviation,
|
|
9013
9071
|
isUsStateName,
|
|
9014
9072
|
isVariable,
|
|
9073
|
+
isVisa,
|
|
9015
9074
|
isVisaMastercard,
|
|
9016
9075
|
isVoltageMetric,
|
|
9017
9076
|
isVoltageUom,
|