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

wordizer

v1.3.0

Published

A library for pluralizing and singularizing words in both English and Portuguese. It supports dynamic word transformations based on language-specific rules.

Downloads

39

Readme

Wordizer

Wordizer is a library for pluralizing and singularizing words in both English and Portuguese. It supports dynamic word transformations based on language-specific rules.

Installation

To install wordizer, use npm or yarn:

npm install wordizer
yarn add wordizer

Usage

Pluralizing and Singularizing Words

wordizer provides functions to pluralize and singularize words for supported languages. Here is an example of how to use wordizer with English and Portuguese:

import { pluralize, singularize } from 'wordizer'

const plural = pluralize('apple', 'en') // -> apples
const singular = singularize('apples', 'en') // -> apple

Contributing Adding New Languages

Wordizer on GitHub

To add a new language to wordizer, follow these steps:

  1. Create a new directory for the language (e.g., fr for French) under the root directory.
  2. Create a rules.js file and populate with the rules for the new language.
  3. Create index.js file in the new language directory.
  4. Initialize the inflector with the rules in the index.js file.

Here is an example of adding French to wordizer:

import inflector from '../inflector.js'
import { pluralization, singularization, uncountable, irregular } from './rules'

export const pluralizeFr = inflector(pluralization, uncountable, irregular)
export const singularizeFr = inflector(singularization, uncountable, irregular)
  1. Update the main index.js file to include the new language:
import { pluralizeFr, singularizeFr } from './fr/index.js'

export const wordizer = {
  // -------------------------------------------------
  fr: {
    pluralize: pluralizeFr,
    singularize: singularizeFr,
  },
  // -------------------------------------------------

  en: {
    pluralize: pluralizeEn,
    singularize: singularizeEn,
  },
  pt: {
    pluralize: pluralizePt,
    singularize: singularizePt,
  },
}

export const pluralize = (word, lang) => {
  return wordizer[lang].pluralize(word)
}
export const singularize = (word, lang) => {
  return wordizer[lang].singularize(word)
}

Running Tests

To run tests for both English and Portuguese, use the following command:

npm test

Here is an example of the test script (wordizer.test.js):

import { wordizer } from './index.js'

const testWords = {
  en: {
    singular: ['apple', 'banana', 'orange', 'strawberry', 'grape'],
    plural: ['apples', 'bananas', 'oranges', 'strawberries', 'grapes'],
  },
  pt: {
    singular: ['maçã', 'banana', 'laranja', 'morango', 'uva'],
    plural: ['maçãs', 'bananas', 'laranjas', 'morangos', 'uvas'],
  },
}

const runTests = (language, wordizer) => {
  const { singular, plural } = testWords[language]

  console.log(`\nTesting ${language.toUpperCase()} Pluralization:`)
  singular.forEach((word, index) => {
    const result = wordizer.pluralize(word)
    const expected = plural[index]
    const status = result === expected ? '🟢' : '🔴'
    console.log(`${status} ${word} -> ${result} (expected: ${expected})`)
  })

  console.log(`\nTesting ${language.toUpperCase()} Singularization:`)
  plural.forEach((word, index) => {
    const result = wordizer.singularize(word)
    const expected = singular[index]
    const status = result === expected ? '🟢' : '🔴'
    console.log(`${status} ${word} -> ${result} (expected: ${expected})`)
  })
}

runTests('en', wordizer.en)
runTests('pt', wordizer.pt)

License

This project is licensed under the ISC License.

Acknowledgements

This package is a fork of the Pluralize and PluralizePTBR libraries. I have refactored it to create wordizer, enhancing its functionality to support both English and Portuguese with a modular approach for easy addition of new languages.