pax_global_header00006660000000000000000000000064136222413610014512gustar00rootroot0000000000000052 comment=46dbbec082bae1b0551168f5fe8fc917d7ba9d2f plur-4.0.0/000077500000000000000000000000001362224136100124755ustar00rootroot00000000000000plur-4.0.0/.editorconfig000066400000000000000000000002571362224136100151560ustar00rootroot00000000000000root = true [*] indent_style = tab end_of_line = lf charset = utf-8 trim_trailing_whitespace = true insert_final_newline = true [*.yml] indent_style = space indent_size = 2 plur-4.0.0/.gitattributes000066400000000000000000000000231362224136100153630ustar00rootroot00000000000000* text=auto eol=lf plur-4.0.0/.github/000077500000000000000000000000001362224136100140355ustar00rootroot00000000000000plur-4.0.0/.github/funding.yml000066400000000000000000000001331362224136100162070ustar00rootroot00000000000000github: sindresorhus open_collective: sindresorhus custom: https://sindresorhus.com/donate plur-4.0.0/.gitignore000066400000000000000000000000271362224136100144640ustar00rootroot00000000000000node_modules yarn.lock plur-4.0.0/.npmrc000066400000000000000000000000231362224136100136100ustar00rootroot00000000000000package-lock=false plur-4.0.0/.travis.yml000066400000000000000000000000551362224136100146060ustar00rootroot00000000000000language: node_js node_js: - '12' - '10' plur-4.0.0/index.d.ts000066400000000000000000000020301362224136100143710ustar00rootroot00000000000000/** Pluralize a word. @param word - Word to pluralize. @param plural - 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. Default: - Irregular nouns will use this [list](https://github.com/sindresorhus/irregular-plurals/blob/master/irregular-plurals.json). - 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*). @param count - Count to determine whether to use singular or plural. @example ``` import plur = require('plur'); plur('unicorn', 4); //=> 'unicorns' plur('puppy', 2); //=> 'puppies' plur('box', 2); //=> 'boxes' plur('cactus', 2); //=> 'cacti' ``` */ declare function plur(word: string, count: number): string; declare function plur(word: string, plural: string, count: number): string; export = plur; plur-4.0.0/index.js000066400000000000000000000017351362224136100141500ustar00rootroot00000000000000'use strict'; const irregularPlurals = require('irregular-plurals'); module.exports = (word, plural, count) => { if (typeof plural === 'number') { count = plural; } if (irregularPlurals.has(word.toLowerCase())) { plural = irregularPlurals.get(word.toLowerCase()); const firstLetter = word.charAt(0); const isFirstLetterUpperCase = firstLetter === firstLetter.toUpperCase(); if (isFirstLetterUpperCase) { plural = firstLetter.toUpperCase() + plural.slice(1); } const isWholeWordUpperCase = word === word.toUpperCase(); if (isWholeWordUpperCase) { plural = plural.toUpperCase(); } } else if (typeof plural !== 'string') { plural = (word.replace(/(?:s|x|z|ch|sh)$/i, '$&e').replace(/([^aeiou])y$/i, '$1ie') + 's') .replace(/i?e?s$/i, match => { const isTailLowerCase = word.slice(-1) === word.slice(-1).toLowerCase(); return isTailLowerCase ? match.toLowerCase() : match.toUpperCase(); }); } return Math.abs(count) === 1 ? word : plural; }; plur-4.0.0/index.test-d.ts000066400000000000000000000002271362224136100153540ustar00rootroot00000000000000import {expectType} from 'tsd'; import plur = require('.'); expectType(plur('chicken', 2)); expectType(plur('chicken', 'chicks', 2)); plur-4.0.0/license000066400000000000000000000021351362224136100140430ustar00rootroot00000000000000MIT License Copyright (c) Sindre Sorhus (https://sindresorhus.com) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. plur-4.0.0/package.json000066400000000000000000000013071362224136100147640ustar00rootroot00000000000000{ "name": "plur", "version": "4.0.0", "description": "Pluralize a word", "license": "MIT", "repository": "sindresorhus/plur", "funding": "https://github.com/sponsors/sindresorhus", "author": { "name": "Sindre Sorhus", "email": "sindresorhus@gmail.com", "url": "https://sindresorhus.com" }, "engines": { "node": ">=10" }, "scripts": { "test": "xo && ava && tsd" }, "files": [ "index.js", "index.d.ts" ], "keywords": [ "plural", "plurals", "pluralize", "singular", "count", "word", "string", "irregular", "noun", "nouns" ], "dependencies": { "irregular-plurals": "^3.2.0" }, "devDependencies": { "ava": "^1.4.1", "tsd": "^0.11.0", "xo": "^0.26.1" } } plur-4.0.0/readme.md000066400000000000000000000021641362224136100142570ustar00rootroot00000000000000# plur [![Build Status](https://travis-ci.org/sindresorhus/plur.svg?branch=master)](https://travis-ci.org/sindresorhus/plur) > Pluralize a word ## Install ``` $ npm install plur ``` ## Usage ```js const plur = require('plur'); plur('unicorn', 4); //=> 'unicorns' plur('puppy', 2); //=> 'puppies' plur('box', 2); //=> 'boxes' plur('cactus', 2); //=> 'cacti' ``` ## API ### plur(word, plural?, count) #### word Type: `string` Word to pluralize. #### plural Type: `string`\ Default: - Irregular nouns will use this [list](https://github.com/sindresorhus/irregular-plurals/blob/master/irregular-plurals.json). - 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*). 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` Count to determine whether to use singular or plural. plur-4.0.0/test.js000066400000000000000000000024621362224136100140160ustar00rootroot00000000000000import test from 'ava'; import plur from '.'; test('main', t => { t.is(plur('unicorn', 0), 'unicorns'); t.is(plur('unicorn', 1), 'unicorn'); t.is(plur('unicorn', 2), 'unicorns'); t.is(plur('unicorn', 'horse', 0), 'horse'); t.is(plur('unicorn', 'horse', 1), 'unicorn'); t.is(plur('unicorn', 'horse', 2), 'horse'); t.is(plur('bus', 2), 'buses'); t.is(plur('box', 2), 'boxes'); t.is(plur('fizz', 2), 'fizzes'); t.is(plur('batch', 2), 'batches'); t.is(plur('bush', 2), 'bushes'); t.is(plur('Bush', 2), 'Bushes'); t.is(plur('guppy', 2), 'guppies'); t.is(plur('UNICORN', 2), 'UNICORNS'); t.is(plur('puppY', 2), 'puppIES'); t.is(plur('man', 2), 'men'); t.is(plur('woman', 2), 'women'); t.is(plur('fish', 2), 'fish'); t.is(plur('sheep', 2), 'sheep'); t.is(plur('tooth', 2), 'teeth'); t.is(plur('tomato', 2), 'tomatoes'); t.is(plur('wife', 2), 'wives'); t.is(plur('shelf', 2), 'shelves'); t.is(plur('day', 2), 'days'); t.is(plur('diy', 2), 'diys'); t.is(plur('child', 2), 'children'); t.is(plur('child', 1), 'child'); t.is(plur('unicorn', -1), 'unicorn'); t.is(plur('unicorn', -2), 'unicorns'); t.is(plur('shelf', 1), 'shelf'); t.is(plur('shelf', 2), 'shelves'); t.is(plur('Shelf', 1), 'Shelf'); t.is(plur('Shelf', 2), 'Shelves'); t.is(plur('SHELF', 1), 'SHELF'); t.is(plur('SHELF', 2), 'SHELVES'); });