Elementals.js

Latest Version: 3.0 RC 1 17 July 2017

Method _.normalize

Summary:

Turns the passed variable into an empty string if the type is undefined, otherwise typecasts to string and trims off leading/trailing whitespace.

This is useful for cases where you are unsure of the variable's content where passing to String doesn't handle null or undefined as desired such as in sorting comparisons. Used internally several times in the elementals.js codebase.

Calling Convention:
_.normalize(stringish[, toLowerCase])
Parameters:
stringish
The variable to typecast to string and trim.
toLowerCase Optional
If "loose" true, the string will be in all lower case. Otherwise it is left alone.
Returns:
The "normalized" string. If the variable is null, undefined, or otherwise unable to be converted to string, an empty string is returned with no errors.

Example

JavaScript

Console.log(_.normalize(' this is a test '));

Will output the string with the leading/trailing whitespace removed from it.