Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

pluralize-ptbr

matheuslugon921MIT1.0.4

Obtenha o plural em portugês brasileiro de palavras no singular

pluralize, br, plural, português

readme

Obtenha o plural de palavras no singular em português brasileiro 🇧🇷

Como usar

NPM

  1. Instale o pacote pluralize-ptbr com o NPM

    $ npm install pluralize-ptbr
  2. 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>