-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cleaned up the national id functions
- Loading branch information
Ardalan Amini
committed
Dec 24, 2017
1 parent
5da3bce
commit 9bfc391
Showing
9 changed files
with
166 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,61 +1,100 @@ | ||
# Verifications | ||
|
||
universal validation library for developers | ||
A **TypeScript Ready** universal validation library for developers | ||
|
||
[![npm](https://img.shields.io/npm/v/verifications.svg)](https://www.npmjs.com/package/verifications) | ||
[![npm](https://img.shields.io/npm/dt/verifications.svg)](https://www.npmjs.com/package/verifications) | ||
[![npm](https://img.shields.io/npm/dm/verifications.svg)](https://www.npmjs.com/package/verifications) | ||
[![GitHub stars](https://img.shields.io/github/stars/ardalanamini/verifications.svg)](https://github.com/ardalanamini/verifications/stargazers) | ||
[![license](https://img.shields.io/github/license/ardalanamini/verifications.svg)](https://github.com/ardalanamini/verifications/blob/master/LICENSE) | ||
|
||
[TOC] | ||
|
||
### Installation | ||
|
||
`npm install --save verifications` | ||
`npm i -s verifications` | ||
|
||
### Usage | ||
|
||
#### require / import | ||
|
||
```javascript | ||
const Verifications = require('verifications'); | ||
|
||
var isNationalIdValid = new Verifications() | ||
.nationalId | ||
.verify('xxx-xxxxxx-x'); | ||
|
||
isNationalIdValid = new Verifications('US') | ||
.nationalId | ||
.verify('xxx-xx-xxxx'); | ||
// or | ||
isNationalIdValid = new Verifications() | ||
.setLocale('US') | ||
.nationalId | ||
.verify('xxx-xx-xxxx'); | ||
|
||
var isCreditCardValid = Verifications | ||
.CreditCard | ||
.verify('xxxx-xxxx-xxxx-xxxx'); | ||
import Verifications from 'verifications'; | ||
``` | ||
|
||
* for client side usage you're going to need json-loader or something... | ||
|
||
##### Available Methods | ||
#### Available Methods | ||
|
||
- nationalId - (needs locale) | ||
- verify(code: string): boolean | ||
- NationalID - (static method) | ||
- verify(code: string, locale?: string): boolean | ||
- CreditCard - (static method) | ||
- verify(code: string): boolean | ||
- type(code: string): string | undefined | ||
- issuer(code: string): { name: string, alias: string, website: string } | undefined | ||
- identify(code: string): { type: Type, issuer: Issuer } | undefined | ||
|
||
### nationalId | ||
##### NationalID | ||
|
||
**Supported countries:** | ||
returns true if the code matches any supported format | ||
|
||
```javascript | ||
var isNationalIDValid = Verifications | ||
.NationalID | ||
.verify('xxx-xxxxxx-x'); | ||
``` | ||
|
||
you can also enforce the locale | ||
|
||
```javascript | ||
isNationalIdValid = Verifications | ||
.NationalID | ||
.verify('xxx-xx-xxxx', 'US'); | ||
``` | ||
|
||
**Supported Locales:** | ||
|
||
- Iran (IR) - کد ملی | ||
- United States (US) - Social Security Number | ||
|
||
### CreditCard | ||
##### CreditCard | ||
|
||
returns true if the code matches any supported format | ||
|
||
```javascript | ||
var isCreditCardValid = Verifications | ||
.CreditCard | ||
.verify('xxxx-xxxx-xxxx-xxxx'); | ||
``` | ||
|
||
returns identity of the card/issuer | ||
|
||
```javascript | ||
var isCreditCardValid = Verifications | ||
.CreditCard | ||
.identify('xxxx-xxxx-xxxx-xxxx'); | ||
``` | ||
|
||
returns type of the card | ||
|
||
```javascript | ||
var isCreditCardValid = Verifications | ||
.CreditCard | ||
.type('xxxx-xxxx-xxxx-xxxx'); | ||
``` | ||
|
||
returns issuer of the card | ||
|
||
```javascript | ||
var isCreditCardValid = Verifications | ||
.CreditCard | ||
.issuer('xxxx-xxxx-xxxx-xxxx'); | ||
``` | ||
|
||
**Luhn verification algorithm (almost all credit cards around the globe)** | ||
|
||
- 9 card/issuer types | ||
- 46 active issuers are supported | ||
|
||
***** | ||
|
||
**for client side usage you're going to need json-loader or something...** |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
{ | ||
"name": "verifications", | ||
"version": "0.2.0", | ||
"description": "universal validation library for developers", | ||
"version": "0.2.1", | ||
"description": "universal verification library for developers", | ||
"main": "dist/index.js", | ||
"scripts": { | ||
"prepublish": "npm run build && npm run files", | ||
|
@@ -17,8 +17,67 @@ | |
"keywords": [ | ||
"verification", | ||
"identification", | ||
"IR", | ||
"US", | ||
"credit card", | ||
"types", | ||
"Airlines", | ||
"Travel", | ||
"Banking and Financial", | ||
"Merchandising and Banking/Financial", | ||
"Petroleum", | ||
"Healthcare", | ||
"Telecommunications", | ||
"National Assignment", | ||
"issuer", | ||
"bank", | ||
"Mellat Bank", | ||
"Saman Bank", | ||
"Parsian Bank", | ||
"Tejarat Bank", | ||
"Ansar Bank", | ||
"Eghtesad Novin Bank", | ||
"Karafarin Bank", | ||
"Export Development Bank of Iran", | ||
"Post Bank of Iran", | ||
"Bank of Industry and Mine", | ||
"Bank Maskan", | ||
"Ayandeh Bank", | ||
"Sina Bank", | ||
"Mehr Eqtesad Bank", | ||
"Sarmayeh Bank", | ||
"Bank Sepah", | ||
"Refah Bank", | ||
"American Express", | ||
"Bank Pasargad", | ||
"Shahr Bank", | ||
"Tose'e Ta'avon Bank", | ||
"Bank Day", | ||
"Bank Saderat Iran", | ||
"Keshavarzi Bank", | ||
"Bank Melli Iran", | ||
"China UnionPay", | ||
"Diners Club International", | ||
"Discover Card", | ||
"Decoupled debit card", | ||
"Japan Credit Bureau", | ||
"Maestro", | ||
"Dankort", | ||
"Mir (payment system)", | ||
"MasterCard", | ||
"Visa Inc", | ||
"Universal Air Travel Plan", | ||
"Interswitch", | ||
"TROY", | ||
"CARDGUARD EAD BG ILS", | ||
"Royal Bank of Canada", | ||
"TD Canada Trust", | ||
"The Bank of Nova Scotia", | ||
"Bank of Montreal", | ||
"Hongkong Bank of Canada", | ||
"national code", | ||
"credit card" | ||
"ssn", | ||
"social security number" | ||
], | ||
"author": "Ardalan Amini <[email protected]>", | ||
"license": "MIT", | ||
|
@@ -30,6 +89,7 @@ | |
"url": "https://github.com/ardalanamini/verifications/issues" | ||
}, | ||
"devDependencies": { | ||
"copyfiles": "^1.2.0", | ||
"typescript": "^2.6.2" | ||
} | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import * as IR from './IR' | ||
import * as US from './US' | ||
|
||
const locales: { [key: string]: any } = { | ||
IR, | ||
US | ||
} | ||
|
||
export default class NationalId { | ||
static get locales() { | ||
return Object.keys(locales) | ||
} | ||
|
||
static verify(code: string, locale?: string) { | ||
if (locale) { | ||
if (NationalId.locales.indexOf(locale) === -1) throw new Error('used locale is not supported') | ||
|
||
locale = locale.toUpperCase() | ||
|
||
return locales[locale].verify(code) | ||
} | ||
|
||
for (let l in locales) { | ||
if (locales[l].verify()) return true | ||
} | ||
|
||
return false | ||
} | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default } from './NationalID' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,7 @@ | ||
import nationalId from './nationalId' | ||
import NationalID from './NationalID' | ||
import CreditCard from './CreditCard' | ||
|
||
export default class Verifications { | ||
private locale: string | ||
|
||
constructor(locale: string = 'IR') { | ||
this.locale = locale.toUpperCase() | ||
} | ||
|
||
setLocale(locale: string) { | ||
this.locale = locale.toUpperCase() | ||
|
||
return this | ||
} | ||
|
||
get nationalId(): Object { | ||
return nationalId[this.locale] | ||
} | ||
|
||
static NationalID = NationalID | ||
static CreditCard = CreditCard | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,8 @@ | ||
export function range(start: number = 0, stop: number = start, step: number = 1) { | ||
const length = Math.max(Math.ceil((stop - start) / step), 0); | ||
let range = []; | ||
const length = Math.max(Math.ceil((stop - start) / step), 0) | ||
let range = [] | ||
|
||
for (let i = 0; i < length; i++, start += step) { | ||
range.push(start); | ||
} | ||
for (let i = 0; i < length; i++, start += step) range.push(start) | ||
|
||
return range; | ||
}; | ||
return range | ||
} |