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:
- 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.
- 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.
Console.log(_.normalize(' this is a test '));
Will output the string with the leading/trailing whitespace removed from it.