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

@koalarx/utils

v3.1.3

Published

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

Downloads

360

Readme

Koala Utils

Install

npm i @koalarx/utils

String

maskCpf

import { maskCpf } from "@koalarx/utils/operators/string";

maskCpf("11111111111");

// Result: 111.111.111-11

maskCnpj

import { maskCnpj } from "@koalarx/utils/operators/string";

maskCnpj("11111111000111");

// Result: 11.111.111/0001-11

unmaskCpf

import { unmaskCpf } from "@koalarx/utils/operators/string";

unmaskCpf("111.111.111-11");

// Result: 11111111111

unmaskCnpj

import { unmaskCnpj } from "@koalarx/utils/operators/string";

unmaskCnpj("11.111.111/0001-11");

// Result: 11111111000111

validateCpf

import { validateCpf } from "@koalarx/utils/operators/string";

validateCpf("111.111.111-11");

// Result: false

validateCnpj

import { validateCnpj } from "@koalarx/utils/operators/string";

validateCnpj("11.111.111/0001-11");

// Result: false

randomString

import { randomString } from "@koalarx/utils/operators/string";

randomString(4, true, true, true, true);

// Result: 1Aa$

clear

import { clear } from "@koalarx/utils/operators/string";

clear("Olá Mundo");

// Result: Ola Mundo

unmaskCoin

import { unmaskCoin } from "@koalarx/utils/operators/string";

unmaskCoin("R$ 1.000,00");

// Result: 1000

toCamelCase

import { toCamelCase } from "@koalarx/utils/operators/string";

toCamelCase("Olá Mundo");

// Result: olaMundo

nbl2br

import { nbl2br } from "@koalarx/utils/operators/string";

nbl2br("Line1\nLine2");

// Result: Line1<br/>Line2

toRegex

import { toRegex } from "@koalarx/utils/operators/string";

toRegex("000.000.000-00");

// Result: /\d{3}.\d{3}.\d{3}-\d{2}/

Number

maskCoin

import { maskCoin } from "@koalarx/utils/operators/number";

maskCoin(1000);

// Result: R$ 1.000,00

random

import { klNumber } from "@koalarx/utils/operators/number";

klNumber(0).random(1000, 2000).getValue();

// Result: 3000

Date

format

import { format } from "@koalarx/utils/operators/date";

format("2020-01-01", "DD/MM/YYYY");

// Result: 01/01/2020

isHoliday

import { isHoliday } from "@koalarx/utils/operators/date";

isHoliday("2020-01-01");

// Result: true

add

import { format } from "@koalarx/utils/operators/date";

add("2020-01-01", 2);

// Result: 2020-01-03

sub

import { format } from "@koalarx/utils/operators/date";

sub("2020-01-03", 2);

// Result: 2020-01-01

diff

import { format } from "@koalarx/utils/operators/date";

diff("2020-01-01", "2020-01-03");

// Result: 2

Delay

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

async () => {
  //some code...

  await delay(2000);

  //some code...
};

Array

map

import { klArray } from "@koalarx/utils/operators/array";

klArray([{ name: "test1" }, { name: "test2" }])
  .map((item) => {
    if (item.name === "test2") {
      item.name = "Hello World";
    }
    return item;
  })
  .getValue();

// Result: [{ name: 'test1' }, { name: 'Hello World' }]

mapAsync

import { klArray } from "@koalarx/utils/operators/array";

async () => {
  // some code...
  (
    await klArray([
      { proposal: "123" },
      { proposal: "456" },
      { proposal: "789" },
    ]).mapAsync<number>(async (item) => {
      await klDelay(300);
      return parseInt(item.proposal, 10);
    })
  ).getValue();
  // some code...
};

// Result: [123, 456, 789]

merge

import { klArray } from "@koalarx/utils/operators/array";

klArray([1]).merge([2]).getValue();

// Result: [1, 2]

filter

import { klArray } from "@koalarx/utils/operators/array";

klArray([{ teste: 123 }, { teste2: 543 }])
  .filter("123", "teste")
  .getValue();

// Result: [{ teste: 123 }]

getIndex

import { klArray } from "@koalarx/utils/operators/array";

klArray([{ teste: 123 }, { teste: 123 }]).getIndex("teste", 123);

// Result: 0

split

import { klArray } from "@koalarx/utils/operators/array";

klArray([1, 2, 3, 4]).split(2).getValue();

// Result: [ [1, 2], [3, 4] ]

toString

import { klArray } from "@koalarx/utils/operators/array";

klArray([1, 2, 3, 4]).toString(",").getValue();

// Result: '1,2,3,4'

orderBy asc

import { klArray } from "@koalarx/utils/operators/array";

klArray([
  { date: new Date("2020-06-18") },
  { date: new Date("2020-06-15") },
  { date: new Date("2020-06-17") },
  { date: new Date("2020-06-20") },
])
  .orderBy("date")
  .getValue();

// Result: [
//   { date: new Date('2020-06-15') },
//   { date: new Date('2020-06-17') },
//   { date: new Date('2020-06-18') },
//   { date: new Date('2020-06-20') },
// ]

orderBy desc

import { klArray } from "@koalarx/utils/operators/array";

klArray([
  { date: new Date("2020-06-18") },
  { date: new Date("2020-06-15") },
  { date: new Date("2020-06-17") },
  { date: new Date("2020-06-20") },
])
  .orderBy("date", true)
  .getValue();

// Result: [
//   { date: new Date('2020-06-20') },
//   { date: new Date('2020-06-18') },
//   { date: new Date('2020-06-17') },
//   { date: new Date('2020-06-15') },
// ]

toBase64

import { klArray } from "@koalarx/utils/operators/array";

(
  await klArray([{ nome: "Teste 1" }, { nome: "Teste 2" }]).toBase64()
).getValue();

// Result: 'bm9tZQpUZXN0ZSAxClRlc3RlIDI='

pipe

import { klArray } from '@koalarx/utils/operators/array';

[{ proposal: '123' }, { proposal: '456' }, { proposal: '789' }])
  .pipe((klArray) => {
    return klArray.getValue().map((item) => parseInt(item.proposal, 10))
  })
  .getValue()

// Result: [123, 456, 789]

pipeAsync

import { klArray } from "@koalarx/utils/operators/array";

(
  await klArray([
    { proposal: "123" },
    { proposal: "456" },
    { proposal: "789" },
  ]).pipeAsync(async (klArray) => {
    await klDelay(300);
    return klArray.getValue().map((item) => parseInt(item.proposal, 10));
  })
).getValue();

// Result: [123, 456, 789]

shuffleArray

import { klArray } from "@koalarx/utils/operators/array";

klArray([{ id: 1 }, { id: 2 }, { id: 3 }])
  .shuffle()
  .getValue();

// Result: [{ id: 2 }, { id: 1 }, { id: 3 }]

Object

merge

import { klObject } from "@koalarx/utils/operators/object";

klObject({ teste: 1 }).merge<any>({ teste2: 2 }).getValue();

// Result: { teste: 1, teste2: 2 }

toString

import { klObject } from "@koalarx/utils/operators/object";

klObject({
  param1: "Hello",
  param2: "World",
})
  .toString(["param1", "param2"])
  .getValue();

// Result: 'Hello World'

clone

import { clone } from "@koalarx/utils/operators/object";

clone({ id: 1 });

Cron

import { klCron } from "@koalarx/utils/operators/cron";

const cron = klCron();

cron.start();
await klDelay(2000);
cron.end();

cron.duration(); // Result: 2