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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@koalarx/utils

v4.2.1

Published

Biblioteca com validadores, conversores e abstrações de algumas problemáticas

Downloads

89

Readme

@koalarx/utils

Biblioteca utilitária para validações, conversões e abstrações de problemas comuns em JavaScript/TypeScript.

Instalação

npm install @koalarx/utils

Funcionalidades

KlString

Classe para manipulação avançada de strings.

Métodos Disponíveis

  • normalizeAndRemoveSpecialChars: Remove caracteres especiais e normaliza a string.
  • removeSpaces: Remove espaços, substituindo-os por um delimitador.
  • clear: Remove espaços e caracteres especiais.
  • toCamelCase: Converte a string para camelCase.
  • unmaskCoin: Remove a máscara de moeda e converte para número.
  • maskCpf: Aplica a máscara de CPF.
  • maskCnpj: Aplica a máscara de CNPJ.
  • validateCpf: Valida se a string é um CPF válido.
  • validateCnpj: Valida se a string é um CNPJ válido.
  • onlyNumbers: Remove todos os caracteres não numéricos.
  • nbl2br: Substitui quebras de linha por <br/>.
  • toBase64: Converte a string para Base64.
  • random: Gera uma string aleatória.

Exemplos de Uso

import { KlString, maskCpf, toCamelCase } from "@koalarx/utils/KlString";

const str = new KlString("Olá Mundo!");
console.log(str.normalizeAndRemoveSpecialChars().toString()); // "Ola Mundo"
console.log(maskCpf("12345678909")); // "123.456.789-09"
console.log(toCamelCase("Olá Mundo")); // "olaMundo"

KlNumber

Classe para manipulação avançada de números.

Métodos Disponíveis

  • random: Gera um número aleatório entre dois valores.
  • maskCoin: Formata o número como moeda.

Exemplos de Uso

import { maskCoin, randomNumber } from "@koalarx/utils/KlNumber";

console.log(maskCoin(1000)); // "R$ 1.000,00"
console.log(randomNumber(1, 100)); // Exemplo: 42

KlDate

Classe para manipulação avançada de datas.

Métodos Disponíveis

  • format: Formata a data com base em uma máscara.
  • changeTimeZone: Altera o fuso horário da data.
  • toUTC: Converte a data para UTC.
  • add: Adiciona tempo à data.
  • sub: Subtrai tempo da data.
  • diff: Calcula a diferença entre duas datas.
  • isHoliday: Verifica se a data é um feriado.

Exemplos de Uso

import { KlDate, isHoliday } from "@koalarx/utils/KlDate";

const date = new KlDate("2023-10-01");
console.log(date.format("dd/MM/yyyy")); // "01/10/2023"
console.log(isHoliday(date, "BR")); // true ou false

KlTime

Classe para manipulação avançada de horários.

Métodos Disponíveis

  • format: Formata um horário com base em uma máscara.
  • changeTimeZone: Altera o fuso horário da data.
  • toUTC: Converte a data para UTC.
  • add: Adiciona tempo à data.
  • sub: Subtrai tempo da data.
  • diff: Calcula a diferença entre duas datas.

Exemplos de Uso

import { KlTime } from "@koalarx/utils/KlTime";

const date = new KlTime(13);
console.log(date.format()); // "13:00:00"

KlArray

Classe para manipulação avançada de arrays.

Métodos Disponíveis

  • clearEmptyValues: Remove valores "falsy" do array.
  • split: Divide o array em subarrays.
  • orderBy: Ordena o array por uma propriedade.
  • shuffle: Embaralha os elementos do array.

Exemplos de Uso

import { KlArray } from "@koalarx/utils/KlArray";

const array = new KlArray([1, 2, 3, 4]);
console.log(array.split(2)); // [[1, 2], [3, 4]]
console.log(array.shuffle()); // Exemplo: [3, 1, 4, 2]

KlDelay

Classe para criar atrasos no código.

Métodos Disponíveis

  • waitFor: Aguarda um período de tempo especificado.

Exemplos de Uso

import { delay } from "@koalarx/utils/KlDelay";

await delay(1000);
console.log("Aguardou 1 segundo");

KlCron

Classe para medir a duração de execuções.

Métodos Disponíveis

  • start: Inicia o cronômetro.
  • end: Finaliza o cronômetro.
  • duration: Calcula a duração entre o início e o fim.

Exemplos de Uso

import { KlCron } from "@koalarx/utils/KlCron";

const cron = new KlCron();
cron.start();
// ... código a ser medido ...
cron.end();
console.log(cron.duration()); // Duração em segundos

Contribuição

Contribuições são bem-vindas! Por favor, abra uma issue ou envie um pull request no repositório do GitHub.

Licença

MIT © Igor D. Rangel