inflection
Advanced tools
Comparing version 3.0.0 to 3.0.1
@@ -21,5 +21,4 @@ /*! | ||
* 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; | ||
/** | ||
@@ -37,5 +36,4 @@ * This function adds singularization support to every String object. | ||
* 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; | ||
/** | ||
@@ -60,5 +58,4 @@ * This function will pluralize or singularlize a String appropriately based on a number value | ||
* 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; | ||
/** | ||
@@ -65,0 +62,0 @@ * This function adds camelization support to every String object. |
@@ -11,3 +11,17 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.transform = exports.ordinalize = exports.foreignKey = exports.classify = exports.tableize = exports.demodulize = exports.titleize = exports.dasherize = exports.capitalize = exports.humanize = exports.underscore = exports.camelize = exports.inflect = exports.singularize = exports.pluralize = void 0; | ||
exports.pluralize = pluralize; | ||
exports.singularize = singularize; | ||
exports.inflect = inflect; | ||
exports.camelize = camelize; | ||
exports.underscore = underscore; | ||
exports.humanize = humanize; | ||
exports.capitalize = capitalize; | ||
exports.dasherize = dasherize; | ||
exports.titleize = titleize; | ||
exports.demodulize = demodulize; | ||
exports.tableize = tableize; | ||
exports.classify = classify; | ||
exports.foreignKey = foreignKey; | ||
exports.ordinalize = ordinalize; | ||
exports.transform = transform; | ||
/** | ||
@@ -564,18 +578,13 @@ * @description This is a list of nouns that use the same form for both singular and plural. | ||
*/ | ||
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())) { | ||
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; | ||
} | ||
} | ||
} | ||
@@ -596,8 +605,6 @@ return str; | ||
* 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; | ||
/** | ||
@@ -615,8 +622,6 @@ * This function adds singularization support to every String object. | ||
* 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; | ||
/** | ||
@@ -641,15 +646,13 @@ * This function will pluralize or singularlize a String appropriately based on a number value | ||
* 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; | ||
/** | ||
@@ -692,3 +695,2 @@ * This function adds camelization support to every String object. | ||
} | ||
exports.camelize = camelize; | ||
/** | ||
@@ -720,3 +722,2 @@ * This function adds underscore support to every String object. | ||
} | ||
exports.underscore = underscore; | ||
/** | ||
@@ -744,3 +745,2 @@ * This function adds humanize support to every String object. | ||
} | ||
exports.humanize = humanize; | ||
/** | ||
@@ -761,3 +761,2 @@ * This function adds capitalization support to every String object. | ||
} | ||
exports.capitalize = capitalize; | ||
/** | ||
@@ -777,3 +776,2 @@ * This function replaces underscores with dashes in the string. | ||
} | ||
exports.dasherize = dasherize; | ||
/** | ||
@@ -809,3 +807,2 @@ * This function adds titleize support to every String object. | ||
} | ||
exports.titleize = titleize; | ||
/** | ||
@@ -825,3 +822,2 @@ * This function adds demodulize support to every String object. | ||
} | ||
exports.demodulize = demodulize; | ||
/** | ||
@@ -842,3 +838,2 @@ * This function adds tableize support to every String object. | ||
} | ||
exports.tableize = tableize; | ||
/** | ||
@@ -859,3 +854,2 @@ * This function adds classification support to every String object. | ||
} | ||
exports.classify = classify; | ||
/** | ||
@@ -879,3 +873,2 @@ * This function adds foreign key support to every String object. | ||
} | ||
exports.foreignKey = foreignKey; | ||
/** | ||
@@ -916,3 +909,2 @@ * This function adds ordinalize support to every String object. | ||
} | ||
exports.ordinalize = ordinalize; | ||
const transformFunctions = { | ||
@@ -955,2 +947,1 @@ pluralize, | ||
} | ||
exports.transform = transform; |
{ | ||
"name": "inflection", | ||
"version": "3.0.0", | ||
"version": "3.0.1", | ||
"description": "A port of inflection-js to node.js module", | ||
@@ -95,4 +95,4 @@ "keywords": [ | ||
"devDependencies": { | ||
"typescript": "^5.2.2", | ||
"vitest": "^0.34.5" | ||
"typescript": "^5.7.2", | ||
"vitest": "^2.1.8" | ||
}, | ||
@@ -99,0 +99,0 @@ "main": "./lib/inflection.js", |
@@ -600,23 +600,14 @@ /*! | ||
*/ | ||
function applyRules( | ||
str: string, | ||
rules: [RegExp, string?][], | ||
skip: string[], | ||
override?: string | ||
) { | ||
if (override) { | ||
return override; | ||
} else { | ||
if (skip.includes(str.toLocaleLowerCase())) { | ||
return str; | ||
} | ||
function applyRules(str: string, rules: [RegExp, string?][], skip: string[]) { | ||
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]); | ||
} | ||
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; | ||
} | ||
@@ -640,6 +631,5 @@ } | ||
* inflection.pluralize( 'Hat' ); // === 'Hats' | ||
* inflection.pluralize( 'person', 'guys' ); // === 'guys' | ||
*/ | ||
export function pluralize(str: string, plural?: string) { | ||
return applyRules(str, pluralRules, uncountableWords, plural); | ||
export function pluralize(str: string) { | ||
return applyRules(str, pluralRules, uncountableWords); | ||
} | ||
@@ -659,6 +649,5 @@ | ||
* inflection.singularize( 'Hats' ); // === 'Hat' | ||
* inflection.singularize( 'guys', 'person' ); // === 'person' | ||
*/ | ||
export function singularize(str: string, singular?: string) { | ||
return applyRules(str, singularRules, uncountableWords, singular); | ||
export function singularize(str: string) { | ||
return applyRules(str, singularRules, uncountableWords); | ||
} | ||
@@ -685,16 +674,10 @@ | ||
* inflection.inflect( 'Hat', 2 ); // === 'Hats' | ||
* inflection.inflect( 'person', 2, null, 'guys' ); // === 'guys' | ||
*/ | ||
export function inflect( | ||
str: string, | ||
count: number, | ||
singular?: string, | ||
plural?: string | ||
) { | ||
export function inflect(str: string, count: number) { | ||
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); | ||
} | ||
@@ -701,0 +684,0 @@ } |
89034
2171