@@ -377,6 +377,7 @@ const regex = {
377377 tium : new RegExp ( '([ti])um$' , 'gi' ) ,
378378 sis : new RegExp ( 'sis$' , 'gi' ) ,
379379 ffe : new RegExp ( '(?:([^f])fe|([lr])f)$' , 'gi' ) ,
380+ focus : new RegExp ( '^(focus)$' , 'gi' ) ,
380381 hive : new RegExp ( '(hi|ti)ve$' , 'gi' ) ,
381382 aeiouyy : new RegExp ( '([^aeiouy]|qu)y$' , 'gi' ) ,
382383 x : new RegExp ( '(x|ch|ss|sh)$' , 'gi' ) ,
@@ -443,6 +444,7 @@ const pluralRules = [
443444 [ regex . singular . tium , '$1a' ] ,
444445 [ regex . singular . sis , 'ses' ] ,
445446 [ regex . singular . ffe , '$1$2ves' ] ,
447+ [ regex . singular . focus , '$1es' ] ,
446448 [ regex . singular . hive , '$1ves' ] ,
447449 [ regex . singular . aeiouyy , '$1ies' ] ,
448450 [ regex . singular . matrix , '$1ices' ] ,
@@ -478,6 +480,7 @@ const singularRules = [
478480 [ regex . singular . tium ] ,
479481 [ regex . singular . sis ] ,
480482 [ regex . singular . ffe ] ,
483+ [ regex . singular . focus ] ,
481484 [ regex . singular . hive ] ,
482485 [ regex . singular . aeiouyy ] ,
483486 [ regex . singular . x ] ,
@@ -574,17 +577,22 @@ const underbarPrefix = new RegExp('^_');
574577 *
575578 * applyRules( 'cows', singular_rules ); // === 'cow'
576579 */
577- function applyRules ( str , rules , skip ) {
578- if ( skip . includes ( str . toLocaleLowerCase ( ) ) ) {
579- return str ;
580+ function applyRules ( str , rules , skip , override ) {
581+ if ( override ) {
582+ return override ;
580583 }
581- for ( const rule of rules ) {
582- if ( str . match ( rule [ 0 ] ) ) {
583- if ( rule [ 1 ] !== undefined ) {
584- return str . replace ( rule [ 0 ] , rule [ 1 ] ) ;
585- }
584+ else {
585+ if ( skip . includes ( str . toLocaleLowerCase ( ) ) ) {
586586 return str ;
587587 }
588+ for ( const rule of rules ) {
589+ if ( str . match ( rule [ 0 ] ) ) {
590+ if ( rule [ 1 ] !== undefined ) {
591+ return str . replace ( rule [ 0 ] , rule [ 1 ] ) ;
592+ }
593+ return str ;
594+ }
595+ }
588596 }
589597 return str ;
590598}
@@ -600,9 +608,10 @@ function applyRules(str, rules, skip) {
600608 * inflection.pluralize( 'person' ); // === 'people'
601609 * inflection.pluralize( 'octopus' ); // === 'octopuses'
602610 * inflection.pluralize( 'Hat' ); // === 'Hats'
611+ * inflection.pluralize( 'person', 'guys' ); // === 'guys'
603612 */
604- function pluralize ( str ) {
605- return applyRules ( str , pluralRules , uncountableWords ) ;
613+ function pluralize ( str , plural ) {
614+ return applyRules ( str , pluralRules , uncountableWords , plural ) ;
606615}
607616/**
608617 * This function adds singularization support to every String object.
@@ -616,9 +625,10 @@ function pluralize(str) {
616625 * inflection.singularize( 'people' ); // === 'person'
617626 * inflection.singularize( 'octopuses' ); // === 'octopus'
618627 * inflection.singularize( 'Hats' ); // === 'Hat'
628+ * inflection.singularize( 'guys', 'person' ); // === 'person'
619629 */
620- function singularize ( str ) {
621- return applyRules ( str , singularRules , uncountableWords ) ;
630+ function singularize ( str , singular ) {
631+ return applyRules ( str , singularRules , uncountableWords , singular ) ;
622632}
623633/**
624634 * This function will pluralize or singularlize a String appropriately based on a number value
@@ -639,15 +649,16 @@ function singularize(str) {
639649 * inflection.inflect( 'person', 2 ); // === 'people'
640650 * inflection.inflect( 'octopus', 2 ); // === 'octopuses'
641651 * inflection.inflect( 'Hat', 2 ); // === 'Hats'
652+ * inflection.inflect( 'person', 2, null, 'guys' ); // === 'guys'
642653 */
643- function inflect ( str , count ) {
654+ function inflect ( str , count , singular , plural ) {
644655 if ( isNaN ( count ) )
645656 return str ;
646657 if ( count === 1 ) {
647- return applyRules ( str , singularRules , uncountableWords ) ;
658+ return applyRules ( str , singularRules , uncountableWords , singular ) ;
648659 }
649660 else {
650- return applyRules ( str , pluralRules , uncountableWords ) ;
661+ return applyRules ( str , pluralRules , uncountableWords , plural ) ;
651662 }
652663}
653664/**
0 commit comments