Skip to content

Commit ca0edd2

Browse files
committed
Updates
Updated Readme, Added prettier and usage details
1 parent b838e9c commit ca0edd2

File tree

13 files changed

+161
-64
lines changed

13 files changed

+161
-64
lines changed

.github/workflows/release.yml

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7,37 +7,37 @@ on:
77
- next
88

99
permissions:
10-
contents: write
11-
issues: write
12-
pull-requests: write
10+
contents: write
11+
issues: write
12+
pull-requests: write
1313

1414
jobs:
1515
release:
1616
runs-on: ubuntu-latest
1717

1818
steps:
19-
- name: Checkout code
20-
uses: actions/checkout@v4
19+
- name: Checkout code
20+
uses: actions/checkout@v4
2121

22-
- name: Set up Node.js
23-
uses: actions/setup-node@v4
24-
with:
25-
node-version: "lts/*"
22+
- name: Set up Node.js
23+
uses: actions/setup-node@v4
24+
with:
25+
node-version: 'lts/*'
2626

27-
- name: Install dependencies
28-
run: npm ci
27+
- name: Install dependencies
28+
run: npm ci
2929

30-
- name: Run tests
31-
run: npm test
30+
- name: Run tests
31+
run: npm test
3232

33-
- name: Build project
34-
run: npm run build
33+
- name: Build project
34+
run: npm run build
3535

36-
- name: Audit npm signatures
37-
run: npm audit signatures
36+
- name: Audit npm signatures
37+
run: npm audit signatures
3838

39-
- name: Release
40-
env:
41-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
42-
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
43-
run: npx semantic-release
39+
- name: Release
40+
env:
41+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
42+
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
43+
run: npx semantic-release

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
dist
2-
node_modules
2+
node_modules
3+
coverage
4+
.DS_Store

.prettierrc

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{
2+
"semi": true,
3+
"singleQuote": true,
4+
"trailingComma": "es5",
5+
"bracketSpacing": true,
6+
"arrowParens": "always",
7+
"tabWidth": 2,
8+
"printWidth": 80,
9+
"endOfLine": "lf",
10+
"proseWrap": "always",
11+
"quoteProps": "as-needed",
12+
"jsxSingleQuote": false,
13+
"htmlWhitespaceSensitivity": "css",
14+
"bracketSameLine": false,
15+
"overrides": [
16+
{
17+
"files": "*.ts",
18+
"options": {
19+
"parser": "typescript"
20+
}
21+
},
22+
{
23+
"files": "*.tsx",
24+
"options": {
25+
"parser": "typescript"
26+
}
27+
}
28+
]
29+
}

README.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# validate-functions
22

3-
The `validate-functions` package provides a set of utility functions for validating common identification numbers and formats, such as SSN, Email, and Aadhaar. This package is designed to be extensible, allowing for additional validation functions to be added incrementally.
3+
The `validate-functions` package provides a set of utility functions for validating common identification numbers and formats. This package will be keep on updating so better look out for latest version for more validation functions.
44

55
## Installation
66

@@ -9,3 +9,12 @@ To install the package, use npm:
99
```bash
1010
npm install validate-functions
1111
```
12+
13+
## Features
14+
15+
- **Email Validation**: Ensures that email addresses conform to standard formats.
16+
- **SSN Validation**: Validates U.S. Social Security Numbers based on predefined rules.
17+
- **Aadhaar Validation**: Checks the validity of Indian Aadhaar numbers using specific patterns.
18+
19+
20+
Usage Details available at [here](./USAGE_DETAILS.md).

USAGE_DETAILS.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
## Usage Details
2+
3+
- **isValid_Email**
4+
5+
```typescript
6+
import { isValid_Email } from 'validate-functions/email-validation';
7+
8+
const email = '<a href="mailto:[email protected]">[email protected]</a>';
9+
console.log(isValid_Email(email)); // Output: true if valid, false otherwise
10+
```
11+
12+
- **isValid_SSN**
13+
14+
```typescript
15+
import { isValid_SSN } from 'validate-functions/ssn-validation';
16+
17+
const ssn = '123-45-6789';
18+
console.log(isValid_SSN(ssn)); // Output: true if valid, false otherwise
19+
```
20+
21+
- **isValid_Aadhaar_Number**
22+
23+
```typescript
24+
import { isValid_Aadhaar_Number } from 'validate-functions/aadhaar-validation';
25+
26+
const aadhaarNumber = '1234 5678 9012';
27+
console.log(isValid_Aadhaar_Number(aadhaarNumber)); // Output: true if valid, false otherwise
28+
```

package-lock.json

Lines changed: 16 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
{
22
"name": "validate-functions",
33
"version": "0.0.0-development",
4-
"description": "A library containing validation functions such as SSN.",
4+
"description": "A library containing various validation functions.",
55
"main": "index.js",
66
"scripts": {
7-
"test": "jest",
7+
"test": "jest --silent --coverage",
88
"build": "tsc",
9+
"format": "prettier --config .prettierrc --write 'src/**/*.{ts,tsx}'",
910
"semantic-release": "semantic-release"
1011
},
1112
"repository": {
@@ -25,6 +26,7 @@
2526
"devDependencies": {
2627
"@types/jest": "^29.5.14",
2728
"jest": "^29.7.0",
29+
"prettier": "^3.4.2",
2830
"semantic-release": "^24.2.0",
2931
"ts-jest": "^29.2.5",
3032
"typescript": "^5.7.2"

release.config.cjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
module.exports = {
2-
branches: ["main", { name: "beta", prerelease: true }],
3-
};
2+
branches: ['main', { name: 'beta', prerelease: true }],
3+
};

src/aadhaar-validation.ts

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1-
/** Funtion to validate Aadhaar Number */
1+
/**
2+
* Aadhaar is a twelve-digit unique identity number that can be obtained voluntarily by all residents of India, based on their biometrics and demographic data.
3+
* @param aadhaar_number
4+
* @returns
5+
*/
26
export const isValid_Aadhaar_Number = (aadhaar_number: string): boolean => {
7+
// Regex to check valid aadhaar_number
8+
let regex = new RegExp(/^[2-9]{1}[0-9]{3}\s[0-9]{4}\s[0-9]{4}$/);
39

4-
// Regex to check valid
5-
// aadhaar_number
6-
let regex = new RegExp(/^[2-9]{1}[0-9]{3}\s[0-9]{4}\s[0-9]{4}$/);
10+
// if aadhaar_number is empty return false
11+
if (aadhaar_number == null) {
12+
return false;
13+
}
714

8-
// if aadhaar_number
9-
// is empty return false
10-
if (aadhaar_number == null) {
11-
return false;
12-
}
13-
14-
// Return true if the aadhaar_number
15-
// matched the ReGex
16-
return regex.test(aadhaar_number);
17-
}
15+
// Return true if the aadhaar_number matched the ReGex
16+
return regex.test(aadhaar_number);
17+
};

src/email-validation.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1+
/**
2+
* Electronic mail (e-mail) is a computer-based application for the exchange of messages between users.
3+
* @param email
4+
* @returns
5+
*/
16
export const isValid_Email = (email: string): boolean => {
2-
const re = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
3-
return re.test(email);
4-
}
7+
const re = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
8+
return re.test(email);
9+
};

0 commit comments

Comments
 (0)