Skip to content

Commit

Permalink
chore: build
Browse files Browse the repository at this point in the history
  • Loading branch information
p-kuen committed Dec 16, 2023
1 parent e16b411 commit e90bfb7
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 29 deletions.
9 changes: 3 additions & 6 deletions lib/inflection.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,8 @@
* inflection.pluralize( 'person' ); // === 'people'
* inflection.pluralize( 'octopus' ); // === 'octopuses'
* inflection.pluralize( 'Hat' ); // === 'Hats'
* inflection.pluralize( 'person', 'guys' ); // === 'guys'
*/
export declare function pluralize(str: string, plural?: string): string;
export declare function pluralize(str: string): string;
/**
* This function adds singularization support to every String object.
* @param str The subject string.
Expand All @@ -33,9 +32,8 @@ export declare function pluralize(str: string, plural?: string): string;
* inflection.singularize( 'people' ); // === 'person'
* inflection.singularize( 'octopuses' ); // === 'octopus'
* inflection.singularize( 'Hats' ); // === 'Hat'
* inflection.singularize( 'guys', 'person' ); // === 'person'
*/
export declare function singularize(str: string, singular?: string): string;
export declare function singularize(str: string): string;
/**
* This function will pluralize or singularlize a String appropriately based on a number value
* @param str The subject string.
Expand All @@ -55,9 +53,8 @@ export declare function singularize(str: string, singular?: string): string;
* inflection.inflect( 'person', 2 ); // === 'people'
* inflection.inflect( 'octopus', 2 ); // === 'octopuses'
* inflection.inflect( 'Hat', 2 ); // === 'Hats'
* inflection.inflect( 'person', 2, null, 'guys' ); // === 'guys'
*/
export declare function inflect(str: string, count: number, singular?: string, plural?: string): string;
export declare function inflect(str: string, count: number): string;
/**
* This function adds camelization support to every String object.
* @param str The subject string.
Expand Down
38 changes: 15 additions & 23 deletions lib/inflection.js
Original file line number Diff line number Diff line change
Expand Up @@ -560,21 +560,16 @@ const underbarPrefix = new RegExp('^_');
*
* applyRules( 'cows', singular_rules ); // === 'cow'
*/
function applyRules(str, rules, skip, override) {
if (override) {
return override;
function applyRules(str, rules, skip) {
if (skip.includes(str.toLocaleLowerCase())) {
return str;
}
else {
if (skip.includes(str.toLocaleLowerCase())) {
return str;
}
for (const rule of rules) {
if (str.match(rule[0])) {
if (rule[1] !== undefined) {
return str.replace(rule[0], rule[1]);
}
return str;
for (const rule of rules) {
if (str.match(rule[0])) {
if (rule[1] !== undefined) {
return str.replace(rule[0], rule[1]);
}
return str;
}
}
return str;
Expand All @@ -591,10 +586,9 @@ function applyRules(str, rules, skip, override) {
* inflection.pluralize( 'person' ); // === 'people'
* inflection.pluralize( 'octopus' ); // === 'octopuses'
* inflection.pluralize( 'Hat' ); // === 'Hats'
* inflection.pluralize( 'person', 'guys' ); // === 'guys'
*/
function pluralize(str, plural) {
return applyRules(str, pluralRules, uncountableWords, plural);
function pluralize(str) {
return applyRules(str, pluralRules, uncountableWords);
}
exports.pluralize = pluralize;
/**
Expand All @@ -609,10 +603,9 @@ exports.pluralize = pluralize;
* inflection.singularize( 'people' ); // === 'person'
* inflection.singularize( 'octopuses' ); // === 'octopus'
* inflection.singularize( 'Hats' ); // === 'Hat'
* inflection.singularize( 'guys', 'person' ); // === 'person'
*/
function singularize(str, singular) {
return applyRules(str, singularRules, uncountableWords, singular);
function singularize(str) {
return applyRules(str, singularRules, uncountableWords);
}
exports.singularize = singularize;
/**
Expand All @@ -634,16 +627,15 @@ exports.singularize = singularize;
* inflection.inflect( 'person', 2 ); // === 'people'
* inflection.inflect( 'octopus', 2 ); // === 'octopuses'
* inflection.inflect( 'Hat', 2 ); // === 'Hats'
* inflection.inflect( 'person', 2, null, 'guys' ); // === 'guys'
*/
function inflect(str, count, singular, plural) {
function inflect(str, count) {
if (isNaN(count))
return str;
if (count === 1) {
return applyRules(str, singularRules, uncountableWords, singular);
return applyRules(str, singularRules, uncountableWords);
}
else {
return applyRules(str, pluralRules, uncountableWords, plural);
return applyRules(str, pluralRules, uncountableWords);
}
}
exports.inflect = inflect;
Expand Down

0 comments on commit e90bfb7

Please sign in to comment.