UNPKG

react-svg-credit-card-payment-icons

Version:

React components library with 6 styles, 108 icons, TypeScript support, and a variety of types and formats for easy integration into React applications.

117 lines (115 loc) 3.51 kB
import { flat_exports } from "../chunk-2NHWBGJO.mjs"; import { Generic_default, flat_rounded_exports } from "../chunk-CIYQQF3S.mjs"; import { logo_exports } from "../chunk-RMU6YMOK.mjs"; import { logo_border_exports } from "../chunk-7RP4D37H.mjs"; import { mono_exports } from "../chunk-KIX35SQA.mjs"; import { mono_outline_exports } from "../chunk-MH746MCW.mjs"; import { CARD_METADATA, detectCardType, formatCardNumber, getCardLengthRange, getCardType, getCardsByCountry, isCardNumberPotentiallyValid, maskCardNumber, sanitizeCardNumber, validateCardForType, validateCardNumber } from "../chunk-DEJVU3HJ.mjs"; import "../chunk-7P6ASYW6.mjs"; // src/index.native.tsx import React from "react"; var categoryMappings = { flat: flat_exports, flatRounded: flat_rounded_exports, logo: logo_exports, logoBorder: logo_border_exports, mono: mono_exports, monoOutline: mono_outline_exports }; var defaultType = "generic"; var defaultCategory = "flat"; var aspectRatio = 780 / 500; var defaultWidth = 40; function resolveAlias(input) { for (const card of CARD_METADATA) { if (card.type === input) { return { type: card.type }; } if (card.aliases.some((alias) => alias === input)) { return { type: card.type }; } if (card.variants) { for (const [variantAlias, variantDef] of Object.entries(card.variants)) { if (variantAlias === input) { return { type: card.type, variant: variantDef.slug }; } } } } return { type: input }; } function PaymentIcon(props) { const category = props.format || defaultCategory; if (!categoryMappings[category]) throw new Error( `Invalid category: ${category} please use one of ${Object.keys(categoryMappings).join(", ")}` ); const inputType = props.type || defaultType; const resolved = resolveAlias(inputType); const sanitizedType = resolved.type.replace(/[-_]/g, ""); const normalizedType = sanitizedType.charAt(0).toUpperCase() + sanitizedType.slice(1); const categoryComponents = categoryMappings[category]; let Component; if (resolved.variant && !props.variant) { const sanitizedInput = inputType.replace(/[-_]/g, ""); const normalizedInput = sanitizedInput.charAt(0).toUpperCase() + sanitizedInput.slice(1); Component = categoryComponents[normalizedInput]; } else if (props.variant) { const sanitizedVariant = props.variant.replace(/[-_]/g, ""); const normalizedVariant = sanitizedVariant.charAt(0).toUpperCase() + sanitizedVariant.slice(1); const compositeKey = `${normalizedType}${normalizedVariant}`; Component = categoryComponents[compositeKey] ?? categoryComponents[normalizedVariant]; } else { Component = categoryComponents[normalizedType]; } if (!Component) { Component = Generic_default; } const width = props.width ?? (props.height ? props.height * aspectRatio : defaultWidth); const height = props.height ?? width / aspectRatio; return /* @__PURE__ */ React.createElement(Component, { ...props, width, height, viewBox: "0 0 780 500" }); } export { PaymentIcon, detectCardType, flat_exports as flat, flat_rounded_exports as flatRounded, formatCardNumber, getCardLengthRange, getCardType, getCardsByCountry, isCardNumberPotentiallyValid, logo_exports as logo, logo_border_exports as logoBorder, maskCardNumber, mono_exports as mono, mono_outline_exports as monoOutline, sanitizeCardNumber, validateCardForType, validateCardNumber };