{"_id":"@juspay/cards-validator","_rev":"3-ecc211bacbd32b6bb997b3718364224e","name":"@juspay/cards-validator","dist-tags":{"latest":"0.1.2"},"versions":{"0.1.0":{"name":"@juspay/cards-validator","version":"0.1.0","keywords":["credit-card","card-validation","payment","typescript","validator","cvv","luhn"],"author":{"name":"Juspay Technologies Pvt Ltd"},"license":"MIT","_id":"@juspay/cards-validator@0.1.0","maintainers":[{"name":"balaganesh_juspay","email":"balaganesh@juspay.in"},{"name":"itadmin","email":"itadmin@juspay.in"},{"name":"murdore","email":"sachin.sharma@juspay.in"},{"name":"georgejames","email":"george.james@juspay.in"},{"name":"sahil_sinha","email":"sahil.sinha@juspay.in"},{"name":"dhineshrks","email":"dhinesh.radhakrishnan@juspay.in"},{"name":"swaroopvarma2359","email":"pinnamaraju.swaroop@juspay.in"}],"homepage":"https://github.com/juspay/cards-validator#readme","bugs":{"url":"https://github.com/juspay/cards-validator/issues"},"dist":{"shasum":"214d1a136241c9f64e3e9e42cc50b85e2cbdd1cf","tarball":"https://registry.npmjs.org/@juspay/cards-validator/-/cards-validator-0.1.0.tgz","fileCount":9,"integrity":"sha512-QN/fIkxlhyD38O/3Rl149aWkzRUyRF3gJ0nf1bHSrPk+hQiF9A+OLUBZjeekwab3+r8ZM4jJeJzaZvc3EGufzg==","signatures":[{"sig":"MEUCIC6DozFM8YiYkSMft6EWqRXh1zKCoy8WqBbgfaUMkoxuAiEAnkznSJe/OGGyP8s5zRjjRb1AMEzugE2FKusS7ITxEOM=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":17025},"main":"dist/index.js","type":"module","types":"./dist/index.d.ts","gitHead":"a9585697081bad95844f35669e56f56f5f2bf4bf","scripts":{"dev":"rollup --config rollup.config.js --watch","lint":"eslint src/**/*.ts","test":"vitest run","build":"rollup --config rollup.config.js","clean":"rm -rf dist","format":"prettier --write src/**/*.ts","prepare":"husky","test:watch":"vitest"},"_npmUser":{"name":"sahil_sinha","email":"sahil.sinha@juspay.in"},"repository":{"url":"git+https://github.com/juspay/cards-validator.git","type":"git"},"_npmVersion":"10.9.4","description":"A JS/TS lib for validating credit and debit card numbers, determining card types, and providing card-specific information like CVV length","directories":{},"_nodeVersion":"22.21.1","_hasShrinkwrap":false,"devDependencies":{"husky":"^9.1.7","tslib":"^2.8.1","eslint":"^9.39.2","rollup":"^4.55.1","vitest":"^2.1.8","globals":"^17.0.0","prettier":"^3.7.4","@eslint/js":"^9.39.2","@vitest/ui":"^2.1.8","typescript":"^5.9.3","@types/node":"^25.0.3","@rollup/plugin-terser":"^0.4.4","eslint-config-prettier":"^10.1.8","@rollup/plugin-typescript":"^12.3.0","@typescript-eslint/parser":"^8.52.0","eslint-plugin-unused-imports":"^4.3.0","@typescript-eslint/eslint-plugin":"^8.52.0"},"_npmOperationalInternal":{"tmp":"tmp/cards-validator_0.1.0_1767782847624_0.12277047200235058","host":"s3://npm-registry-packages-npm-production"}},"0.1.1":{"name":"@juspay/cards-validator","version":"0.1.1","keywords":["credit-card","card-validation","payment","typescript","validator","cvv","luhn"],"author":{"name":"Juspay Technologies Pvt Ltd"},"license":"MIT","_id":"@juspay/cards-validator@0.1.1","maintainers":[{"name":"balaganesh_juspay","email":"balaganesh@juspay.in"},{"name":"itadmin","email":"itadmin@juspay.in"},{"name":"murdore","email":"sachin.sharma@juspay.in"},{"name":"georgejames","email":"george.james@juspay.in"},{"name":"sahil_sinha","email":"sahil.sinha@juspay.in"},{"name":"dhineshrks","email":"dhinesh.radhakrishnan@juspay.in"},{"name":"swaroopvarma2359","email":"pinnamaraju.swaroop@juspay.in"}],"homepage":"https://github.com/juspay/cards-validator#readme","bugs":{"url":"https://github.com/juspay/cards-validator/issues"},"dist":{"shasum":"fd4415706ee0c5dd88c2dac9182fe8d83da01a36","tarball":"https://registry.npmjs.org/@juspay/cards-validator/-/cards-validator-0.1.1.tgz","fileCount":6,"integrity":"sha512-lrBVAv+ne/bL3rIC1IAnursm0x3f6kvhUSOeaF5ez4BIaRRd8mB5Vgy2aGeL0f9HaDEDm5VAGCb6r2V6ak5gDw==","signatures":[{"sig":"MEYCIQCn823eqWp4L/ZKbjdzz/jHNe/oQGfo3qqAFNTdUyhI3wIhALG70NthE8N19WMqQJLznY4uRn93uB4kbrOezPV1UyGM","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":16274},"main":"dist/index.js","type":"module","gitHead":"23ea2e300ff92a187c61e3893bc9c7775f08a832","scripts":{"dev":"rollup --config rollup.config.js --watch","lint":"eslint src/**/*.ts","test":"vitest run","build":"rollup --config rollup.config.js","clean":"rm -rf dist","format":"prettier --write src/**/*.ts","prepare":"husky","test:watch":"vitest"},"_npmUser":{"name":"sahil_sinha","email":"sahil.sinha@juspay.in"},"repository":{"url":"git+https://github.com/juspay/cards-validator.git","type":"git"},"_npmVersion":"10.8.2","description":"A JS/TS lib for validating credit and debit card numbers, determining card types, and providing card-specific information like CVV length","directories":{},"_nodeVersion":"20.19.6","_hasShrinkwrap":false,"devDependencies":{"husky":"^9.1.7","tslib":"^2.8.1","eslint":"^9.39.2","rollup":"^4.55.1","vitest":"^2.1.8","globals":"^17.0.0","prettier":"^3.7.4","@eslint/js":"^9.39.2","@vitest/ui":"^2.1.8","typescript":"^5.9.3","@types/node":"^25.0.3","@rollup/plugin-terser":"^0.4.4","eslint-config-prettier":"^10.1.8","@rollup/plugin-typescript":"^12.3.0","@typescript-eslint/parser":"^8.52.0","eslint-plugin-unused-imports":"^4.3.0","@typescript-eslint/eslint-plugin":"^8.52.0"},"_npmOperationalInternal":{"tmp":"tmp/cards-validator_0.1.1_1767964496364_0.714043755588152","host":"s3://npm-registry-packages-npm-production"}},"0.1.2":{"name":"@juspay/cards-validator","version":"0.1.2","description":"A JS/TS lib for validating credit and debit card numbers, determining card types, and providing card-specific information like CVV length","main":"dist/index.js","types":"dist/index.d.ts","type":"module","scripts":{"build":"rollup --config rollup.config.js","dev":"rollup --config rollup.config.js --watch","clean":"rm -rf dist","test":"vitest run","test:watch":"vitest","lint":"eslint src/**/*.ts","format":"prettier --write src/**/*.ts","prepare":"husky"},"repository":{"type":"git","url":"git+https://github.com/juspay/cards-validator.git"},"homepage":"https://github.com/juspay/cards-validator#readme","keywords":["credit-card","card-validation","payment","typescript","validator","cvv","luhn"],"author":{"name":"Juspay Technologies Pvt Ltd"},"license":"MIT","devDependencies":{"@eslint/js":"^9.39.2","@rollup/plugin-terser":"^0.4.4","@rollup/plugin-typescript":"^12.3.0","@types/node":"^25.0.3","@typescript-eslint/eslint-plugin":"^8.52.0","@typescript-eslint/parser":"^8.52.0","@vitest/ui":"^2.1.8","eslint":"^9.39.2","eslint-config-prettier":"^10.1.8","eslint-plugin-unused-imports":"^4.3.0","globals":"^17.0.0","husky":"^9.1.7","prettier":"^3.7.4","rollup":"^4.55.1","tslib":"^2.8.1","typescript":"^5.9.3","vitest":"^2.1.8"},"_id":"@juspay/cards-validator@0.1.2","gitHead":"9a8047585885c92a8412bf4fe7df6345804ef168","bugs":{"url":"https://github.com/juspay/cards-validator/issues"},"_nodeVersion":"20.19.6","_npmVersion":"10.8.2","dist":{"integrity":"sha512-zV0KGgEOf5wqj9CWAkbDldhVOmPgy3Vy3+vO4OlWzxNmitim7LWN7PZe5j0B9Fa0/Ei9VS97GJAXodg3Vd+djA==","shasum":"511c46556f49ac0fd996a6c22b7c478f550bc471","tarball":"https://registry.npmjs.org/@juspay/cards-validator/-/cards-validator-0.1.2.tgz","fileCount":6,"unpackedSize":16304,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIDYknQgDqqFKVWB9FOYd5Yi9gwZeZ3nK0MLeStKUFhe/AiEA8z+ip2vkm1GKyUMv2p5RQksMHRQBP+IgvHDH+mfl4G8="}]},"_npmUser":{"name":"sahil_sinha","email":"sahil.sinha@juspay.in"},"directories":{},"maintainers":[{"name":"balaganesh_juspay","email":"balaganesh@juspay.in"},{"name":"itadmin","email":"itadmin@juspay.in"},{"name":"murdore","email":"sachin.sharma@juspay.in"},{"name":"georgejames","email":"george.james@juspay.in"},{"name":"sahil_sinha","email":"sahil.sinha@juspay.in"},{"name":"dhineshrks","email":"dhinesh.radhakrishnan@juspay.in"},{"name":"swaroopvarma2359","email":"pinnamaraju.swaroop@juspay.in"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/cards-validator_0.1.2_1767969954688_0.36377406301590565"},"_hasShrinkwrap":false}},"time":{"created":"2026-01-07T10:47:27.551Z","modified":"2026-01-09T14:45:55.182Z","0.1.0":"2026-01-07T10:47:27.778Z","0.1.1":"2026-01-09T13:14:56.533Z","0.1.2":"2026-01-09T14:45:54.830Z"},"bugs":{"url":"https://github.com/juspay/cards-validator/issues"},"author":{"name":"Juspay Technologies Pvt Ltd"},"license":"MIT","homepage":"https://github.com/juspay/cards-validator#readme","keywords":["credit-card","card-validation","payment","typescript","validator","cvv","luhn"],"repository":{"type":"git","url":"git+https://github.com/juspay/cards-validator.git"},"description":"A JS/TS lib for validating credit and debit card numbers, determining card types, and providing card-specific information like CVV length","maintainers":[{"name":"balaganesh_juspay","email":"balaganesh@juspay.in"},{"name":"itadmin","email":"itadmin@juspay.in"},{"name":"murdore","email":"sachin.sharma@juspay.in"},{"name":"georgejames","email":"george.james@juspay.in"},{"name":"sahil_sinha","email":"sahil.sinha@juspay.in"},{"name":"dhineshrks","email":"dhinesh.radhakrishnan@juspay.in"},{"name":"swaroopvarma2359","email":"pinnamaraju.swaroop@juspay.in"}],"readme":"<div align=\"center\">\n\n# 💳 Cards Validator\n\n### A comprehensive JS/TS library for validating credit and debit card numbers\n\n[![npm version](https://img.shields.io/npm/v/@juspay/cards-validator.svg)](https://www.npmjs.com/package/@juspay/cards-validator)\n[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)\n[![TypeScript](https://img.shields.io/badge/TypeScript-Ready-blue.svg)](https://www.typescriptlang.org/)\n[![Bundle Size](https://img.shields.io/bundlephobia/minzip/@juspay/cards-validator)](https://bundlephobia.com/package/@juspay/cards-validator)\n\n</div>\n\n---\n\n## ✨ Features\n\n<table>\n<tr>\n<td>\n\n🎯 **Card Type Detection**  \nAutomatically detects 12+ major card types including Visa, MasterCard, American Express, Discover, JCB, Maestro, RuPay, UnionPay, and more\n\n</td>\n<td>\n\n✅ **Luhn Algorithm Validation**  \nImplements the industry-standard Luhn algorithm for card number validation\n\n</td>\n</tr>\n<tr>\n<td>\n\n📏 **Length Validation**  \nValidates card number length based on card type specifications\n\n</td>\n<td>\n\n🔢 **CVV Length Information**  \nProvides valid CVV lengths for each detected card type\n\n</td>\n</tr>\n<tr>\n<td>\n\n🎨 **Range-based Detection**  \nUses both regex patterns and BIN ranges for accurate card type identification\n\n</td>\n<td>\n\n📘 **TypeScript Support**  \nFully typed with comprehensive type definitions\n\n</td>\n</tr>\n<tr>\n<td colspan=\"2\" align=\"center\">\n\n⚡ **Zero Dependencies**  \nLightweight library with no external dependencies\n\n</td>\n</tr>\n</table>\n\n## 💳 Supported Card Types\n\n<details open>\n<summary><b>Click to view all supported card types</b></summary>\n\n| 🏦 Card Type | 🔍 Pattern/Range | 📏 Valid Lengths | 🔢 CVV Length |\n|--------------|------------------|------------------|---------------|\n| 🔵 Visa | `^4` | 16 | 3 |\n| 🔴 MasterCard | BIN ranges 222100-272099, 510000-559999 | 16 | 3 |\n| 🔵 American Express | `^3[47]` | 15 | 4 |\n| 🟠 Discover | `^(6011\\|622...)` | 16 | 3 |\n| 🟢 JCB | `^35(2[89]\\|[3-8][0-9])` | 16 | 3 |\n| 🔴 Maestro | `^(5018\\|5081\\|...)` | 12-19 | 0, 3 |\n| 🟣 RuPay | BIN ranges | 16 | 3 |\n| 🔵 UnionPay | `^6[0289]\\|9[0245689]...` | 16-19 | 3 |\n| ⚪ Diners Club | `^30[0-5]`, `^3([689]\\|09)` | 14 | 3 |\n| 🟢 Laser | `^(6304\\|670[69]\\|6771)` | 16-19 | 3, 4 |\n| 🔵 Visa Electron | `^(4026\\|417500\\|...)` | 16 | 3 |\n| 🟠 Sodexo | `^(637513)` | 16 | 3 |\n\n</details>\n\n---\n\n## 📦 Installation\n\n```bash\nnpm install @juspay/cards-validator\n```\n\n**Alternative package managers:**\n\n```bash\n# Using Yarn\nyarn add @juspay/cards-validator\n\n# Using pnpm\npnpm add @juspay/cards-validator\n```\n\n---\n\n## 🚀 Usage\n\n### 🎯 Basic Usage\n\n```typescript\nimport CardValidator from '@juspay/cards-validator';\n\n// Create a new validator instance\nconst validator = new CardValidator('4111111111111111');\n\n// Get card validation details\nconst result = validator.getCardDetails();\n\nconsole.log(result);\n// Output:\n// {\n//   card_type: 'visa',\n//   valid: true,\n//   luhn_valid: true,\n//   length_valid: true,\n//   cvv_length: [3],\n//   supported_lengths: [16]\n// }\n```\n\n### 🔧 Advanced Usage\n\n```typescript\nimport CardValidator, { CardDetails } from '@juspay/cards-validator';\n\n// Validate different card types\nconst cards = [\n  '4111111111111111',    // Visa\n  '5555555555554444',    // MasterCard\n  '378282246310005',     // American Express\n  '6011111111111117',    // Discover\n];\n\ncards.forEach(cardNumber => {\n  const validator = new CardValidator(cardNumber);\n  const result: CardDetails = validator.getCardDetails();\n\n  console.log(`Card: ${cardNumber}`);\n  console.log(`Type: ${result.card_type}`);\n  console.log(`Valid: ${result.valid}`);\n  console.log(`CVV Length: ${result.cvv_length.join(', ')}`);\n  console.log('---');\n});\n```\n\n### 🔄 Handling Spaces and Dashes\n\nThe library automatically normalizes card numbers by removing spaces and dashes:\n\n```typescript\nconst validator1 = new CardValidator('4111 1111 1111 1111');\nconst validator2 = new CardValidator('4111-1111-1111-1111');\nconst validator3 = new CardValidator('4111111111111111');\n\n// All three will produce the same result\nconsole.log(validator1.getCardDetails().valid); // true\nconsole.log(validator2.getCardDetails().valid); // true\nconsole.log(validator3.getCardDetails().valid); // true\n```\n\n---\n\n## 📚 API Reference\n\n### 🏗️ CardValidator Class\n\n#### Constructor\n\n```typescript\nnew CardValidator(cardNumber: string)\n```\n\n- `cardNumber`: The credit card number to validate (string)\n\n#### Methods\n\n##### 📋 `getCardDetails(): CardDetails`\n\nReturns a comprehensive validation result object.\n\n---\n\n### 📝 Types\n\n#### 📊 `CardDetails`\n\n```typescript\ninterface CardDetails {\n  card_type: string;           // Detected card type (e.g., 'visa', 'mastercard', 'amex', 'unknown')\n  valid: boolean;              // Overall validity (luhn_valid && length_valid)\n  luhn_valid: boolean;         // Whether card passes Luhn algorithm check\n  length_valid: boolean;       // Whether card length is valid for detected type\n  cvv_length: number[];        // Valid CVV lengths for this card type, e.g., [3] or [3, 4]\n  supported_lengths: number[]; // Valid card number lengths, e.g., [16] or [12,13,14,15,16,17,18,19]\n}\n```\n\n#### 💳 `CardType`\n\n```typescript\ninterface CardType {\n  name: string;\n  valid_length: number[];\n  cvv_length: number[];\n  pattern?: RegExp;      // For pattern-based detection\n  range?: number[][];    // For BIN range-based detection\n  gaps?: number[];       // Optional: for formatting (e.g., Sodexo)\n}\n```\n\n---\n\n## 💡 Examples\n\n### 🎨 Validate and Format Card Information\n\n```typescript\nimport CardValidator from '@juspay/cards-validator';\n\nfunction formatCardInfo(cardNumber: string) {\n  const validator = new CardValidator(cardNumber);\n  const result = validator.getCardDetails();\n\n  if (result.valid) {\n    return {\n      isValid: true,\n      cardType: result.card_type.replace('_', ' ').toUpperCase(),\n      cvvLength: result.cvv_length,\n      message: `Valid ${result.card_type} card`\n    };\n  } else {\n    return {\n      isValid: false,\n      cardType: result.card_type,\n      issues: [\n        !result.luhn_valid && 'Invalid checksum',\n        !result.length_valid && 'Invalid length'\n      ].filter(Boolean),\n      message: 'Invalid card number'\n    };\n  }\n}\n\n// Examples\nconsole.log(formatCardInfo('4111111111111111'));\n// { isValid: true, cardType: 'VISA', cvvLength: [3], message: 'Valid visa card' }\n\nconsole.log(formatCardInfo('4111111111111112'));\n// { isValid: false, cardType: 'visa', issues: ['Invalid checksum'], message: 'Invalid card number' }\n```\n\n---\n\n## 🛠️ Development\n\n### ⚙️ Prerequisites\n\n- Node.js (version 14 or higher)\n- npm, yarn, or pnpm\n\n### 🔧 Setup\n\n```bash\n# Clone the repository\ngit clone https://github.com/juspay/cards-validator.git\ncd cards-validator\n\n# Install dependencies\nnpm install\n\n# Build the project\nnpm run build\n\n# Run tests\nnpm test\n\n# Run development mode with watch\nnpm run dev\n```\n\n### 📜 Scripts\n\n| Script | Description |\n|--------|-------------|\n| `npm run build` | 🔨 Compile TypeScript to JavaScript |\n| `npm run dev` | 👀 Watch mode for development |\n| `npm test` | 🧪 Run test suite |\n| `npm run clean` | 🧹 Remove build artifacts |\n| `npm run lint` | 🔍 Run ESLint |\n| `npm run format` | ✨ Format code with Prettier |\n\n---\n\n## 🧪 Testing\n\nThe library includes comprehensive tests covering:\n\n✅ Card type detection for all supported card types  \n✅ Luhn algorithm validation  \n✅ Length validation  \n✅ Edge cases and error handling  \n✅ Input normalization (spaces, dashes)\n\nRun tests with:\n\n```bash\nnpm test\n```\n\n---\n\n## 🤝 Contributing\n\n1. Fork the repository\n2. Create your feature branch (`git checkout -b feature/amazing-feature`)\n3. Commit your changes (`git commit -m 'Add some amazing feature'`)\n4. Push to the branch (`git push origin feature/amazing-feature`)\n5. Open a Pull Request\n\n---\n\n## 📄 License\n\nThis project is licensed under the **MIT License** - see the [LICENSE](LICENSE) file for details.\n\n---\n\n## 📋 Changelog\n\n### v0.1.0\n- ✨ Initial release\n- 💳 Support for 12+ major card types\n- ✅ Luhn algorithm validation\n- 📏 Length validation\n- 📘 TypeScript support\n- 🧪 Comprehensive test suite\n\n---\n\n## 🙏 Acknowledgments\n\n- 🔐 [Luhn Algorithm](https://en.wikipedia.org/wiki/Luhn_algorithm) for card number validation\n- 💳 Card type patterns and ranges based on industry standards\n- 🌟 Inspired by various open-source card validation libraries\n\n---\n\n## 📞 Support\n\nIf you encounter any issues or have questions, please file an issue on the [GitHub repository](https://github.com/juspay/cards-validator/issues).\n\n---\n\n<div align=\"center\">\n\nMade with ❤️ by [Juspay Technologies](https://juspay.in)\n\n⭐ Star us on [GitHub](https://github.com/juspay/cards-validator) — it helps us grow!\n\n</div>\n","readmeFilename":"README.md"}