inferred-types 0.55.5 → 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.
@@ -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,
@@ -340,6 +341,7 @@ __export(index_exports, {
340
341
  isAccelerationUom: () => isAccelerationUom,
341
342
  isAlpha: () => isAlpha,
342
343
  isAmazonUrl: () => isAmazonUrl,
344
+ isAmericanExpress: () => isAmericanExpress,
343
345
  isApi: () => isApi,
344
346
  isApiSurface: () => isApiSurface,
345
347
  isAppleUrl: () => isAppleUrl,
@@ -367,6 +369,7 @@ __export(index_exports, {
367
369
  isCountryCode2: () => isCountryCode2,
368
370
  isCountryCode3: () => isCountryCode3,
369
371
  isCountryName: () => isCountryName,
372
+ isCreditCard: () => isCreditCard,
370
373
  isCssAspectRatio: () => isCssAspectRatio,
371
374
  isCsv: () => isCsv,
372
375
  isCurrentMetric: () => isCurrentMetric,
@@ -450,6 +453,7 @@ __export(index_exports, {
450
453
  isMapToken: () => isMapToken,
451
454
  isMassMetric: () => isMassMetric,
452
455
  isMassUom: () => isMassUom,
456
+ isMastercard: () => isMastercard,
453
457
  isMetric: () => isMetric,
454
458
  isMexicanNewsUrl: () => isMexicanNewsUrl,
455
459
  isMoment: () => isMoment,
@@ -555,6 +559,8 @@ __export(index_exports, {
555
559
  isUsStateAbbreviation: () => isUsStateAbbreviation,
556
560
  isUsStateName: () => isUsStateName,
557
561
  isVariable: () => isVariable,
562
+ isVisa: () => isVisa,
563
+ isVisaMastercard: () => isVisaMastercard,
558
564
  isVoltageMetric: () => isVoltageMetric,
559
565
  isVoltageUom: () => isVoltageUom,
560
566
  isVolumeMetric: () => isVolumeMetric,
@@ -7157,6 +7163,86 @@ function isYesterday(test) {
7157
7163
  }
7158
7164
  return false;
7159
7165
  }
7166
+ function isVisa(val) {
7167
+ if (isString(val) && val.startsWith("4")) {
7168
+ const parts = val.split(" ");
7169
+ return parts.length === 4 && parts.every((i) => isNumberLike(i) && i.length === 4);
7170
+ }
7171
+ return false;
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
+ }
7183
+ function isAmericanExpress(val) {
7184
+ if (isString(val)) {
7185
+ const parts = val.split(" ");
7186
+ return parts.length === 3 && parts.every(
7187
+ (i) => isNumberLike(i) && parts[0].length === 4 && parts[1].length === 6
7188
+ );
7189
+ }
7190
+ return false;
7191
+ }
7192
+ function isCreditCard(val) {
7193
+ return isVisaMastercard(val) || isAmericanExpress(val);
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
+ }
7160
7246
  function isString(value) {
7161
7247
  return typeof value === "string";
7162
7248
  }
@@ -8675,6 +8761,7 @@ var ExifSaturation = /* @__PURE__ */ ((ExifSaturation2) => {
8675
8761
  box,
8676
8762
  boxDictionaryValues,
8677
8763
  capitalize,
8764
+ cardType,
8678
8765
  choices,
8679
8766
  createConstant,
8680
8767
  createConverter,
@@ -8773,6 +8860,7 @@ var ExifSaturation = /* @__PURE__ */ ((ExifSaturation2) => {
8773
8860
  isAccelerationUom,
8774
8861
  isAlpha,
8775
8862
  isAmazonUrl,
8863
+ isAmericanExpress,
8776
8864
  isApi,
8777
8865
  isApiSurface,
8778
8866
  isAppleUrl,
@@ -8800,6 +8888,7 @@ var ExifSaturation = /* @__PURE__ */ ((ExifSaturation2) => {
8800
8888
  isCountryCode2,
8801
8889
  isCountryCode3,
8802
8890
  isCountryName,
8891
+ isCreditCard,
8803
8892
  isCssAspectRatio,
8804
8893
  isCsv,
8805
8894
  isCurrentMetric,
@@ -8883,6 +8972,7 @@ var ExifSaturation = /* @__PURE__ */ ((ExifSaturation2) => {
8883
8972
  isMapToken,
8884
8973
  isMassMetric,
8885
8974
  isMassUom,
8975
+ isMastercard,
8886
8976
  isMetric,
8887
8977
  isMexicanNewsUrl,
8888
8978
  isMoment,
@@ -8988,6 +9078,8 @@ var ExifSaturation = /* @__PURE__ */ ((ExifSaturation2) => {
8988
9078
  isUsStateAbbreviation,
8989
9079
  isUsStateName,
8990
9080
  isVariable,
9081
+ isVisa,
9082
+ isVisaMastercard,
8991
9083
  isVoltageMetric,
8992
9084
  isVoltageUom,
8993
9085
  isVolumeMetric,