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

lual-utils

v0.0.5

Published

This repository aims to guide a tutorial on how to create an npm module, and mainly to add useful functions that I use in my daily life in various projects.

Downloads

27

Readme

Introduction 📖

lual-utils is a library that was built for creating an article about developing a JavaScript package for publication on NPM. The article is in Portuguese and can be accessed at the following link:

Artigo: Como criar um pacote JavaScript para o NPM

In this article, I cover step by step the process of building this package, from project creation to publishing on NPM. However, to make it more than just a theoretical article, I created this package with some utility functions that I use frequently in my daily life and that might be useful for you too.

Features 🚀

  • Validate CPF
  • Validate CNPJ
  • Generate Random Code
  • Phone Number Masking for Major Countries
  • Validate Email
  • Validate URL
  • New features coming soon ⏱️

Contributing 🤝

If you want to contribute to this project, feel free to fork this repository and submit a pull request. I will be happy to review and approve it.

Installation 📦

To install lual-utils, run the following command:

npm install lual-utils

Validate CPF and CNPJ

Validation of CPF and CNPJ using regular expressions and validation algorithms.

// Import the lual-utils module
import { isCpfOrCnpjValid } from 'lual-utils'

const cpf = '12345678901'
const cnpj = '12345678901234'

console.log(isCpfOrCnpjValid(cpf)) // true or false
console.log(isCpfOrCnpjValid(cnpj)) // true or false

Validate Email

Email validation using regular expressions.

// Import the lual-utils module
import { isEmailValid } from 'lual-utils'

const emailExample = '[email protected]'

console.log(isEmailValid(emailExample)) // true or false

Generate Random Code

Generate a random code to be used as a token, password, etc. This generation uses the Math.random() algorithm.

// Import the lual-utils module
import { genRandomStrCode } from 'lual-utils'

const password = genRandomStrCode(8)
console.log(password) // 7sa2d3f4

Phone Number Masking

Phone number masking for major countries, using regular expressions based on the country codes of the 25+ most used countries.

// Import the lual-utils module
import { setPhoneMask } from 'lual-utils'

const phone = '5511999999999'
const phoneMask = setPhoneMask(phone) // +55 (11) 99999-9999

Validate URL

URL validation using regular expressions.

// Import the lual-utils module
import { isUrlValid } from 'lual-utils'

// Validate only HTTPS URLs
validateUrl('https://example.com', { protocols: ['https'] }) // true
validateUrl('http://example.com', { protocols: ['https'] }) // false

// Validate URLs HTTP and HTTPS without IP
validateUrl('http://example.com', { allowIp: false }) // true
validateUrl('http://192.168.0.1', { allowIp: false }) // false

// Validate URLs HTTPS and HTTPS with IP
validateUrl('https://192.168.0.1', { protocols: ['https'], allowIp: true }) // true
validateUrl('http://192.168.0.1', { protocols: ['https'], allowIp: true }) // false