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

jgs-js-utils

v1.0.1

Published

Um punhado de ferramentas javascript úteis na formatação de números brasileiros e outras tarefas cotidianas.

Downloads

42

Readme

jgs-js-utils

Javascript formatting functions for the main Brazilian number standards.


Installation

  • Using NPM
npm install jgs-js-utils
  • Using YARN
yarn add jgs-js-utils

How to use

just import the desired function

import { formatPhoneNumber } from "jgs-js-utils";

var phone = 11987654321
console.log(formatPhoneNumber(phone)); // print: (11) 9 8765-4321

⚠️ all functions will show a warning on the console if given a null or undefined value and will return false or an empty string.


Functions List

Coming soon:

Using the Functions

formatOnlyNumbers

returns a string with only numbers.

Use

formatOnlyNumbers(string | number);

import { formatOnlyNumbers } from "jgs-js-utils";

console.log( formatOnlyNumbers('cpf: 476.848.724-60') );  // 47684872460
console.log( formatOnlyNumbers('     476848724-60 ') );   // 47684872460
console.log( formatOnlyNumbers('476848724-60 pos') );     // 47684872460

formatPhoneNumber

format different phone numbers, with or without area code, with or without the ninth digit.

Use

formatPhoneNumber(string | number);

import { formatPhoneNumber } from "jgs-js-utils";

console.log( formatPhoneNumber(11987654321) );   // (11) 9 8765-4321
console.log( formatPhoneNumber(1187654321) );    // (11) 8765-4321
console.log( formatPhoneNumber(987654321) );     // 9 8765-4321
console.log( formatPhoneNumber(87654321) );      // 8765-4321

console.log( formatPhoneNumber('11987654321') ); // (11) 9 8765-4321
console.log( formatPhoneNumber('1187654321') );  // (11) 8765-4321
console.log( formatPhoneNumber('987654321') );   // 9 8765-4321
console.log( formatPhoneNumber('87654321') );    // 8765-4321

formatZipCode

returns a string with the zip code formatted.

Use

formatZipCode(string | number);
import { formatZipCode } from "jgs-js-utils";

console.log( formatZipCode(1234567) );      // 1234567
console.log( formatZipCode(12345678) );     // 12345-678
console.log( formatZipCode('12345678') );   // 12345-678

formatCnpj

returns a string with the CNPJ formatted.

Use

formatCnpj(string | number);
import { formatCnpj } from "jgs-js-utils";

console.log( formatCnpj(12345678000104) );    // 12.345.678/0001-04
console.log( formatCnpj('12345678000104') );  // 12.345.678/0001-04

formatCpf

returns a string with the CPF formatted.

Use

formatCpf(string | number);
import { formatCpf } from "jgs-js-utils";

console.log( formatCpf(12345678901) );    // 123.456.789-01
console.log( formatCpf('12345678901') );  // 123.456.789-01

formatCnp

return a string with the CNPJ or CPF formatted.

Use

formatCnp(string | number);
import { formatCnp } from "jgs-js-utils";

console.log( formatCnp(12345678000104) );    // 12.345.678/0001-04
console.log( formatCnp('12345678000104') );  // 12.345.678/0001-04
console.log( formatCnp(12345678901) );       // 123.456.789-01
console.log( formatCnp('12345678901') );     // 123.456.789-01

validateEmail

returns true if the email is valid, false otherwise.

Use

validateEmail(string);
import { validateEmail } from "jgs-js-utils";

console.log( validateEmail('') );                  // false
console.log( validateEmail('teste') );             // false
console.log( validateEmail('teste@') );            // false
console.log( validateEmail('teste@teste') );       // false
console.log( validateEmail('[email protected]') );   // true

validateCnpj

returns true if the CNPJ is valid, false otherwise.

Use

validateCnpj(string | number);
import { validateCnpj } from "jgs-js-utils";

console.log( validateCnpj('77272951000144') );     // true
console.log( validateCnpj('77.272.951/0001-44') ); // true
console.log( validateCnpj(77272951000144) );       // true
console.log( validateCnpj('77.272.951/0001-43') ); // false
console.log( validateCnpj(77272951000143) );       // false

validateCpf

returns true if the CPF is valid, false otherwise.

Use

validateCpf(string | number);
import { validateCnpj } from "jgs-js-utils";

console.log( validateCpf('476.848.724-60') ); // true
console.log( validateCpf('225668949-22') );   // true
console.log( validateCpf(84832198327) );      // true
console.log( validateCpf('476.848.724-69') ); // false
console.log( validateCpf('225668949-21') );   // false
console.log( validateCpf(84832198326) );      // false