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
|
@@ -7859,9 +7859,12 @@ type IterateOver<TContent extends readonly unknown[], TTrailing extends string>
|
|
|
7859
7859
|
type EnsureTrailing<TContent extends string | number | readonly (string | number)[], TTrailing extends string | number> = IsWideType<TContent> extends true ? IsWideType<TTrailing> extends true ? TContent : `${string}${TTrailing}` : IsWideType<TTrailing> extends true ? IsString<TContent> extends true ? `${AsString<TContent>}${string}` : never : TContent extends number ? AsNumber<P<`${TContent}`, `${TTrailing}`>> : TContent extends string ? P<TContent, `${TTrailing}`> : TContent extends readonly unknown[] ? IterateOver<TContent, `${TTrailing}`> : never;
|
|
7860
7860
|
|
|
7861
7861
|
/** the shae for an American Express long number */
|
|
7862
|
-
type AmericanExpress = `${number} ${number} ${number}`;
|
|
7862
|
+
type AmericanExpress = `${"34" | "37"}${number} ${number} ${number}`;
|
|
7863
|
+
/** the shape of Visa long numbers */
|
|
7864
|
+
type Visa = `4${number} ${number} ${number} ${number}`;
|
|
7865
|
+
type Mastercard = `${"51" | "55"}${number} ${number} ${number} ${number}` | `2${"2" | "3" | "4" | "5" | "6" | "7"}${number} ${number} ${number} ${number}`;
|
|
7863
7866
|
/** the shape for a VISA/Mastercard long number */
|
|
7864
|
-
type VisaMastercard =
|
|
7867
|
+
type VisaMastercard = Visa | Mastercard;
|
|
7865
7868
|
/**
|
|
7866
7869
|
* Represents the string literal type for either a Mastercard/VISA
|
|
7867
7870
|
* format or an American Express card.
|
|
@@ -14041,9 +14044,24 @@ declare function isTomorrow(test: unknown): boolean;
|
|
|
14041
14044
|
*/
|
|
14042
14045
|
declare function isYesterday(test: unknown): boolean;
|
|
14043
14046
|
|
|
14047
|
+
declare function isVisa(val: unknown): val is Visa;
|
|
14048
|
+
declare function isMastercard(val: unknown): val is Mastercard;
|
|
14044
14049
|
declare function isVisaMastercard(val: unknown): val is VisaMastercard;
|
|
14045
14050
|
declare function isAmericanExpress(val: unknown): val is AmericanExpress;
|
|
14046
14051
|
declare function isCreditCard(val: unknown): val is CreditCard;
|
|
14052
|
+
/**
|
|
14053
|
+
* Given a card's long number, attempt to match this to a card type from:
|
|
14054
|
+
*
|
|
14055
|
+
* - Visa, Mastercard
|
|
14056
|
+
* - American Express
|
|
14057
|
+
* - Discover
|
|
14058
|
+
* - JCB
|
|
14059
|
+
* - Diners Club
|
|
14060
|
+
* - China UnionPay
|
|
14061
|
+
* - Maestro
|
|
14062
|
+
* - Solo
|
|
14063
|
+
*/
|
|
14064
|
+
declare function cardType(cardNumber: string | number): string;
|
|
14047
14065
|
|
|
14048
14066
|
/**
|
|
14049
14067
|
* Type guard which checks whether `val` is a 2 character country
|
|
@@ -15475,4 +15493,4 @@ declare function isVueRef(val: unknown): val is VueRef;
|
|
|
15475
15493
|
*/
|
|
15476
15494
|
declare function asVueRef<T extends Narrowable>(value: T): VueRef<T>;
|
|
15477
15495
|
|
|
15478
|
-
export { type AsClassSelector, type AsList, type BoxValue, type BoxedFnParams, type ConfigRestApi, type CssKeyframeCallback, type CssSelectorOptions, type CsvFormat, type DictionaryWithValueFilter, type DictionaryWithoutValueFilter, type DoesExtendTypeguard, type EndingWithTypeGuard, type EndpointGenerator, type EqualTo, type Finder, type FnParam, type FnParams, type GenParam, type GenParams, type GetEachOptions, type GetInference, type GetInferenceProps, type GetOptions, type Joiner, type KeyframeApi, type Mapper, type Rtn, ShapeApiImplementation, type SingletonClosure, type StartingWithTypeGuard, type StripSurroundConfigured, type SurroundWith, type ToKeyValueSort, type TokenContainerClosure, type TokenFunctionClosure, type TokenSetClosure, type TypeOfTypeGuard, type Unbox, type UndefinedArrayIsUnknown, type UnionClosure, type UrlMeta, type YouTubeMeta, addFnToProps, addPropsToFn, and, asApi, asArray, asChars, asDate, asEscapeFunction, asIsoDate, asOptionalParamFunction, asPhoneFormat, asRecord, asString, asStringLiteral, asType, asTypeToken, asVueRef, box, boxDictionaryValues, capitalize, choices, createConverter, createCssKeyframe, createCssSelector, createErrorCondition, createFifoQueue, createFixedLengthArray, createFnWithProps, createFnWithPropsExplicit, createLifoQueue, createMapper, createObjectMap, createTypeToken, cssColor, csv, defineCss, defineObj, defineObject, defineObjectApi, defineTuple, doesExtend, endsWith, ensureLeading, ensureSurround, ensureTrailing, entries, errCondition, filter, find, fnMeta, fromDefineObject, fromKeyValue, get, getDaysBetween, getEach, getPhoneCountryCode, getTailwindModifiers, getToday, getTokenKind, getTomorrow, getTypeSubtype, getUrlBase, getUrlDefaultPort, getUrlDynamics, getUrlPath, getUrlPort, getUrlProtocol, getUrlQueryParams, getUrlSource, getWeekNumber, getYesterday, getYouTubePageType, handleDoneFn, hasCountryCode, hasDefaultValue, hasIndexOf, hasKeys, hasOverlappingKeys, hasProtocol, hasProtocolPrefix, hasUrlPort, hasUrlQueryParameter, hasWhiteSpace, idLiteral, idTypeGuard, identity, ifArray, ifArrayPartial, ifBoolean, ifChar, ifContainer, ifDefined, ifFalse, ifFunction, ifHasKey, ifLength, ifLowercaseChar, ifNotNull, ifNull, ifNumber, ifObject, ifSameType, ifScalar, ifString, ifTrue, ifUndefined, ifUppercaseChar, indexOf, infer, intersect, intersection, ip6GroupExpansion, ip6Prefix, isAccelerationMetric, isAccelerationUom, isAlpha, isAmazonUrl, isAmericanExpress, isApi, isApiSurface, isAppleUrl, isAreaMetric, isAreaUom, isArray, isArrayToken, isAtomicKind, isAtomicToken, isAustralianNewsUrl, isBelgiumNewsUrl, isBestBuyUrl, isBitbucketUrl, isBoolean, isBooleanLike, isBox, isCanadianNewsUrl, isChineseNewsUrl, isCodeCommitUrl, isConstant, isContainer, isContainerToken, isCostCoUrl, isCountryAbbrev, isCountryCode2, isCountryCode3, isCountryName, isCreditCard, isCssAspectRatio, isCsv, isCurrentMetric, isCurrentUom, isCvsUrl, isDanishNewsUrl, isDate, isDefineObject, isDefined, isDellUrl, isDistanceMetric, isDistanceUom, isDomainName, isDoneFn, isDutchNewsUrl, isEbayUrl, isEmail, isEmpty, isEnergyMetric, isEnergyUom, isEqual, isErrorCondition, isEscapeFunction, isEtsyUrl, isFalse, isFalsy, isFnBasedKind, isFnBasedToken, isFnWithParams, isFrenchNewsUrl, isFrequencyMetric, isFrequencyUom, isFunction, isGermanNewsUrl, isGithubIssueUrl, isGithubIssuesListUrl, isGithubOrgUrl, isGithubProjectUrl, isGithubProjectsListUrl, isGithubReleaseTagUrl, isGithubReleasesListUrl, isGithubRepoReleaseTagUrl, isGithubRepoReleasesUrl, isGithubRepoUrl, isGithubUrl, isHexadecimal, isHmUrl, isHomeDepotUrl, isHtmlElement, isIkeaUrl, isIndexable, isIndianNewsUrl, isInlineSvg, isIp4Address, isIp6Address, isIpAddress, isIso3166Alpha2, isIso3166Alpha3, isIso3166CountryCode, isIso3166CountryName, isIsoDate, isIsoDateTime, isIsoExplicitDate, isIsoExplicitTime, isIsoImplicitDate, isIsoImplicitTime, isIsoTime, isIsoYear, isItalianNewsUrl, isJapaneseNewsUrl, isKrogersUrl, isLeapYear, isLength, isLikeRegExp, isLowesUrl, isLuminosityMetric, isLuminosityUom, isLuxonDateTime, isMacysUrl, isMap, isMapToken, isMassMetric, isMassUom, isMetric, isMexicanNewsUrl, isMoment, isNarrowableObject, isNever, isNewsUrl, isNikeUrl, isNorwegianNewsUrl, isNotNull, isNothing, isNull, isNumber, isNumberLike, isNumericArray, isNumericString, isObject, isObjectToken, isOptionalParamFunction, isPhoneNumber, isPowerMetric, isPowerUom, isPressureMetric, isPressureUom, isProtocol, isProtocolPrefix, isReadonlyArray, isRecordToken, isRef, isRegExp, isRepoSource, isRepoUrl, isResistance, isResistanceUom, isRetailUrl, isSameTypeOf, isScalar, isSemanticVersion, isSet, isSetBasedKind, isSetBasedToken, isSetContainer, isSetToken, isShape, isShapeCallback, isSimpleContainerToken, isSimpleContainerTokenTuple, isSimpleScalarToken, isSimpleScalarTokenTuple, isSimpleToken, isSimpleTokenTuple, isSingletonKind, isSingletonToken, isSocialMediaProfileUrl, isSocialMediaUrl, isSouthKoreanNewsUrl, isSpanishNewsUrl, isSpecificConstant, isSpeedMetric, isSpeedUom, isString, isStringArray, isSwissNewsUrl, isSymbol, isTailwindColor, isTailwindColorClass, isTailwindColorName, isTailwindColorTarget, isTailwindColorWithLuminosity, isTailwindColorWithLuminosityAndOpacity, isTailwindModifier, isTargetUrl, isTemperatureMetric, isTemperatureUom, isThenable, isThisMonth, isThisWeek, isThisYear, isTimeMetric, isTimeUom, isToday, isTomorrow, isTrimable, isTrue, isTruthy, isTuple, isTupleToken, isTurkishNewsUrl, isTypeOf, isTypeSubtype, isTypeToken, isTypeTokenKind, isTypeTuple, isUkNewsUrl, isUndefined, isUnset, isUom, isUri, isUrl, isUrlPath, isUrlSource, isUsNewsUrl, isUsPhoneNumber, isUsStateAbbreviation, isUsStateName, isVariable, isVisaMastercard, isVoltageMetric, isVoltageUom, isVolumeMetric, isVolumeUom, isVueRef, isWalgreensUrl, isWalmartUrl, isWayfairUrl, isWholeFoodsUrl, isYesterday, isYouTubeCreatorUrl, isYouTubeFeedHistoryUrl, isYouTubeFeedUrl, isYouTubePlaylistUrl, isYouTubePlaylistsUrl, isYouTubeShareUrl, isYouTubeSubscriptionsUrl, isYouTubeTrendingUrl, isYouTubeUrl, isYouTubeVideoUrl, isYouTubeVideosInPlaylist, isZaraUrl, isZipCode, isZipCode5, isZipPlus4, joinWith, jsonValue, jsonValues, keysOf, kindLiteral, last, list, literal, logicalReturns, lookupCountryAlpha2, lookupCountryAlpha3, lookupCountryCode, lookupCountryName, lowercase, maybePhoneNumber, mergeObjects, mergeScalars, mergeTuples, nameLiteral, narrow, narrowObjectTo, narrowObjectToType, never, objectToApi, objectValues, omit, optional, optionalOrNull, or, orNull, pathJoin, pluralize, removePhoneCountryCode, removeTailwindModifiers, removeUrlProtocol, result, retain, retainAfter, retainAfterInclusive, retainChars, retainUntil, retainUntilInclusive, retainWhile, reverse, rightWhitespace, shape, sharedKeys, shift, simpleContainerToken, simpleContainerTokenToTypeToken, simpleContainerType, simpleScalarToken, simpleScalarTokenToTypeToken, simpleScalarType, simpleToken, simpleType, simpleUnionTokenToTypeToken, slice, split, startsWith, stripAfter, stripBefore, stripChars, stripLeading, stripParenthesis, stripSurround, stripTrailing, stripUntil, stripWhile, surround, takeNumericCharacters, takeProp, toCamelCase, toKebabCase, toKeyValue, toNumber, toNumericArray, toPascalCase, toSnakeCase, toString, toUppercase, trim, trimEnd, trimLeft, trimRight, trimStart, truncate, tuple, twColor, unbox, uncapitalize, union, unionize, unique, uniqueKeys, unset, uppercase, urlMeta, valuesOf, widen, withDefaults, withKeys, withValue, withoutKeys, withoutValue, wrapFn, youtubeEmbed, youtubeMeta };
|
|
15496
|
+
export { type AsClassSelector, type AsList, type BoxValue, type BoxedFnParams, type ConfigRestApi, type CssKeyframeCallback, type CssSelectorOptions, type CsvFormat, type DictionaryWithValueFilter, type DictionaryWithoutValueFilter, type DoesExtendTypeguard, type EndingWithTypeGuard, type EndpointGenerator, type EqualTo, type Finder, type FnParam, type FnParams, type GenParam, type GenParams, type GetEachOptions, type GetInference, type GetInferenceProps, type GetOptions, type Joiner, type KeyframeApi, type Mapper, type Rtn, ShapeApiImplementation, type SingletonClosure, type StartingWithTypeGuard, type StripSurroundConfigured, type SurroundWith, type ToKeyValueSort, type TokenContainerClosure, type TokenFunctionClosure, type TokenSetClosure, type TypeOfTypeGuard, type Unbox, type UndefinedArrayIsUnknown, type UnionClosure, type UrlMeta, type YouTubeMeta, addFnToProps, addPropsToFn, and, asApi, asArray, asChars, asDate, asEscapeFunction, asIsoDate, asOptionalParamFunction, asPhoneFormat, asRecord, asString, asStringLiteral, asType, asTypeToken, asVueRef, box, boxDictionaryValues, capitalize, cardType, choices, createConverter, createCssKeyframe, createCssSelector, createErrorCondition, createFifoQueue, createFixedLengthArray, createFnWithProps, createFnWithPropsExplicit, createLifoQueue, createMapper, createObjectMap, createTypeToken, cssColor, csv, defineCss, defineObj, defineObject, defineObjectApi, defineTuple, doesExtend, endsWith, ensureLeading, ensureSurround, ensureTrailing, entries, errCondition, filter, find, fnMeta, fromDefineObject, fromKeyValue, get, getDaysBetween, getEach, getPhoneCountryCode, getTailwindModifiers, getToday, getTokenKind, getTomorrow, getTypeSubtype, getUrlBase, getUrlDefaultPort, getUrlDynamics, getUrlPath, getUrlPort, getUrlProtocol, getUrlQueryParams, getUrlSource, getWeekNumber, getYesterday, getYouTubePageType, handleDoneFn, hasCountryCode, hasDefaultValue, hasIndexOf, hasKeys, hasOverlappingKeys, hasProtocol, hasProtocolPrefix, hasUrlPort, hasUrlQueryParameter, hasWhiteSpace, idLiteral, idTypeGuard, identity, ifArray, ifArrayPartial, ifBoolean, ifChar, ifContainer, ifDefined, ifFalse, ifFunction, ifHasKey, ifLength, ifLowercaseChar, ifNotNull, ifNull, ifNumber, ifObject, ifSameType, ifScalar, ifString, ifTrue, ifUndefined, ifUppercaseChar, indexOf, infer, intersect, intersection, ip6GroupExpansion, ip6Prefix, isAccelerationMetric, isAccelerationUom, isAlpha, isAmazonUrl, isAmericanExpress, isApi, isApiSurface, isAppleUrl, isAreaMetric, isAreaUom, isArray, isArrayToken, isAtomicKind, isAtomicToken, isAustralianNewsUrl, isBelgiumNewsUrl, isBestBuyUrl, isBitbucketUrl, isBoolean, isBooleanLike, isBox, isCanadianNewsUrl, isChineseNewsUrl, isCodeCommitUrl, isConstant, isContainer, isContainerToken, isCostCoUrl, isCountryAbbrev, isCountryCode2, isCountryCode3, isCountryName, isCreditCard, isCssAspectRatio, isCsv, isCurrentMetric, isCurrentUom, isCvsUrl, isDanishNewsUrl, isDate, isDefineObject, isDefined, isDellUrl, isDistanceMetric, isDistanceUom, isDomainName, isDoneFn, isDutchNewsUrl, isEbayUrl, isEmail, isEmpty, isEnergyMetric, isEnergyUom, isEqual, isErrorCondition, isEscapeFunction, isEtsyUrl, isFalse, isFalsy, isFnBasedKind, isFnBasedToken, isFnWithParams, isFrenchNewsUrl, isFrequencyMetric, isFrequencyUom, isFunction, isGermanNewsUrl, isGithubIssueUrl, isGithubIssuesListUrl, isGithubOrgUrl, isGithubProjectUrl, isGithubProjectsListUrl, isGithubReleaseTagUrl, isGithubReleasesListUrl, isGithubRepoReleaseTagUrl, isGithubRepoReleasesUrl, isGithubRepoUrl, isGithubUrl, isHexadecimal, isHmUrl, isHomeDepotUrl, isHtmlElement, isIkeaUrl, isIndexable, isIndianNewsUrl, isInlineSvg, isIp4Address, isIp6Address, isIpAddress, isIso3166Alpha2, isIso3166Alpha3, isIso3166CountryCode, isIso3166CountryName, isIsoDate, isIsoDateTime, isIsoExplicitDate, isIsoExplicitTime, isIsoImplicitDate, isIsoImplicitTime, isIsoTime, isIsoYear, isItalianNewsUrl, isJapaneseNewsUrl, isKrogersUrl, isLeapYear, isLength, isLikeRegExp, isLowesUrl, isLuminosityMetric, isLuminosityUom, isLuxonDateTime, isMacysUrl, isMap, isMapToken, isMassMetric, isMassUom, isMastercard, isMetric, isMexicanNewsUrl, isMoment, isNarrowableObject, isNever, isNewsUrl, isNikeUrl, isNorwegianNewsUrl, isNotNull, isNothing, isNull, isNumber, isNumberLike, isNumericArray, isNumericString, isObject, isObjectToken, isOptionalParamFunction, isPhoneNumber, isPowerMetric, isPowerUom, isPressureMetric, isPressureUom, isProtocol, isProtocolPrefix, isReadonlyArray, isRecordToken, isRef, isRegExp, isRepoSource, isRepoUrl, isResistance, isResistanceUom, isRetailUrl, isSameTypeOf, isScalar, isSemanticVersion, isSet, isSetBasedKind, isSetBasedToken, isSetContainer, isSetToken, isShape, isShapeCallback, isSimpleContainerToken, isSimpleContainerTokenTuple, isSimpleScalarToken, isSimpleScalarTokenTuple, isSimpleToken, isSimpleTokenTuple, isSingletonKind, isSingletonToken, isSocialMediaProfileUrl, isSocialMediaUrl, isSouthKoreanNewsUrl, isSpanishNewsUrl, isSpecificConstant, isSpeedMetric, isSpeedUom, isString, isStringArray, isSwissNewsUrl, isSymbol, isTailwindColor, isTailwindColorClass, isTailwindColorName, isTailwindColorTarget, isTailwindColorWithLuminosity, isTailwindColorWithLuminosityAndOpacity, isTailwindModifier, isTargetUrl, isTemperatureMetric, isTemperatureUom, isThenable, isThisMonth, isThisWeek, isThisYear, isTimeMetric, isTimeUom, isToday, isTomorrow, isTrimable, isTrue, isTruthy, isTuple, isTupleToken, isTurkishNewsUrl, isTypeOf, isTypeSubtype, isTypeToken, isTypeTokenKind, isTypeTuple, isUkNewsUrl, isUndefined, isUnset, isUom, isUri, isUrl, isUrlPath, isUrlSource, isUsNewsUrl, isUsPhoneNumber, isUsStateAbbreviation, isUsStateName, isVariable, isVisa, isVisaMastercard, isVoltageMetric, isVoltageUom, isVolumeMetric, isVolumeUom, isVueRef, isWalgreensUrl, isWalmartUrl, isWayfairUrl, isWholeFoodsUrl, isYesterday, isYouTubeCreatorUrl, isYouTubeFeedHistoryUrl, isYouTubeFeedUrl, isYouTubePlaylistUrl, isYouTubePlaylistsUrl, isYouTubeShareUrl, isYouTubeSubscriptionsUrl, isYouTubeTrendingUrl, isYouTubeUrl, isYouTubeVideoUrl, isYouTubeVideosInPlaylist, isZaraUrl, isZipCode, isZipCode5, isZipPlus4, joinWith, jsonValue, jsonValues, keysOf, kindLiteral, last, list, literal, logicalReturns, lookupCountryAlpha2, lookupCountryAlpha3, lookupCountryCode, lookupCountryName, lowercase, maybePhoneNumber, mergeObjects, mergeScalars, mergeTuples, nameLiteral, narrow, narrowObjectTo, narrowObjectToType, never, objectToApi, objectValues, omit, optional, optionalOrNull, or, orNull, pathJoin, pluralize, removePhoneCountryCode, removeTailwindModifiers, removeUrlProtocol, result, retain, retainAfter, retainAfterInclusive, retainChars, retainUntil, retainUntilInclusive, retainWhile, reverse, rightWhitespace, shape, sharedKeys, shift, simpleContainerToken, simpleContainerTokenToTypeToken, simpleContainerType, simpleScalarToken, simpleScalarTokenToTypeToken, simpleScalarType, simpleToken, simpleType, simpleUnionTokenToTypeToken, slice, split, startsWith, stripAfter, stripBefore, stripChars, stripLeading, stripParenthesis, stripSurround, stripTrailing, stripUntil, stripWhile, surround, takeNumericCharacters, takeProp, toCamelCase, toKebabCase, toKeyValue, toNumber, toNumericArray, toPascalCase, toSnakeCase, toString, toUppercase, trim, trimEnd, trimLeft, trimRight, trimStart, truncate, tuple, twColor, unbox, uncapitalize, union, unionize, unique, uniqueKeys, unset, uppercase, urlMeta, valuesOf, widen, withDefaults, withKeys, withValue, withoutKeys, withoutValue, wrapFn, youtubeEmbed, youtubeMeta };
|
|
@@ -4204,13 +4204,23 @@ function isYesterday(test) {
|
|
|
4204
4204
|
}
|
|
4205
4205
|
|
|
4206
4206
|
// src/type-guards/finance/CreditCards.ts
|
|
4207
|
-
function
|
|
4208
|
-
if (isString(val)) {
|
|
4207
|
+
function isVisa(val) {
|
|
4208
|
+
if (isString(val) && val.startsWith("4")) {
|
|
4209
4209
|
const parts = val.split(" ");
|
|
4210
4210
|
return parts.length === 4 && parts.every((i) => isNumberLike(i) && i.length === 4);
|
|
4211
4211
|
}
|
|
4212
4212
|
return false;
|
|
4213
4213
|
}
|
|
4214
|
+
function isMastercard(val) {
|
|
4215
|
+
if (isString(val) && val.startsWith("4")) {
|
|
4216
|
+
const parts = val.split(" ");
|
|
4217
|
+
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));
|
|
4218
|
+
}
|
|
4219
|
+
return false;
|
|
4220
|
+
}
|
|
4221
|
+
function isVisaMastercard(val) {
|
|
4222
|
+
return isVisa(val) || isMastercard(val);
|
|
4223
|
+
}
|
|
4214
4224
|
function isAmericanExpress(val) {
|
|
4215
4225
|
if (isString(val)) {
|
|
4216
4226
|
const parts = val.split(" ");
|
|
@@ -4223,6 +4233,57 @@ function isAmericanExpress(val) {
|
|
|
4223
4233
|
function isCreditCard(val) {
|
|
4224
4234
|
return isVisaMastercard(val) || isAmericanExpress(val);
|
|
4225
4235
|
}
|
|
4236
|
+
function cardType(cardNumber) {
|
|
4237
|
+
const cleanedNumber = String(cardNumber).replace(/\D/g, "");
|
|
4238
|
+
const length = cleanedNumber.length;
|
|
4239
|
+
if (!isValidLength(length)) {
|
|
4240
|
+
return "invalid";
|
|
4241
|
+
}
|
|
4242
|
+
if (!luhnCheck(cleanedNumber)) {
|
|
4243
|
+
return "invalid";
|
|
4244
|
+
}
|
|
4245
|
+
const cardTypes = [
|
|
4246
|
+
{ name: "Visa", lengths: [16], prefixes: [/^4/] },
|
|
4247
|
+
{ 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)/] },
|
|
4248
|
+
{ name: "American Express", lengths: [15], prefixes: [/^3[47]/] },
|
|
4249
|
+
{ 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)/] },
|
|
4250
|
+
{ name: "JCB", lengths: [16], prefixes: [/^(35|2131|1800)/] },
|
|
4251
|
+
{ name: "Diners Club", lengths: [14, 16], prefixes: [/^(30[0-5]|36|38)/] },
|
|
4252
|
+
{ name: "China UnionPay", lengths: [16, 17, 18, 19], prefixes: [/^(62|88)/] },
|
|
4253
|
+
{ name: "Maestro", lengths: [12, 13, 14, 15, 16, 17, 18, 19], prefixes: [/^(5018|5020|5038|6304)/] },
|
|
4254
|
+
{ name: "Solo", lengths: [16, 18, 19], prefixes: [/^(6334|6767)/] }
|
|
4255
|
+
];
|
|
4256
|
+
for (const type of cardTypes) {
|
|
4257
|
+
if (type.lengths.includes(length)) {
|
|
4258
|
+
for (const prefix of type.prefixes) {
|
|
4259
|
+
if (prefix.test(cleanedNumber)) {
|
|
4260
|
+
return type.name;
|
|
4261
|
+
}
|
|
4262
|
+
}
|
|
4263
|
+
}
|
|
4264
|
+
}
|
|
4265
|
+
return "invalid";
|
|
4266
|
+
}
|
|
4267
|
+
function isValidLength(length) {
|
|
4268
|
+
const validLengths = [13, 14, 15, 16, 17, 18, 19];
|
|
4269
|
+
return validLengths.includes(length);
|
|
4270
|
+
}
|
|
4271
|
+
function luhnCheck(num) {
|
|
4272
|
+
let sum = 0;
|
|
4273
|
+
let double = false;
|
|
4274
|
+
for (let i = num.length - 1; i >= 0; i--) {
|
|
4275
|
+
let n = Number.parseInt(num.charAt(i), 10);
|
|
4276
|
+
if (double) {
|
|
4277
|
+
n *= 2;
|
|
4278
|
+
if (n > 9) {
|
|
4279
|
+
n -= 9;
|
|
4280
|
+
}
|
|
4281
|
+
}
|
|
4282
|
+
sum += n;
|
|
4283
|
+
double = !double;
|
|
4284
|
+
}
|
|
4285
|
+
return sum % 10 === 0;
|
|
4286
|
+
}
|
|
4226
4287
|
|
|
4227
4288
|
// src/type-guards/isString.ts
|
|
4228
4289
|
function isString(value) {
|
|
@@ -5602,6 +5663,7 @@ export {
|
|
|
5602
5663
|
box,
|
|
5603
5664
|
boxDictionaryValues,
|
|
5604
5665
|
capitalize,
|
|
5666
|
+
cardType,
|
|
5605
5667
|
choices,
|
|
5606
5668
|
createConverter,
|
|
5607
5669
|
createCssKeyframe,
|
|
@@ -5811,6 +5873,7 @@ export {
|
|
|
5811
5873
|
isMapToken,
|
|
5812
5874
|
isMassMetric,
|
|
5813
5875
|
isMassUom,
|
|
5876
|
+
isMastercard,
|
|
5814
5877
|
isMetric,
|
|
5815
5878
|
isMexicanNewsUrl,
|
|
5816
5879
|
isMoment,
|
|
@@ -5916,6 +5979,7 @@ export {
|
|
|
5916
5979
|
isUsStateAbbreviation,
|
|
5917
5980
|
isUsStateName,
|
|
5918
5981
|
isVariable,
|
|
5982
|
+
isVisa,
|
|
5919
5983
|
isVisaMastercard,
|
|
5920
5984
|
isVoltageMetric,
|
|
5921
5985
|
isVoltageUom,
|