npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

text-regex-validation

v1.0.6

Published

This is npm package for validation of texts and Many other featurs

Downloads

8

Readme

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 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&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 🐻.