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

@imagineapps/utils

v0.0.3

Published

`@imagineapps-team/utils` é o pacote que contém as funções utilitárias que podem ser usadas em qualquer projeto.

Downloads

28

Readme

utils

@imagineapps-team/utils é o pacote que contém as funções utilitárias que podem ser usadas em qualquer projeto.

Instalação

yarn add @imagineapps-team/utils
# ou
npm install @imagineapps-team/utils

String

Utilitários para manipulação de strings.

StringComposer

Classe para facilitar a manipulação de strings.

import { StringComposer } from '@imagineapps-team/utils';

const stringComposer = new StringComposer('Hello World');

stringComposer
  .replace('Hello', 'Hi')
  .replace('World', 'Everyone')
  .append('!')
  .prepend('Hey, ');

console.log(stringComposer.toString()); // Hey, Hi Everyone!

console.log(
  StringComposer.create('Isso pode ser um texto muito grande')
    .truncate(10)
    .toString()
);
// -> Isso pode 

console.log(
  StringComposer.create('Arquivo de ação de usuário 2020')
    .sanitize()
    .truncate(30)
    .toString()
);
// -> arquivo-de-acao-de-usuario-2020

StringSanitizer

Higienização e tratamento de strings.

import { StringSanitizer } from '@imagineapps-team/utils';

const stringSanitizer = new StringSanitizer();

sanitizeSpecialLetters: Substitui todos os caracteres especiais por seu caractere "normal" (ASCII) correspondente. Também trata caracteres ISO-8859-1.

console.log(stringSanitizer.sanitizeSpecialLetters('Não é possível remover acentos')); 
// -> Nao e possivel remover acentos

console.log(stringSanitizer.sanitizeSpecialLetters('ação de bem estar'));
// -> acao de bem estar

clearSpecialCharacters: Remove todos os caracteres que não sejam letras, números ou espaços.


console.log(stringSanitizer.clearSpecialCharacters('#$ Não é possível remover acentos'));
// -> Não é possível remover acentos

StringTransformer

Transformação de strings comuns

import { StringTransformer } from '@imagineapps-team/utils';

const stringTransformer = new StringTransformer();

toKebabCase: Transforma uma string em kebab-case.

console.log(stringTransformer.toKebabCase('Não é possível remover acentos'));
// -> nao-e-possivel-remover-acentos

truncate: Trunca uma string para um tamanho máximo, adicionando um sufixo opcional no final.

console.log(stringTransformer.truncate('Não é possível remover acentos', 10));
// -> Não é pos

console.log(stringTransformer.truncate('Não é possível remover acentos', 10, '...'));
// -> Não é pos...

chunk: Divide uma string em um array de strings de tamanho máximo.

console.log(stringTransformer.chunk('Não é possível remover acentos', 10));
// -> ['Não é pos', 'sível remo', 'ver acento', 's']

toSlug: Transforma uma string em slug, podendo opcionalmente escolher o separador e tamanho máximo

console.log(stringTransformer.toSlug('Não é possível remover acentos'));
// -> nao-e-possivel-remover-acentos

console.log(stringTransformer.toSlug('Não é possível remover acentos', { separator: '_', maxLength: 10 }));
// -> nao_e_pos

StringEncoder

Codificação e decodificação de strings.

import { StringEncoder } from '@imagineapps-team/utils';

const stringEncoder = new StringEncoder();

fromISO88591: Decodifica uma string ISO-8859-1 para UTF-8.

console.log(stringEncoder.fromISO88591('ação de bem estar'));
// -> ação de bem estar

StringChecker

Verificação de strings.

import { StringChecker } from '@imagineapps-team/utils';

const stringChecker = new StringChecker();

hasUnicode: Verifica se uma string contém caracteres unicode.

console.log(stringChecker.hasUnicode('Não é possível remover acentos'));
// -> false

console.log(stringChecker.hasUnicode('Não é possível remover acentos 😁'));
// -> true

hasHtmlEntities: Verifica se uma string contém entidades HTML.

console.log(stringChecker.hasHtmlEntities('Não é possível remover acentos'));
// -> false

console.log(stringChecker.hasHtmlEntities('Não é possível remover acentos  '));
// -> true

Object

Utilitários para manipulação de objetos.

ObjectSet

Facilitar a manipulação de objetos únicos

import { ObjectSet } from '@imagineapps-team/utils';

const objectSet = new ObjectSet({ compareBy: 'id' });

objectSet.add({ id: 1, name: 'John' });
objectSet.add({ id: 2, name: 'Mary' });
objectSet.add({ id: 3, name: 'Peter' });

console.log(objectSet.toArray());
// -> [{ id: 1, name: 'John' }, { id: 2, name: 'Mary' }, { id: 3, name: 'Peter' }]

objectSet.add({ id: 2, name: 'Mary', other: 'other' });
console.log(objectSet.toArray());
// -> [{ id: 1, name: 'John' }, { id: 2, name: 'Mary' }, { id: 3, name: 'Peter' }] (não adiciona o objeto pois já existe um com o mesmo id)

console.log(objectSet.getDuplicates());
// -> [{ key: 2, identifier: 'id', values: [{ id: 2, name: 'Mary' }, { id: 2, name: 'Mary', other: 'other' } ] }]

objectSet.remove({ id: 2, name: 'Mary' });
console.log(objectSet.toArray());
// -> [{ id: 1, name: 'John' }, { id: 3, name: 'Peter' }]

objectSet.has({ id: 2, name: 'Mary' });
// -> false

Building

Run nx build utils to build the library.

Running unit tests

Run nx test utils to execute the unit tests via Jest.