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.
@@ -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,
@@ -138,6 +139,7 @@ __export(index_exports, {
138
139
  isAccelerationUom: () => isAccelerationUom,
139
140
  isAlpha: () => isAlpha,
140
141
  isAmazonUrl: () => isAmazonUrl,
142
+ isAmericanExpress: () => isAmericanExpress,
141
143
  isApi: () => isApi,
142
144
  isApiSurface: () => isApiSurface,
143
145
  isAppleUrl: () => isAppleUrl,
@@ -165,6 +167,7 @@ __export(index_exports, {
165
167
  isCountryCode2: () => isCountryCode2,
166
168
  isCountryCode3: () => isCountryCode3,
167
169
  isCountryName: () => isCountryName,
170
+ isCreditCard: () => isCreditCard,
168
171
  isCssAspectRatio: () => isCssAspectRatio,
169
172
  isCsv: () => isCsv,
170
173
  isCurrentMetric: () => isCurrentMetric,
@@ -248,6 +251,7 @@ __export(index_exports, {
248
251
  isMapToken: () => isMapToken,
249
252
  isMassMetric: () => isMassMetric,
250
253
  isMassUom: () => isMassUom,
254
+ isMastercard: () => isMastercard,
251
255
  isMetric: () => isMetric,
252
256
  isMexicanNewsUrl: () => isMexicanNewsUrl,
253
257
  isMoment: () => isMoment,
@@ -353,6 +357,8 @@ __export(index_exports, {
353
357
  isUsStateAbbreviation: () => isUsStateAbbreviation,
354
358
  isUsStateName: () => isUsStateName,
355
359
  isVariable: () => isVariable,
360
+ isVisa: () => isVisa,
361
+ isVisaMastercard: () => isVisaMastercard,
356
362
  isVoltageMetric: () => isVoltageMetric,
357
363
  isVoltageUom: () => isVoltageUom,
358
364
  isVolumeMetric: () => isVolumeMetric,
@@ -4694,6 +4700,88 @@ function isYesterday(test) {
4694
4700
  return false;
4695
4701
  }
4696
4702
 
4703
+ // src/type-guards/finance/CreditCards.ts
4704
+ function isVisa(val) {
4705
+ if (isString(val) && val.startsWith("4")) {
4706
+ const parts = val.split(" ");
4707
+ return parts.length === 4 && parts.every((i) => isNumberLike(i) && i.length === 4);
4708
+ }
4709
+ return false;
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
+ }
4721
+ function isAmericanExpress(val) {
4722
+ if (isString(val)) {
4723
+ const parts = val.split(" ");
4724
+ return parts.length === 3 && parts.every(
4725
+ (i) => isNumberLike(i) && parts[0].length === 4 && parts[1].length === 6
4726
+ );
4727
+ }
4728
+ return false;
4729
+ }
4730
+ function isCreditCard(val) {
4731
+ return isVisaMastercard(val) || isAmericanExpress(val);
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
+ }
4784
+
4697
4785
  // src/type-guards/isString.ts
4698
4786
  function isString(value) {
4699
4787
  return typeof value === "string";
@@ -6073,6 +6161,7 @@ function asVueRef(value) {
6073
6161
  box,
6074
6162
  boxDictionaryValues,
6075
6163
  capitalize,
6164
+ cardType,
6076
6165
  choices,
6077
6166
  createConverter,
6078
6167
  createCssKeyframe,
@@ -6170,6 +6259,7 @@ function asVueRef(value) {
6170
6259
  isAccelerationUom,
6171
6260
  isAlpha,
6172
6261
  isAmazonUrl,
6262
+ isAmericanExpress,
6173
6263
  isApi,
6174
6264
  isApiSurface,
6175
6265
  isAppleUrl,
@@ -6197,6 +6287,7 @@ function asVueRef(value) {
6197
6287
  isCountryCode2,
6198
6288
  isCountryCode3,
6199
6289
  isCountryName,
6290
+ isCreditCard,
6200
6291
  isCssAspectRatio,
6201
6292
  isCsv,
6202
6293
  isCurrentMetric,
@@ -6280,6 +6371,7 @@ function asVueRef(value) {
6280
6371
  isMapToken,
6281
6372
  isMassMetric,
6282
6373
  isMassUom,
6374
+ isMastercard,
6283
6375
  isMetric,
6284
6376
  isMexicanNewsUrl,
6285
6377
  isMoment,
@@ -6385,6 +6477,8 @@ function asVueRef(value) {
6385
6477
  isUsStateAbbreviation,
6386
6478
  isUsStateName,
6387
6479
  isVariable,
6480
+ isVisa,
6481
+ isVisaMastercard,
6388
6482
  isVoltageMetric,
6389
6483
  isVoltageUom,
6390
6484
  isVolumeMetric,