Skip to content
This repository has been archived by the owner on Oct 25, 2023. It is now read-only.

Commit

Permalink
feat: export pluralize functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
imurchie committed Feb 6, 2020
1 parent 41c0c71 commit 674a9aa
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 4 deletions.
6 changes: 3 additions & 3 deletions lib/fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import which from 'which';
import glob from 'glob';
import crypto from 'crypto';
import klaw from 'klaw';
import pluralize from 'pluralize';
import { pluralize } from './util';
import log from './logger';
import Timer from './timing';

Expand Down Expand Up @@ -134,8 +134,8 @@ let fs = {
});
});
}).finally(function () {
log.debug(`Traversed ${directoryCount} ${pluralize('directory', directoryCount)} ` +
`and ${fileCount} ${pluralize('file', fileCount)} ` +
log.debug(`Traversed ${pluralize('directory', directoryCount, true)} ` +
`and ${pluralize('file', fileCount, true)} ` +
`in ${timer.getDuration().asMilliSeconds.toFixed(0)}ms`);
if (walker) {
walker.destroy();
Expand Down
14 changes: 13 additions & 1 deletion lib/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import path from 'path';
import fs from './fs';
import semver from 'semver';
import { quote as shellQuote } from 'shell-quote';
import pluralizeLib from 'pluralize';


const W3C_WEB_ELEMENT_IDENTIFIER = 'element-6066-11e4-a52e-4f735466cecf';
Expand Down Expand Up @@ -338,10 +339,21 @@ function unleakString (s) {
return ` ${s}`.substr(1);
}

/**
* Get the form of a word appropriate to the count
*
* @param {string} word - The word to pluralize
* @param {number} count - How many of the word exist
* @param {?boolean} inclusive - Whether to prefix with the number (e.g., 3 ducks)
*/
function pluralize (word, count, inclusive = false) {
return pluralizeLib(word, count, inclusive);
}

export {
hasValue, escapeSpace, escapeSpecialChars, localIp, cancellableDelay,
multiResolve, safeJsonParse, wrapElement, unwrapElement, filterObject,
toReadableSizeString, isSubPath, W3C_WEB_ELEMENT_IDENTIFIER,
isSameDestination, compareVersions, coerceVersion, quote, unleakString,
jsonStringify,
jsonStringify, pluralize,
};
14 changes: 14 additions & 0 deletions test/util-specs.js
Original file line number Diff line number Diff line change
Expand Up @@ -510,4 +510,18 @@ describe('util', function () {
}
});
});

describe('pluralize', function () {
/*
* The pluralize library (https://github.com/blakeembrey/pluralize)
* has a robust set of tests. Here we just need to verify that it
* is usable through the exported package, and the arguments are correct
*/
it('should pluralize a string', function () {
util.pluralize('word', 2).should.eql('words');
});
it('should pluralize a string and prepend the number', function () {
util.pluralize('word', 2, true).should.eql('2 words');
});
});
});

0 comments on commit 674a9aa

Please sign in to comment.