1.2.0 • Published 4 years ago

chocula v1.2.0

Weekly downloads
4
License
MIT
Repository
-
Last release
4 years ago

About

This are a packages for pluralize many word. Wait a seconds...

It's called that because it counts. Get it? Yeah, you get it. Anyway I hate seeing things like "You have 1 messages" so please stop doing that. Thanks.

Parameters

value can be a number or a string, I don't particularly care which. It'll work out the same either way.

capitalize is a boolean value that will capitalize the first letter of your word. Only used if you don't supply the actual word.

Some methods allow you to supply the word as a string. Others don't need that. See below for details.

Usage

chocula.s(value, 'word') Returns word or words based on the value. Starting in version 1.1.0, you can omit the word to only get back the s or an empty string, so you can place it at the end of your word, such as mon.

chocula.ies(value, 'story') Returns story or stories based on the value. Specifically for use with words that end in Y (not EY, sorry). Words that require addtional manipulation should use the custom option below. Starting in version 1.1.0, you can omit the word to only get back the ies or an y, so you can place it at the end of your words in your stor${ies(count.stories)}.

chocula.is(value, capitalize) Returns is or are based on the value.

chocula.these(value, capitalize) Returns this or these based on the value.

chocula.that(value, capitalize) Returns that or those based on the value.

chocula.them(value, capitalize) Returns it or them based on the value.

chocula.they(value, capitalize) Returns it or they based on the value.

chocula.was(value, capitalize) (added in v1.2.0) Returns was or were based on the value.

chocula.custom(value, 'singular', 'plural') Returns either your custom singular word or custom plural word. Useful if nothing else fits your usage.

Examples

For this code:

I have ${chocula.custom(value, 'a', 'some')} good ${chocula.s(value, 'reason')} for adding custom pluralizations.
I have ${chocula.custom(value, 'a', 'a few')} good ${chocula.s(value, 'idea')} about when you might want to use this.
I'm sure you will have ${chocula.custom(value, 'a', 'an awful lot of')} good ${chocula.s(value, 'reason')} for needing this at some point.
const value = 1 results in:
I have a good reason for adding custom pluralizations.
I have a good idea about when you might want to use this.
I'm sure you will have a good reason for needing this at some point.
const value = 2 results in:
I have some good reasons for adding custom pluralizations.
I have a few good ideas about when you might want to use this.
I'm sure you will have an awful lot of good reasons for needing this at some point.

The above examples work best if your value won't be zero. There are plenty of use cases where it works fine with a zero, but the above sentences are not among them. Some good uses with zero would be along the lines of:

You currently have ${value} ${chocula.s(value, 'message')}.

You can read ${chocula.them(value)} in your inbox.

You can use spaces in your plural to add an extra word:

You have selected ${value} ${chocula.s(value, 'message')}.
<button>Delete${chocula.custom(value, '', ' All')}</button>

This will render the button label as "Delete" without an extra space at the end for a single message selected or "Delete All" for multiple messages. You could also just use Delete as the singular and Delete All as the plural. Both will give the same result.

Use as many {chocula.s(countOfValues, 'value')} as you want in the same sentence.

import chocula from 'chocula';
const {these, is, custom, s} = chocula;

${these(value1, true)} ${is(value1)} ${custom(value1, 'a', 'some')} ${s(value1 'package')} for pluralizing ${custom(value2, 'a', 'many')} ${s(value2, 'word')}.

This could result in:

This is a package for pluralizing many words. (value1 = 1, value2 = 2)

This is a package for pluralizing a word. (value1 = 1, value2 = 1)

These are some packages for pluralizing a word. (value1 = 2, value2 = 1)

These are some packages for pluralizing many words. (value1 = 2, value2 = 2)

1.2.0

4 years ago

1.1.0

4 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago