Skip to content

Pluralize function at correcting #187

@alexygreen

Description

@alexygreen

Hello,
I just detect a minor bug in your script for the "pluralize".

Numéric> 1 = Plurialize string OK
Numéric = 1 = singularize string OK
Numéric = 0 = Singlularize string KO

I thank in advance the creator of this script to modify its code.

Update if (Math.abs(count) === 1) by if (Math.abs(count) === 1 || Math.abs(count) === 0)

function pluralize(format, count) { 
        var plural = "s", singular = "";
        if (format) {                            
            format = format.replace(/(:|;|\s)/gi, "").split(/\,/);
            if (format.length === 1) { 
                plural = format[0];        
            } else {                             
                singular = format[0];    
                plural = format[1];        
            }                                       
        }                                           
        if (Math.abs(count) === 1 || Math.abs(count) === 0 ) { 
            return singular;                                                          
        } else {                                                                           
            return plural;                                                              
        }                                                                                     
    } 

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions