Skip to content

Commit

Permalink
v0.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Ardalan Amini committed Dec 26, 2017
1 parent cc58cd7 commit 74a0d05
Show file tree
Hide file tree
Showing 21 changed files with 734 additions and 51 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Change Log

## v0.3.0

1. added Phone to verifications (IR only for now)
2. added UK to NationalID locales support
3. transformed json files info js variables (no more json-loader, yay!)
123 changes: 87 additions & 36 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Verifications

A **TypeScript Ready** universal validation library for developers
A **TypeScript Ready** universal verification library (Server-Side and Client-Side) for developers.

[![npm](https://img.shields.io/npm/v/verifications.svg)](https://www.npmjs.com/package/verifications)
[![npm](https://img.shields.io/npm/dm/verifications.svg)](https://www.npmjs.com/package/verifications)
Expand All @@ -9,90 +9,141 @@ A **TypeScript Ready** universal validation library for developers

[TOC]

### Installation
## Installation

`npm i -s verifications`

### Usage
## Usage

#### require / import
### require / import

```javascript
const Verifications = require('verifications').default;
// or
// Node.js :
const Verifications = require('verifications');
// ES6 :
import Verifications from 'verifications';
// Typescript :
import * as Verifications from 'verifications';
```

#### Available Methods
### Available Methods

- NationalID - (static method)
- NationalID
- verify(code: string, locale?: string): boolean
- CreditCard - (static method)
- CreditCard
- 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
- Phone
- identify(number: string): identity: { [key: string]: any } | undefined
- country(number: string): { name: string, alias: string } | undefined
- fancy(number: string): string
- normalize(number: string): string

##### NationalID
#### NationalID

returns true if the code matches any supported format
##### Verify

```javascript
var isNationalIDValid = Verifications
.NationalID
.verify('xxx-xxxxxx-x');
Verifications
.NationalID
.verify('xxx-xxxxxx-x');
// returns true if the code matches any supported format
```

you can also enforce the locale

```javascript
isNationalIdValid = Verifications
.NationalID
.verify('xxx-xx-xxxx', 'US');
Verifications
.NationalID
.verify('xxx-xx-xxxx', 'US');
```

**Supported Locales:**

- Iran (IR) - کد ملی
- United States (US) - Social Security Number
- United States (US) - Social Security Number (SSN)
- United Kingdom (UK) - National Insurance Number (NINO)

##### CreditCard
#### CreditCard

returns true if the code matches any supported format

##### Verify

```javascript
var isCreditCardValid = Verifications
.CreditCard
.verify('xxxx-xxxx-xxxx-xxxx');
Verifications
.CreditCard
.verify('xxxx-xxxx-xxxx-xxxx');
// returns true if the code matches any supported format
```

returns identity of the card/issuer
##### Identify

```javascript
var isCreditCardValid = Verifications
.CreditCard
.identify('xxxx-xxxx-xxxx-xxxx');
Verifications
.CreditCard
.identify('xxxx-xxxx-xxxx-xxxx');
// returns identity of the card/issuer
```

returns type of the card
##### Type

```javascript
var isCreditCardValid = Verifications
.CreditCard
.type('xxxx-xxxx-xxxx-xxxx');
Verifications
.CreditCard
.type('xxxx-xxxx-xxxx-xxxx');
// returns type of the card
```

returns issuer of the card
##### Issuer

```javascript
var isCreditCardValid = Verifications
.CreditCard
.issuer('xxxx-xxxx-xxxx-xxxx');
Verifications
.CreditCard
.issuer('xxxx-xxxx-xxxx-xxxx');
// returns issuer of the card
```

**Luhn verification algorithm (almost all credit cards around the globe)**

- 9 card/issuer types
- 46 active issuers are supported

*****
#### Phone

##### Identify

```javascript
Verifications
.Phone
.identify('+xx (xxx) xxx xxxx');
// returns the identity of the number or undefined
```

##### Country

```javascript
Verifications
.Phone
.country('+xx (xxx) xxx xxxx');
// returns the country of the number or undefined
```

##### Fancy

```javascript
Verifications
.Phone
.fancy('00xx xx x xxx x x xx');
// returns the beautified format if supported or the given number
```

##### Normalize

```javascript
Verifications
.Phone
.normalize('+xx (xxx) xxx xxxx');
// returns numbers only -> xxxxxxxxxxxx
```
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"name": "verifications",
"version": "0.2.1",
"version": "0.3.0",
"description": "universal verification library for developers",
"main": "dist/index.js",
"scripts": {
"prepare": "./scripts/prepare.js",
"prepare": "node ./scripts/prepare.js",
"build": "tsc",
"test": "echo \"Error: no test specified\" && exit 1"
},
Expand Down
24 changes: 24 additions & 0 deletions src/CreditCard/CreditCard.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,27 @@
//
// MIT License
//
// Copyright (c) 2017 Ardalan Amini
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
//

import * as issuers from './issuers.json'
import * as types from './types.json'
import { range } from '../utils'
Expand Down
24 changes: 24 additions & 0 deletions src/CreditCard/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,25 @@
//
// MIT License
//
// Copyright (c) 2017 Ardalan Amini
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
//

export { default } from './CreditCard'
26 changes: 26 additions & 0 deletions src/NationalID/IR.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,29 @@
//
// MIT License
//
// Copyright (c) 2017 Ardalan Amini
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
//

// National Identification Number (کد ملی)

export function verify(code: string) {
code = code.replace(/\D/g, '') // just in case

Expand Down
27 changes: 27 additions & 0 deletions src/NationalID/NationalID.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,38 @@
//
// MIT License
//
// Copyright (c) 2017 Ardalan Amini
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
//

import * as IR from './IR'
import * as UK from './UK'
import * as US from './US'

const locales: { [key: string]: any } = {
IR,
UK,
US
}

// @see https://en.wikipedia.org/wiki/National_identification_number
export default class NationalId {
static get locales() {
return Object.keys(locales)
Expand Down
39 changes: 39 additions & 0 deletions src/NationalID/UK.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
//
// MIT License
//
// Copyright (c) 2017 Ardalan Amini
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
//

// National Insurance Number - NI Number (NINO)

export function verify(code: string) {
code = code.replace(/_|\W/g, '') // just in case

if (code.length !== 9) return false

code = code.toUpperCase()

if (!/^[ABCEGHJKLMNOPRSTWXYZ]{1}[ABCEGHJKLMNPRSTWXYZ]{1}\d{6}[A-D]{1}$/.test(code)) return false

if (/^(BG|GB|NK|KN|TN|NT|ZZ)/.test(code)) return false

return true
}
26 changes: 26 additions & 0 deletions src/NationalID/US.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,29 @@
//
// MIT License
//
// Copyright (c) 2017 Ardalan Amini
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
//

// Social Security Number (SSN)

const blackList = [
'078-05-1120'
]
Expand Down
Loading

0 comments on commit 74a0d05

Please sign in to comment.