{"id":18389355,"url":"https://github.com/rightpoint/cardparser","last_synced_at":"2025-09-05T19:48:10.228Z","repository":{"id":143418192,"uuid":"75000661","full_name":"Rightpoint/CardParser","owner":"Rightpoint","description":"Credit Card Type Parsing for Swift","archived":false,"fork":false,"pushed_at":"2018-08-24T11:26:54.000Z","size":6,"stargazers_count":40,"open_issues_count":4,"forks_count":12,"subscribers_count":8,"default_branch":"master","last_synced_at":"2025-08-02T21:07:43.411Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Swift","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/Rightpoint.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":"2016-11-28T18:11:46.000Z","updated_at":"2024-12-16T23:18:54.000Z","dependencies_parsed_at":null,"dependency_job_id":"308e02db-429b-42a8-9366-921f94161e4c","html_url":"https://github.com/Rightpoint/CardParser","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/Rightpoint/CardParser","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Rightpoint%2FCardParser","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Rightpoint%2FCardParser/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Rightpoint%2FCardParser/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Rightpoint%2FCardParser/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Rightpoint","download_url":"https://codeload.github.com/Rightpoint/CardParser/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Rightpoint%2FCardParser/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":273812677,"owners_count":25172881,"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","status":"online","status_checked_at":"2025-09-05T02:00:09.113Z","response_time":402,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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-11-06T01:42:45.983Z","updated_at":"2025-09-05T19:48:10.204Z","avatar_url":"https://github.com/Rightpoint.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"# CardParser \n\n*Credit Card Type Parsing for Swift*\n\nCardParser is a lightweight utility for identifying major credit card types from in-progress input. This is useful for building responsive credit entry forms and validating input.\n\n## Usage\n\nFor now, just download and add `CardParser.swift` to your project.\n\n### The Basics\n\nTo determine the state of some in-progress text:\n\n```swift\nswitch CardState(fromPrefix: cardString) {\n\ncase .identified(let card):\n  //do something with card\n\ncase .indeterminate(let possibleCards):\n  //do something with possibleCards\n\ncase .invalid:\n  //show some validation error\n\n}\n```\n\nOr if you are just concerned with the validity of some completed input:\n```swift\nguard CardState(fromNumber: cardNumber) != .invalid else {\n    //show some validation error\n}\n```\n\n### Under The Hood\n\n`CardParser.swift` contains the enums:\n- `CardType` \n- `CardState`\n\n### Card Type\n`CardType` encapsulates credit card issuers and their validation/ formatting requirements\n```swift\n\nenum CardType {\n    case amex\n    case diners\n    case discover\n    case jcb\n    case masterCard\n    case visa\n}\n```\nYou can interact with an extracted card type to update your form:\n```swift\nlet visa: CardType = .visa\nvisa.isPrefixValid(\"4\") //true\nvisa.isValid(\"4\")       //false\nvisa.cvvLength          //3\nvisa.segmentGroupings   //[4, 4, 4, 4]\nvisa.maxLength          //19\n```\n\n### Card State\n`CardState` can be leveraged to identify the `CardType` (or possible `CardType`s) of some input.\n```swift\nenum CardState {\n    case identified(CardType)\n    case indeterminate([CardType])\n    case invalid\n}\n```\nUse `CardState` to extract state and type information\n```swift\nCardState(fromPrefix: \"4\")  //.identified(.visa)\nCardState(fromPrefix: \"3\")  //.indeterminate([.amex, .diners, .jcb])\nCardState(fromPrefix: \"0\")  //.invalid\n```\nFor example, you may write a method to return a card image for your form:\n```swift\nfunc cardImage(forState cardState:CardState) -\u003e UIImage? {\n    switch cardState {\n    case .identified(let cardType):\n        switch cardType{\n        case .visa:         return #imageLiteral(resourceName: \"credit_cards_visa\")\n        case .masterCard:   return #imageLiteral(resourceName: \"credit_cards_mastercard\")\n        case .amex:         return #imageLiteral(resourceName: \"credit_cards_americanexpress\")\n        case .diners:       return #imageLiteral(resourceName: \"credit_cards_diners\")\n        case .discover:     return #imageLiteral(resourceName: \"credit_cards_discover\")\n        case .jcb:          return #imageLiteral(resourceName: \"credit_cards_jcb\")\n        }\n    case .indeterminate: return #imageLiteral(resourceName: \"credit_cards_generic\")\n    case .invalid:      return #imageLiteral(resourceName: \"credit_cards_invalid\")\n    }\n}\n```\n\n## Author\n\nJay Clark: \u003cjason.clark@raizlabs.com\u003e\n\n## License\n\nCardParser is available under the MIT license. See the LICENSE file for more info.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frightpoint%2Fcardparser","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frightpoint%2Fcardparser","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frightpoint%2Fcardparser/lists"}