text-regex-validation
v1.0.6
Published
This is npm package for validation of texts and Many other featurs
Downloads
8
Maintainers
Readme
text-regex-validation
Introduction
This package includes the following functionalities 🐻
Text Validation: This could include checks for length, presence of certain characters, format requirements (like email addresses or phone numbers), or any other rules you need. Use same method if you have your own regex with third parameter of your regex and make second parameter null.
Log Analysis: For analyzing logs, you might want to create functions that parse log files and extract relevant data.
Search and Replace: Implement functions that perform search and replace operations on strings..
URL Parsing: Create functions that parse URLs into their component parts. Regular expressions can help with this by matching different parts of the URL (protocol, domain, path, query parameters, etc.) and extracting them into separate variables or objects.
Get Regex: Create functions that return regex pattern for different inputs from user.
Convert base64ToString: This method will return string if we provide base64 value to it.
Convert stringToBase64: This method will return base64 if we provide string value to it.
getCountryCallingCode: This method will return country list with its calling code's.
Installation
npm install text-regex-validation
OR
npm i text-regex-validation
Usage Guidelines
Text Validation:
To validate string or get regex you have to Call below function respectively. If you have your own regex then use same method by passing third parameter (your regex) and make second parameter null.
validateString(inputString, regexType) //string and regextype from table
validateString(inputString, null, {Your regex}) // Your regex must be in /{your regex}/ like this not in "{your regex}" string. It will return true or false.
getRegex(regexType) // Regex Type will be same from the below regexType name It will return exact regex for that type
regexType name must be same
it will return true or false(Boolean).
Example
import {validateString,analyzeLog, searchAndReplace,parseUrl, base64ToString, stringToBase64} from 'text-regex-validation'
TABLE
| regexType name | Input String Example | Description |
|:------:|:------:|:--:|
| email | [email protected]
| This is for validation of E-mail pattern like {[email protected]} |
| url | https://chat.openai.com
| This is for validation of URL pattern like {https://chat.openai.com} |
| date | 2024-03-04
| This is for validation of Date in pattern like {YYYY-MM-DD} |
| username | username_123
| This is for validation of Username (Alphanumeric with underscores, hyphens, or periods) |
| time | 14:30
| This is for validation of Time (HH:MM 24-hour format) |
| ipv4 | 192.168.1.1
| This is for validation of IPv4 Address |
| ipv6 | 2001:0db8:85a3:0000:0000:8a2e:0370:7334
| This is for validation of IPv6 Address |
| creditcard | 4111111111111111
| This is for validation of Credit Card Number (Visa, MasterCard, American Express, Discover) |
| html | <tag>content</tag>
| This is for validation of HTML Tags|
| zipus | 12345
or 12345-6789
| This is for validation of ZIP Code (U.S.) |
| phoneindia | +911234567890
| This is for validation of Phone number og india like {+91{10 digits are allowed}} |
| phoneus | +1 (555) 123-4567
| This is for validation of Phone number of US|
| phoneuk | +44 20 1234 5678
| This is for validation of Phone number of UK|
| phoneaus | +61 2 1234 5678
| This is for validation of Phone number of Australia|
| phonecan | +1 (416) 123-4567
| This is for validation of Phone number of Canada|
| pin | 123456
| This is for validation of pin code |
| name | John Doe
| This is for validation of name |
| password | P@ssw0rd
| This is for validation of password |
| aadhar | 1234 5678 9101
| This is for validation of aadhar |
| username | username123
| This is for validation of userName |
validateString("[email protected]", 'email')
// output :- true
Log Analysis:
analyzeLog('[2024-03-03 10:17:20] ERROR: Invalid username or password')
// output :- [
// {
// timestamp: '2024-03-03 10:17:20',
// error: 'Invalid username or password',
// ip: 'N/A'
// }
// ]
Search and Replace:
searchAndReplace('This is sample data', 'is', 'not')
// output :- This not sample data
URL Parsing:
parseUrl('https://www.example.com:8080/path/to/page?param1=value1¶m2=value2#section1')
// output :- {
// protocol: 'https',
// domain: 'www.example.com',
// port: '8080',
// path: '/path/to/page',
// queryParams: [ 'param1=value1', 'param2=value2' ],
// fragment: 'section1'
// }
Get Regex:
getRegex('phoneindia')
// output :- /^\+?(91)?[\s-]?\d{10}$/
Convert base64ToString:
const base64String = 'SGVsbG8sIFdvcmxkIQ==';
console.log(base64ToString(base64String));
// output :- Hello, World!
Convert stringToBase64:
const base64String = 'Hello, World!';
console.log(stringToBase64(base64String));
// output :- SGVsbG8sIFdvcmxkIQ==
getCountryCallingCode:
getCountryCallingCode()
// output :- Without parameter It will return list of all countries
getCountryCallingCode("india")
// output :- { name: 'india', dial_code: '+91', code: 'IN' }
Build
npm run build
Contribute
If you would like to contribute your most welcome. Clone the repository 🐻.