Skip to content

Commit

Permalink
Merge c7118c5 into abb3991
Browse files Browse the repository at this point in the history
  • Loading branch information
AwesomeBobX64 committed Aug 28, 2019
2 parents abb3991 + c7118c5 commit c8a8848
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 0 deletions.
6 changes: 6 additions & 0 deletions Readme.md
Expand Up @@ -81,6 +81,12 @@ pluralize.plural('paper') //=> "paper"
// Example of asking whether a word looks singular or plural:
pluralize.isPlural('test') //=> false
pluralize.isSingular('test') //=> true

// Example of making a word possessive, handling plural cases:
pluralize.posessive('Bob') // => "Bob's"
pluralize.posessive('sheep') // => "sheep's"
pluralize.posessive('dress') // => "dress's"
pluralize.posessive('dresses') // => "dresses'"
```

## License
Expand Down
15 changes: 15 additions & 0 deletions pluralize.js
Expand Up @@ -179,6 +179,21 @@
return (inclusive ? count + ' ' : '') + pluralized;
}

/**
* Make a word posessive handling plurals properly.
*
* @type {Function}
*/
pluralize.possessive = function (word) {
var possessiveWord = word + "'s";

if (word.endsWith('s') && pluralize.isPlural(word)) {
possessiveWord = possessiveWord.slice(0, -1); // Drop the "s"
}

return possessiveWord;
};

/**
* Pluralize a word.
*
Expand Down
18 changes: 18 additions & 0 deletions test.js
Expand Up @@ -702,6 +702,16 @@ var PLURAL_TESTS = [
['passerby', 'passersby']
];

var POSESSIVE_TESTS = [
['Bob', "Bob's"],
['dress', "dress's"],
['dresses', "dresses'"],
['whisky', "whisky's"],
['whiskies', "whiskies'"],
['sheep', "sheep's"],
['christmas', "christmas's"]
];

/**
* Test suite.
*/
Expand Down Expand Up @@ -738,6 +748,14 @@ describe('pluralize', function () {
});
});
});

describe('possessive', function () {
POSESSIVE_TESTS.forEach(function (test) {
it(test[0] + ' -> ' + test[1], function () {
expect(pluralize.possessive(test[0])).to.equal(test[1]);
});
});
});
});

describe('automatically convert', function () {
Expand Down

0 comments on commit c8a8848

Please sign in to comment.