1.0.4 • Published 2 years ago

pluralize-ptbr v1.0.4

Weekly downloads
138
License
MIT
Repository
-
Last release
2 years ago

Como usar

NPM

  1. Instale o pacote pluralize-ptbr com o NPM
$ npm install pluralize-ptbr
  1. Importe o pacote no seu projeto
const p = require("pluralize-ptbr");

function Pluralizar(palavras, condicao) {
    if (true == condicao) {
        return p(palavras)
    }
    return palavras
}

function ExibirAlerta(msgs) {
    const total = msgs.length
    
    if (total == 0) {
        return "Você não tem mensagem."
    }
    
    let obterPlural = total > 1 ? true : false
    let alertaLabel = `Você tem ${total} ${Pluralizar("nova mensagem", obterPlural)}`
    
    return alertaLabel
}

// ExibirAlerta([])
// -> "Você não tem mensagem."
//
// ExibirAlerta([1])
// -> "Você tem 1 nova mensagem."
//
// ExibirAlerta([1, 2, 3])
// -> "Você tem 3 novas mensagens."

Manualmente

<script src="https://raw.githubusercontent.com/k4fer74/pluralize-ptbr/master/pluralize-ptbr.browser.js"></script>

<script>
    console.log(plural("projétil mão"));
    // -> projéteis mãos
</script>