Security News
JSR Working Group Kicks Off with Ambitious Roadmap and Plans for Open Governance
At its inaugural meeting, the JSR Working Group outlined plans for an open governance model and a roadmap to enhance JavaScript package management.
@mamba/utils
Advanced tools
@mamba/utils
O pacote @mamba/utils
contém métodos úteis para facilitar o desenvolvimento de aplicativos Mamba.
import * as UI from '@mamba/utils/ui.js';
timeout(delay: Number): Promise
UI.timeout()
move a execução do script para o final da pilha de execução. É uma simples abstração de um setTimeout
que retorna uma Promise
.
import { timeout } from '@mamba/utils/ui.js';
function init() {
console.log('Log imediato');
timeout(300).then(() => {
console.log('Log após 300ms');
});
}
init();
Com isso, é possível utilizar async/await
para facilitar a leitura de alguns métodos:
import { timeout } from '@mamba/utils/ui.js';
async function init() {
console.log('Log imediato');
await timeout(300);
console.log('Log após 300ms');
}
init();
import * as Money from '@mamba/utils/money.js';
format(value: Number): string
Money.format()
formata um valor númerico para um formato de dinheiro:
import { format } from '@mamba/utils/money.js';
format(100); // '100,00'
format(1000); // '1.000,00'
format(100000); // '100.000,00'
format(1000000.27); // '1.000.000,27'
padZero(value: Number | string): string
Money.padZero()
adiciona um 0
para valores numéricos menores que 10
or strings de tamanho 1
.
import { padZero } from '@mamba/utils/money.js';
padZero(1); // '01'
padZero('2'); // '02'
padZero(17); // '17'
padZero('230'); // '230'
round(value: Number): Number
ceil(value: Number): Number
floor(value: Number): Number
Money.round()
, Money.ceil()
, Money.floor()
são similares aos métodos Math.*
de mesmo nome. A principal diferença é que lidam com alguns erros de arrendondamento da linguagem e levam em conta o valor decimal.
import { round, ceil, floor } from '@mamba/utils/money.js';
Math.round(1.005); // 1
round(1.005); // 1.01
Math.floor(127.77 / 10); // 12
floor(127.77 / 10); // 12.77
Math.ceil(127.77 / 10); // 13
ceil(127.77 / 10); // 12.78
import * as DateUtils from '@mamba/utils/date.js';
format(date: Date, mask: string): string
DateUtils.format()
recebe um objeto Date
retorna a data formatada de acordo com a string
de máscara passada.
Os tokens
suportados são:
import { format } from '@mamba/utils/date.js';
format(new Date(2019, 1, 20), 'dd/mm/yyyy')) // 20/02/2019
format(new Date(2019, 1, 20, 20, 30, 55), 'HH:MM:ss')) // 20:30:55
FAQs
Utility methods for mamba apps
The npm package @mamba/utils receives a total of 107 weekly downloads. As such, @mamba/utils popularity was classified as not popular.
We found that @mamba/utils demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
At its inaugural meeting, the JSR Working Group outlined plans for an open governance model and a roadmap to enhance JavaScript package management.
Security News
Research
An advanced npm supply chain attack is leveraging Ethereum smart contracts for decentralized, persistent malware control, evading traditional defenses.
Security News
Research
Attackers are impersonating Sindre Sorhus on npm with a fake 'chalk-node' package containing a malicious backdoor to compromise developers' projects.