From e90bfb75aa65fdccf859369455c76f8318b92913 Mon Sep 17 00:00:00 2001 From: Patrick Date: Sat, 16 Dec 2023 10:01:04 +0100 Subject: [PATCH] chore: build --- lib/inflection.d.ts | 9 +++------ lib/inflection.js | 38 +++++++++++++++----------------------- 2 files changed, 18 insertions(+), 29 deletions(-) diff --git a/lib/inflection.d.ts b/lib/inflection.d.ts index 995628a..ff05b6e 100644 --- a/lib/inflection.d.ts +++ b/lib/inflection.d.ts @@ -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. @@ -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. @@ -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. diff --git a/lib/inflection.js b/lib/inflection.js index 2d3cf68..8d97571 100644 --- a/lib/inflection.js +++ b/lib/inflection.js @@ -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; @@ -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; /** @@ -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; /** @@ -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;