Trimming and substring functions
Trimming white-space from strings is made simple with using the rtrim, ltrim, and trim functions inside Jel.String:
While JavaScript has two functions to extract substrings (substr, and substring), it doesn't have any convenient ways to get a certain number of characters from the left or right of a string. Jel makes this easy:
And that about covers that really. Simple but useful functions, that are strangely absent from the core of many languages.
Comparison functions
Jel.String has a number of similarly useful and easy to understand comparison functions: equals, startsWith, and endsWith. These
functions have the extra benefit of being able to ignore case too:
Converting between variable naming standards
Naming standards for XHTML class and id attributes can vary a lot between developers and teams. When delimiting separate words in a class or id string, there common standards to adhere to are:
- camel case - the first word is lower case, with additional words having their first letter as uppercase - e.g. camelCase, containerField
- dash delimited - all letters are lower case, with each word being separated by a dash - e.g. dash-delimited, container-field
- underscore delimited - all letters are lower case, with each word being separated by an underscore - e.g. underscore_delimited, container_field
To convert between these naming standards, Jel.String has the functions normalize, camelize, and decamelize. normalize acts as a bridge
between these naming standards, by converting any of the above naming standards, or even a mixture of them in one string, into the dash delimited version:
Once you have a normlized string, it's trivial to convert into any of the other standards:
Finally, decamelize does the opposite of camelize, breaking up a camel case word into delimited words with a delimiter of your choice (default dash "-"):
Integer extraction
The built-in JavaScript function parseInt is a handy function at times, but not so good when you know a number exists somewhere in the middle or end of a string. In those cases parseInt returns "NaN", as shown below:
The Jel.String.extractInt function is designed to solve this problem, and can even return the resulting integer if numbers are not contiguous in the string:
Language Specific Functions
The English-language builds of JEL contain a few extra nuggets in Jel.String for constructing sentences: an and plural.
More information
All functions discussed here (and a few more) are detailed in the API documentation for Jel.String.