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

fillablestring

v1.4.1

Published

Classe para criação de strings, onde se deseja ter controle sobre posiçao e quantidade de caracteres.

Downloads

14

Readme

FillableString

Classe para criação de strings, onde se deseja ter controle sobre posição e quantidade de caracteres, ideal para criação de string para arquivos de remessas bancárias e outros onde controle da informação no texto é feito por posição.

Repositório NPM: https://www.npmjs.com/package/fillablestring

Instalação via NPM

npm install fillablestring --save

Exemplo de uso

const FillableString = require('fillablestring')

const stringText = new FillableString();
stringText.fill('REMESSA')
stringText.fill(' ')
stringText.fill("123456", 5, FillableString.POSITION_RIGHT)
stringText.fill(' ')
stringText.fill('JOÃO PEDRO DA SILVA')
stringText.fill("9", 2, FillableString.POSITION_LEFT)
stringText.fill("21", 2, FillableString.POSITION_RIGHT)
stringText.fill("\n")
stringText.fill('JOÃO PEDRO DA SILVA')
stringText.fill(' ', 27, FillableString.POSITION_RIGHT)
stringText.fill('[email protected]')
stringText.fill('21', 2, FillableString.POSITION_RIGHT)

console.info(stringText.getString())

Retorno da execução acima será:

99REMESSA 123456123456123456123456123456 JOÃO PEDRO DA SILVA2121
JOÃO PEDRO DA SILVA                           [email protected]

Documentação dos métodos

  • fill(string)

Preenche com determinado texto a string criada, exemplo:

const FillableString = require('fillablestring')

const stringText = new FillableString();
stringText.fill('REMESSA')

console.info(stringText.getString())

Retorno da execução acima será:

REMESSA
  • fill(string, size)

Preenche com determinado texto a string criada repetindo ela x número de vezes:

const FillableString = require('fillablestring')

const stringText = new FillableString();
stringText.fill('R', 2)

console.info(stringText.getString())

Retorno da execução acima será:

RR
  • fill(string, size, position)

Preenche com determinado texto a string criada possibilitando informar quantas vezes o texto irá se repetir informando esse valor no segundo parâmetro. Pode definir se o se a string será adicionada à direita ou a esquerda do texto, através do parametro possition onde os valores permitidos são FillableString.POSITION_LEFT ou FillableString.POSITION_RIGHT, exemplo:

const FillableString = require('fillablestring')

const stringText = new FillableString();
stringText.fill('REMESSA')
stringText.fill("@", 2, FillableString.POSITION_LEFT)
stringText.fill("-", 2, FillableString.POSITION_RIGHT)

console.info(stringText.getString()) 

Retorno da execução acima será:

@@REMESSA--
  • fillAndCompleteWith(string, fillable, size, position)

Preenche uma string com número exatos de caracteres completando espaços vazios com algum caracter especifico, ideal para preenchimento de string com tamanho fixo, onde deve-se completar os espaços faltante com algum caracters, exemplo:

const FillableString = require('fillablestring')

const stringText = new FillableString();
stringText.fillAndCompleteWith('Pedro', 0, 15, FillableString.POSITION_LEFT)

console.info(stringText.getString())

Retorno da execução acima será:

0000000000Pedro
  • removeSpecialCharacter()

Altera string removendo todos os caracteres especiais, exemplo:

const FillableString = require('fillablestring')

const stringText = new FillableString();
stringText.fill('654.498.480-99')
stringText.removeSpecialCharacter()

console.info(stringText.getString())

Retorno da execução acima será:

65449848099
  • removeWhiteSpaces()

Altera string removendo todos os espaços vazios, exemplo:

const FillableString = require('fillablestring')

const stringText = new FillableString();
stringText.fill('JOÃO PEDRO DA SILVA')
stringText.removeWhiteSpaces()

console.info(stringText.getString())

Retorno da execução acima será:

JOÃOPEDRODASILVA
  • getByPosition(start, end)

Retorna um trecho da string com base na sua posição, onde a primeira posição do texto é sempre 1, exemplo:

const FillableString = require('fillablestring')

const stringText = new FillableString();
stringText.fill('JOÃO PEDRO DA SILVA')

console.info(stringText.getByPosition(6, 10))

Retorno da execução acima será:

PEDRO
  • completeWith(string, size, position)

Preenche os espaços vazios de uma string até completar um certo número de caracteres, podendo escolher a posição do preenchimento, sendo para direita ou esquerda, exemplo:

const stringText = new FillableString();
stringText.fill('123')
stringText.completeWith(0, 6, FillableString.POSITION_LEFT)

Retorno da execução acima será:

000123
  • insertBefore(stringToFind, stringToAdd)

Insere uma string antes de uma string informada, exemplo:

const FillableString = require('fillablestring')

const stringText = new FillableString();
stringText.fill('JOÃO PEDRO')
stringText.insertBefore('JOÃO', 'NOME: ')
console.info(stringText.getString())

Retorno da execução acima será:

NOME: JOÃO PEDRO
  • insertAfter(stringToFind, stringToAdd)

Insere uma string após a string informada, exemplo:

const FillableString = require('fillablestring')

const stringText = new FillableString();
stringText.fill('JOÃO PEDRO')
stringText.insertAfter('JOÃO', ' E')
console.info(stringText.getString())

Retorno da execução acima será:

JOÃO E PEDRO

Teste unitário

Para executar os testes unitários deve-se executar o comando para instalar as dependências:

yarn install

Após instalado as depedências deve-se executar o teste untiário com o comando:

yarn test

O retorno deverá ser:

yarn run v1.22.10
$ jest --config ./jest.config.json
 PASS  ./fillableString.test.js
  FillableString
    ✓ Testando método constructor(string) (1 ms)
    ✓ Testando método fill(string)
    ✓ Testando método fill(string, size)
    ✓ Testando método fill(string, size, position) : FillableString.POSITION_RIGHT
    ✓ Testando método fill(string, size, position) : FillableString.POSITION_LEFT
    ✓ Testando método fillAndCompleteWith(string, fillable, size, position) : FillableString.POSITION_RIGHT (1 ms)
    ✓ Testando método fillAndCompleteWith(string, fillable, size, position) : FillableString.POSITION_LEFT
    ✓ Testando método removeSpecialCharacter()
    ✓ Testando método removeWhiteSpaces()
    ✓ Testando método getByPosition(start, end)
    ✓ Testando método completeWith(string, size, position) : FillableString.POSITION_RIGHT (1 ms)
    ✓ Testando método completeWith(string, size, position) : FillableString.POSITION_LEFT
    ✓ Testando método insertBefore(stringToFind, stringToAdd) : String vazia (1 ms)
    ✓ Testando método insertBefore(stringToFind, stringToAdd) : Com string preenchida
    ✓ Testando método insertAfter(stringToFind, stringToAdd) : String vazia
    ✓ Testando método insertAfter(stringToFind, stringToAdd) : Com string preenchida

-------------------|---------|----------|---------|---------|-------------------
File               | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s 
-------------------|---------|----------|---------|---------|-------------------
All files          |     100 |      100 |     100 |     100 |                   
 FillableString.js |     100 |      100 |     100 |     100 |                   
-------------------|---------|----------|---------|---------|-------------------
Test Suites: 1 passed, 1 total
Tests:       16 passed, 16 total
Snapshots:   0 total
Time:        0.191 s, estimated 1 s
Ran all test suites.
Done in 0.61s.