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

koala-utils

v1.0.34

Published

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

Downloads

9

Readme

Koala Utils

Install

npm i koala-utils

Usage

merge

let arraySample = [1]
arraySample = koala(arraySample).array<number>()
                                .merge([2])
                                .getValue();

console.log(arraySample);// [1,2]

map

const result = koala([{name: 'test1'}, {name: 'test2'}])
  .array<any>()
  .map(item => {
    if (item.name === 'test2') {
      item.name = 'Hello World';
    }    
    return item;
  }).getValue();

console.log(result);// [{name: 'test1'}, {name: 'Hello World'}]

filter

let result = koala([
   {teste: 123},
   {teste2: 543}
]).array().filter("123", "teste").getValue();

console.log(result);// [{teste: 123}]

getIndex

let index = koala([
  {teste: 123},
  {teste: "123"}
]).array().getIndex("teste",123);

console.log(index);// 0

split

let result = koala([1,2,3,4]).array()
                             .split(2)
                             .getValue();

console.log(result);// [[1,2],[3,4]]

toString

let result = koala([1,2,3,4]).array()
                             .toString(',')
                             .getValue();

console.log(result);// "1,2,3,4"

orderBy

let result = koala([
   {date: new Date('2020-06-18')},
   {date: new Date('2020-06-15')},
   {date: new Date('2020-06-17')},
   {date: new Date('2020-06-20')}
]).array().orderBy('date').getValue();

// [
//   {date: new Date('2020-06-15')},
//   {date: new Date('2020-06-17')},
//   {date: new Date('2020-06-18')},
//   {date: new Date('2020-06-20')}
// ]
console.log(result);

//inverse
let result = koala([
   {date: new Date('2020-06-18')},
   {date: new Date('2020-06-15')},
   {date: new Date('2020-06-17')},
   {date: new Date('2020-06-20')}
]).array().orderBy('date',true);

// [
//   {date: new Date('2020-06-20')},
//   {date: new Date('2020-06-18')},
//   {date: new Date('2020-06-17')},
//   {date: new Date('2020-06-15')}
// ]
console.log(result);

toBase64

let result = koala([
    {nome: 'Teste 1'},
    {nome: 'Teste 2'}
]).array()
  .toBase64()
  .getValue();

console.log(result);// "bm9tZQpUZXN0ZSAxClRlc3RlIDI="

pipe

let result = koala([
    {proposal: '123'},
    {proposal: '456'},
    {proposal: '789'}
]).array<{proposal: string}>()
  .pipe<number>(objProposta => {
    return klArray.getValue().map((item) => parseInt(item.proposal));
  })
  .getValue();

console.log(result);// [123,456,789]

pipeAsync

let result = (await koala([
    {proposal: '123'},
    {proposal: '456'},
    {proposal: '789'}
]).array<{proposal: string}>()
  .pipeAsync<number>(async objProposta => {
    await KlDelay.waitfor(300);
    return klArray.getValue().map((item) => parseInt(item.proposal));
  }))
  .getValue();

console.log(result);// [123,456,789]

clear

let result = koala('Olá Mundo').string()
                               .clear()
                               .getValue();

console.log(result);// "Ola Mundo"

let result = koala('Olá Mundo').string()
                               .clear('-')
                               .getValue();

console.log(result);// "Ola-Mundo"

nbl2br

let result = koala('Olá\nMundo').string()
                                .nbl2br()
                                .getValue();

console.log(result);// "Olá<br/>Mundo"

maskCpf

let result = koala('47695329037').string()
                                 .maskCpf()
                                 .getValue();

console.log(result);// "476.953.290-37"

maskCnpj

let result = koala('5581451000183').string()
                                   .maskCnpj()
                                   .getValue();

console.log(result);// "05.581.451/0001-83"

toCamelCase

let result = koala('Olá Mundo').string()
                               .toCamelCase()
                               .getValue();

console.log(result);// "olaMundo"

split

let result = koala('1,2').string()
                         .split()
                         .getValue();

console.log(result);// ['1', '2']

unmaskCoin

let result = koala('1.000,00').string()
                              .unmaskCoin()
                              .getValue();

console.log(result);// 1000

concat

let result = koala('teste').string()
                           .concat('1')
                           .getValue();

console.log(result);// "teste1"

let result = koala('1').string()
                       .concat('teste', true)
                       .getValue();

console.log(result);// "teste1"

random

let result = koala('').string()
                      .random(4, true, true, true, true)
                      .getValue();

console.log(result);// "4Oa@"

toBase64

let result = koala('teste').string()
                           .toBase64()
                           .getValue();

console.log(result);// "dGVzdGU="

replace

let result = koala('Hellow World').string()
                              .replace('Hellow', 'Hello')
                              .getValue();

console.log(result);// 1000
</details><br>

<details>
 <summary><strong>Number Utils usage</strong></summary>
 
### random
```bash
let result = koala(0).number()
                     .random(1000, 2000)
                     .getValue();

console.log(result);// 1389

maskCoin

let result = koala(1000).number()
                        .maskCoin()
                        .getValue();

console.log(result);// "R$ 1.000,00"

format

let result = koala('2020-06-20').date()
                                .format('DD/MM/YYYY')
                                .getValue();

console.log(result);// '20/06/2020'

let result = koala('2020-06-20').date()
                                .format('HH:mm:ss')
                                .getValue();

console.log(result);// '00:00:00'

let result = koala('2020-06-20').date()
                                .format()
                                .getValue();

console.log(result);// '20/06/2020 00:00:00'

let result = koala('2020-06-20T13:51:00').date('+0300')
                                         .format()
                                         .getValue();

console.log(result);// '20/06/2020 07:51:00'

add

let result = koala('2020-01-01').date()
                                .add({qtd: 1, type: 'days'})
                                .getValue();

console.log(result);// Date('2020-01-02')

let result = koala('2020-10-30').date()
                                .add({qtd: 1, type: 'days', ignoreDays: [
                                    KlDateDay.saturday, 
                                    KlDateDay.sunday
                                ])
                                .getValue();

console.log(result);// Date('2020-11-02')

sub

let result = koala('2020-01-02').date()
                                .sub({qtd: 1, type: 'days'})
                                .getValue();

console.log(result);// Date('2020-01-01')

let result = koala('2020-10-30').date()
                                .sub({qtd: 1, type: 'days', ignoreDays: [
                                    KlDateDay.saturday, 
                                    KlDateDay.sunday
                                ])
                                .getValue();

console.log(result);// Date('2020-11-23')

isHoliday

let result = koala('2020-11-02').date().isHoliday();

console.log(result);// true

waitFor

public async ForAsyncFunctions(){
    await KlDelay.waitFor(1000); // wait's 1s after to pass new line
    // some code
}

merge

let result = koala({teste: 1}).object<any>()
                              .merge({teste2: 2})
                              .getValue();

console.log(result); // {teste: 1,teste2: 2}

toString

let result = koala({
    param1: "Hello",
    param2: "World"
}).object().toString(['param1','param2']).getValue();

console.log(result); // "Hello World"

request

let result = await koala('https://exemple.com')
    .request()
    .get<Users[]>('/users', {name: 'test'});

console.log(result); // {statusCode: number, data: Users[]}