Skip to content

Commit 41058ee

Browse files
authored
Merge pull request #86 from bijx/bijx/inflect-float-improvement
2 parents 0aaa8d7 + 4be097f commit 41058ee

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

lib/inflection.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -699,7 +699,7 @@
699699

700700

701701
/**
702-
* This function will pluralize or singularlize a String appropriately based on an integer value
702+
* This function will pluralize or singularlize a String appropriately based on a number value
703703
* @public
704704
* @function
705705
* @param {String} str The subject string.
@@ -715,20 +715,21 @@
715715
* inflection.inflect( 'octopuses' 1 ); // === 'octopus'
716716
* inflection.inflect( 'Hats' 1 ); // === 'Hat'
717717
* inflection.inflect( 'guys', 1 , 'person' ); // === 'person'
718+
* inflection.inflect( 'inches', 1.5 ); // === 'inches'
718719
* inflection.inflect( 'person', 2 ); // === 'people'
719720
* inflection.inflect( 'octopus', 2 ); // === 'octopuses'
720721
* inflection.inflect( 'Hat', 2 ); // === 'Hats'
721722
* inflection.inflect( 'person', 2, null, 'guys' ); // === 'guys'
722723
*/
723724
inflect : function ( str, count, singular, plural ){
724-
count = parseInt( count, 10 );
725+
count = parseFloat( count, 10 );
725726

726727
if( isNaN( count )) return str;
727728

728-
if( count === 0 || count > 1 ){
729-
return inflector._apply_rules( str, plural_rules, uncountable_words, plural );
730-
}else{
729+
if( count === 1 ){
731730
return inflector._apply_rules( str, singular_rules, uncountable_words, singular );
731+
}else{
732+
return inflector._apply_rules( str, plural_rules, uncountable_words, plural );
732733
}
733734
},
734735

test/inflection.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,9 @@ describe( 'test .inflect', function (){
150150
inflection.inflect( 'original', 'not a number' ).should.equal( 'original' );
151151
inflection.inflect( 'drive', 1 ).should.equal( 'drive' );
152152
inflection.inflect( 'drives', 1 ).should.equal( 'drive' );
153+
// decimal numbers should use plural state
154+
inflection.inflect( 'inches', 1.5 ).should.equal( 'inches' );
155+
inflection.inflect( 'inches', 1.0 ).should.equal( 'inch' );
153156
});
154157
});
155158

0 commit comments

Comments
 (0)