Giter VIP home page Giter VIP logo

plur's Introduction

plur

Pluralize a word

Install

npm install plur

Usage

import plur from 'plur';

plur('rainbow');
//=> 'rainbows'

plur('unicorn', 4);
//=> 'unicorns'

plur('puppy', 2);
//=> 'puppies'

plur('box', 2);
//=> 'boxes'

plur('cactus', 2);
//=> 'cacti'

API

plur(word, plural?, count?)

word

Type: string

The word to pluralize.

plural

Type: string
Default:

  • Irregular nouns will use this list.
  • Words ending in s, x, z, ch, sh will be pluralized with -es (eg. foxes).
  • Words ending in y that are preceded by a consonant will be pluralized by replacing y with -ies (eg. puppies).
  • All other words will have "s" added to the end (eg. days).

Explicitly provide the pluralized word.

The plural suffix will match the case of the last letter in the word.

This option is only for extreme edge-cases. You probably won't need it.

count

Type: number

The count to determine whether to use singular or plural. If omitted, defaults to plural.

plur's People

Contributors

alexmeah avatar bendingbender avatar cadam11 avatar coreyfarrell avatar ersel avatar fed avatar icyflame avatar mriceman avatar ntwb avatar richienb avatar sindresorhus avatar therealklanni avatar tyriar avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

plur's Issues

Type for single param invocation

Since plur defaults to returning the plural version, it's handy when you don't have a specific count but just want to get the plural form. Right now, plur('word') returns (correctly) words, but TypeScript complains about this usage. Would be nice if the type defs added a single-param overload.

I'm happy to open a PR if this sounds reasonable to the maintainers.

I get a type error on this line:

For some reason, when I compile the Vite project and ran the preview command.
It throws an error in console and all components become non-functioning.

has method does not exist

irregularPlurals.has(word.toLowerCase())

So I am unsure what is it. At the moment, since we use only a single word for pluralization, I wrote my own tiny function that will just append s for plural meaning. For more complex checks and words, I'd like to use this package, but it's just not working.

Reverse operation

As the module already knows how to convert singluar to plural, I wonder if the reverse operation, e.g. convert plural to singular can be supported without much effort. I'd certainly have use cases for it.

negative counts

library does not handle negative counts currently.

plur('unicorn', -1);
//expected => 'unicorn'
//actual => 'unicorns'

Custom rules

Hi, is there a way to define custom rules?
E.g. pluralize feedback => feedback (just an example, not sure how plur actually handles this word right now)

Please, ship es2015 version

The version of uglify I'm using using doesn't support es6 and the node_modules is not compiles. So I'm getting error SyntaxError: Unexpected token: operator (>) [./~/plur/index.js:4,0] during a builds.

Jest Testing Error

Thanks for writing this package!

I'm getting the following error in Jest when tying to use this package. It looks like the issue may be because the 'irregular-plurals' dependency uses a "require" instead of "import" (even thought the error says "SyntaxError: Cannot use import statement outside a module", it's pointing to the "require" statement)

`Test suite failed to run

Jest encountered an unexpected token

Jest failed to parse a file. This happens e.g. when your code or its dependencies use non-standard JavaScript syntax, or when Jest is not configured to support such syntax.

Out of the box Jest supports Babel, which will be used to transform your files into valid JS based on your Babel configuration.

By default "node_modules" folder is ignored by transformers.

Here's what you can do:
 • If you are trying to use ECMAScript Modules, see https://jestjs.io/docs/ecmascript-modules for how to enable it.
 • If you are trying to use TypeScript, see https://jestjs.io/docs/getting-started#using-typescript
 • To have some of your "node_modules" files transformed, you can specify a custom "transformIgnorePatterns" in your config.
 • If you need a custom transformation specify a "transform" option in your config.
 • If you simply want to mock your non-JS modules (e.g. binary assets) you can stub them out with the "moduleNameMapper" config option.

You'll find more details and examples of these config options in the docs:
https://jestjs.io/docs/configuration
For information about custom transformations, see:
https://jestjs.io/docs/code-transformation

Details:

C:\Repos\wb-vue\node_modules\plur\index.js:1
({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,jest){import irregularPlurals from 'irregular-plurals';
                                                                                  ^^^^^^

SyntaxError: Cannot use import statement outside a module

> 1 | import plur from 'plur'
    | ^
  2 | 
  3 |
  4 | import EpmlFnReturnType from '../classes/EpmlFnReturnType'

  at Runtime.createScriptFromCode (node_modules/jest-runtime/build/index.js:1728:14)
  at Object.<anonymous> (src/plugins/epml-interpreter/epml/plural.js:1:1)
  at Object.<anonymous> (tests/unit/src/plugins/epml-interpreter/epml/plural.test.js:2:1)
  at TestScheduler.scheduleTests (node_modules/@jest/core/build/TestScheduler.js:333:13)
  at runJest (node_modules/@jest/core/build/runJest.js:404:19)
  at _run10000 (node_modules/@jest/core/build/cli/index.js:320:7)
  at runCLI (node_modules/@jest/core/build/cli/index.js:173:3)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.