{"id":17419798,"url":"https://github.com/bendrucker/creditcards-types","last_synced_at":"2025-05-16T14:04:40.828Z","repository":{"id":27440756,"uuid":"30918874","full_name":"bendrucker/creditcards-types","owner":"bendrucker","description":"Card type definitions and methods for creditcards","archived":false,"fork":false,"pushed_at":"2025-02-03T12:06:57.000Z","size":713,"stargazers_count":70,"open_issues_count":2,"forks_count":20,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-05-06T08:46:53.586Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bendrucker.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2015-02-17T13:50:07.000Z","updated_at":"2024-12-16T23:18:52.000Z","dependencies_parsed_at":"2024-06-18T15:03:36.633Z","dependency_job_id":"e4580404-626d-44aa-abe1-6723249e44c5","html_url":"https://github.com/bendrucker/creditcards-types","commit_stats":{"total_commits":142,"total_committers":15,"mean_commits":9.466666666666667,"dds":0.295774647887324,"last_synced_commit":"91f463452855b0222f359556801be5932fb735be"},"previous_names":[],"tags_count":26,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bendrucker%2Fcreditcards-types","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bendrucker%2Fcreditcards-types/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bendrucker%2Fcreditcards-types/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bendrucker%2Fcreditcards-types/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bendrucker","download_url":"https://codeload.github.com/bendrucker/creditcards-types/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253891775,"owners_count":21979855,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-17T02:33:28.217Z","updated_at":"2025-05-16T14:04:40.806Z","avatar_url":"https://github.com/bendrucker.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# creditcards-types [![tests](https://github.com/bendrucker/creditcards-types/workflows/tests/badge.svg)](https://github.com/bendrucker/creditcards-types/actions?query=workflow%3Atests)\n\n\u003e Card type definitions in JavaScript modules\n\nThis library powers [creditcards](https://github.com/bendrucker/creditcards), a higher level tool for parsing/formatting/validating card data. This repository focuses on [tests](#tests) and [documentation](docs). Card types are primarily represented by static values and regular expressions.\n\n## Card Types\n\n* Visa\n* Mastercard\n* American Express\n* Diners Club\n* Discover\n* JCB\n* UnionPay\n* Maestro\n* Forbrugsforeningen\n* Dankort\n* Troy\n* Elo\n* Mir\n* UATP\n\nVisa Electron cards will validate and match as regular Visa cards. \n\nCard data can be required individually by [type](types/). The main module includes _all_ defined card types. You may want to select specific cards that your customers will use to save bytes or avoid confusion.\n\n## Co-Branded Cards\n\nThe main types in this library have unique patterns that map to major card networks. In some locales, companies issue co-branded with other card networks within the major partner's BIN range. This library includes these types as modules but _does not_ include co-branded types in the main export. Custom types include:\n\n* Mada\n* Meeza\n\nSimilar to [using custom types](#usage), you can prepend optional types to the main list. Cards that previously matched as a major issuer will instead match the custom type if applicable.\n\n```js\nvar types = [ require('creditcards-types/types/mada') ].concat(require('creditcards-types'))\n```\n\n[Open an issue](https://github.com/bendrucker/creditcards-types/issues/new) or a PR if you'd like to contribute documentation/code for a type that's missing.\n\n## Test Card Numbers\n\nSome processors (e.g. [Stripe](https://stripe.com/docs/testing)) support fake card numbers used for testing payments. In some cases, these test card numbers do not fall within the actual issuing range. For example, `6011 1111 1111 1117` is provided as a Discover test card, but falls outside of the [documented range](./docs/discover.md). If you need to match these cards, you'll need to handle them outside this library or [add a custom type](#usage). \n\n## Installing\n\n```sh\nnpm install --save creditcards-types\n```\n\n## Usage\n\n```js\n// finding\nvar types = require('creditcards-types')\nvar type = types.find(type =\u003e type.test('4', true))\n// type.name =\u003e Visa\n\n// specific types\nvar visa = require('creditcards-types/types/visa')\nvisa.test('4242424242424242') // true\n\n// creating custom types\nvar Type = require('creditcards-types/type')\nvar myCard = Type({\n  name: 'My Card',\n  pattern: /^999\\d{13}$/\n  eagerPattern: /^999/,\n  luhn: false\n})\n\nvar myTypes = types.concat(myCard) // myCard gets lowest priority\n```\n\n## API\n\n#### `new Type(data)` -\u003e `type`\n\nCreates a new card type.\n\n```js\nvar Type = require('creditcards-types/type')\nvar type = Type(data)\n```\n\n##### data\n\n*Required*  \nType: `object`\n\nThe type configuration, containing the following properties:\n\n* `pattern`\n  * description: A regular expression for validating a full card number.\n  * required: `true`\n  * type: `regexp`\n* `eagerPattern`\n  * description: A regular expression for guessing the card type from a partial number.\n  * required: `true`\n  * type: `regexp`\n* `groupPattern`\n  * description: A regular expression for separating the card number into formatting. groups\n  * type: `regexp`\n  * default: `/(\\d{1,4})(\\d{1,4})?(\\d{1,4})?(\\d{1,4})?/`\n* `cvcLength`\n  * description: The length of the CVC expected for the card type.\n  * type: `number`\n  * default: `3`\n* `luhn`\n  * description: Setting for whether the card should pass a [Luhn](https://github.com/bendrucker/fast-luhn) check. Not used internally, purely informational.\n  * type: `boolean`\n  * default: `true`\n\n---\n\n#### `type.test(number, [eager])` -\u003e `boolean`\n\nCheck whether a card number matches the type.\n\n##### number\n\n*Required*  \nType: `string`\n\nThe card number to test.\n\n##### eager\n\nType: `Boolean`  \nDefault: `false`\n\nWhen `false`, the full card pattern is used. When `true`, the eager pattern is tested instead.\n\n```js\nvar visa = require('creditcards-types/types/visa')\n\n// Strict type validation\nvisa.test('4242424242424242') // =\u003e true\n\n// Eager type checking\nvisa.test('42', true) // =\u003e true\n```\n\n---\n\n#### `type.group(number)` -\u003e `array[string]`\n\nSeparates the card number into formatting groups. \n\n##### number\n\n*Required*  \nType: `string`\n\nThe card number to group. This may be a complete or partial card number. Any digits past the type's maximum length will be discarded.\n\n## Tests\n\nThis repository is designed to support a large volume of automated testing. There are two types of tests.\n\n#### Regression tests (~100)\n\nTraditional regression tests are included in the [`test/`](test) folder. These tests describe the regular expressions and make assertions about a few possible card patterns. Each type tests checks that expedcted eager matches for that type do not also match another card type. There's also a coverage check that will fail the test run if any type module is missing an identically named test file.\n\n#### Fuzz tests (~12,500)\n\nAs an additional check, `npm test` downloads [range data from binlist](https://github.com/binlist/data). The [binlist tests](binlist-test.js):\n\n* Check the BIN range start and end to make sure they are an eager match for their corresponding type\n* Generate a random card number matching the maximum length for that type\n* Strictly test the generated number against the type\n\nThis data is not guaranteed to be accurate but provides a valuable external check against the validity of the type definitions with far more assertions than could ever be written by hand. \n\n\n\n## License\n\nMIT © [Ben Drucker](http://bendrucker.me)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbendrucker%2Fcreditcards-types","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbendrucker%2Fcreditcards-types","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbendrucker%2Fcreditcards-types/lists"}