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

@guilelab/tools

v1.6.0

Published

Essa é uma pequena biblioteca "canivete suíço" com funções e ferramentas de uso comum <br/> <br/>

Downloads

20

Readme

@guilelab/tools

Essa é uma pequena biblioteca "canivete suíço" com funções e ferramentas de uso comum

Classe GuileMath

GuileMath.choice(...items: any[]): any

Uso:

const { GuileMath } = require("@guilelab/tools")

const fruits = ["banana", "mango", "pineapple", "grape"];
const choicedFruit = GuileMath.choice(...fruits);

console.log("There is a random fruit: %s", choicedFruit);

Classe GuileTreeNode


const { GuileTreeNode } = require("@guilelab/tools")

const options = {
    key: "any-key", //Chave do nó
    parent: "parent-key", //Chave do nó pai
    extras: { ... }, //Qualquer dado desejado
    childrens: [{
        key: "any-key-2",
        parent: "parent-key-2",
        ...
    }] //Nós filhos seguindo a mesma lógica do options
}

//Construtor da árvore de nós
const tree = new GuileTreeNode(options);

//Corrigir o id dos filhos com base no id do pai
const correctParentKeys = GuileTreeNode.fillParent(tree);

//Converter árvore para lista
const listFromTree = GuileTreeNode.treeToList(correctParentKeys);

/* 
    Converter lista para árvore. É possível passar no segundo parametro o nó em que se deseja montar a estrutura.
*/
const treeFromList = GuileTreeNode.listToTree(listFromTree)

Classe GuileGigaNumber

const { GuileGigaNumber } = require("@guilelab/tools")

const HUNDRED_THOUSAND = 100000;

//Um numero em string com o 18 repetido 100.000 vezes (200.000 digitos)
const reallyBigNumber = "18".repeat(HUNDRED_THOUSAND);
//Um outro numero em string com o 85 repetido 100.000 vezes (200.000 digitos)
const reallyBigNumber2 = "85".repeat(HUNDRED_THOUSAND);

//Realiza uma soma, o resultado é retornado em uma string
const resultPlus = GuileGigaNumber.add(
	reallyBigNumber,
	reallyBigNumber2
)

console.log('Num. de digitos:', resultPlus.length);
console.log('Resultado %s...', resultPlus.substring(0, 100));

//Calcula a potencia de 10^1000
const muchMoreThanOneGoogol = GuileGigaNumber.pow("10", "1000")
console.log('Num. de digitos:', muchMoreThanOneGoogol.length);
console.log('Resultado %s...', muchMoreThanOneGoogol.substring(0, 100));

Classe GuileArray

const { GuileArray } = require("@guilelab/tools")


//Retorna o primeiro item da array ou um valor default
console.log(GuileArray.firstOrDefault([1, 2, 3], "s/v")) // 1
console.log(GuileArray.firstOrDefault([], "s/v")) // 1

//Retorna o ultimo item da array ou um valor default
console.log(GuileArray.lastOrDefault([1, 2, 3], "s/v")) // 3
console.log(GuileArray.lastOrDefault([], "s/v")) // 1

//Quebra a array em subarrays de tamanho igual ou menor do que o informado
console.log(GuileArray.chunk([1, 2, 3], 2)) // [[1, 2], [3]]


//Injeta as funções dentro de Array
GuileArray.injectToGlobalMethods();

console.log([1 ,2 ,3].firstOrDefault("s/v")) // 1
console.log([].firstOrDefault("s/v")) // "s/v"

console.log([1 ,2 ,3].lastOrDefault("s/v")) // 3
console.log([].lastOrDefault("s/v")) // "s/v"

console.log([1 ,2 ,3].chunk(2)) // [[1, 2], [3]]