1.0.6 • Published 1 year ago

text-regex-validation v1.0.6

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

text-regex-validation PRs Welcome

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 nameInput String ExampleDescription
emailabc121@xyz.comThis is for validation of E-mail pattern like {abc121@xyz.com}
urlhttps://chat.openai.comThis is for validation of URL pattern like {https://chat.openai.com}
date2024-03-04This is for validation of Date in pattern like {YYYY-MM-DD}
usernameusername_123This is for validation of Username (Alphanumeric with underscores, hyphens, or periods)
time14:30This is for validation of Time (HH:MM 24-hour format)
ipv4192.168.1.1This is for validation of IPv4 Address
ipv62001:0db8:85a3:0000:0000:8a2e:0370:7334This is for validation of IPv6 Address
creditcard4111111111111111This is for validation of Credit Card Number (Visa, MasterCard, American Express, Discover)
html<tag>content</tag>This is for validation of HTML Tags
zipus12345 or 12345-6789This is for validation of ZIP Code (U.S.)
phoneindia+911234567890This is for validation of Phone number og india like {+91{10 digits are allowed}}
phoneus+1 (555) 123-4567This is for validation of Phone number of US
phoneuk+44 20 1234 5678This is for validation of Phone number of UK
phoneaus+61 2 1234 5678This is for validation of Phone number of Australia
phonecan+1 (416) 123-4567This is for validation of Phone number of Canada
pin123456This is for validation of pin code
nameJohn DoeThis is for validation of name
passwordP@ssw0rdThis is for validation of password
aadhar1234 5678 9101This is for validation of aadhar
usernameusername123This is for validation of userName
validateString("example@example.com", '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&param2=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 🐻.

1.0.6

1 year ago

1.0.5

1 year ago

1.0.4

1 year ago

1.0.3

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago