Mangler.tokenize() - DarthJDG/Mangler.js GitHub Wiki
Break down an identifier name to an array of words.
Mangler.tokenize(string[, from])| Parameter | Type | Default | Description |
|---|---|---|---|
| string | String Array.String |
A string with the identifier name to break down. If an array is passed, it is returned as is. | |
| from | String | 'auto' |
Explicit case to convert from:
|
Returns a list of words in an array of strings.
This function is used internally by Mangler.transform(). The 'lower_' and 'upper_' options were included for completeness to support the same parameters as Mangler.transform(), they work the same way as '_'. Similarly, both 'camel' and 'title' finds word boundaries the same way.
If there are any underscores in string, it will be treated as snake case. Otherwise, it will try to find word boundaries by looking at switches between numbers and uppercase and lowercase letters. This means that if you mix camel/title case with underscores, your camel/title case parts will be treated as a single word.
Mangler.tokenize('some_id'); // = ['some', 'id']
Mangler.tokenize('camelCaseId2'); // = ['camel', 'Case', 'Id', '2']
Mangler.tokenize('DontMess_WithTheSnake'); // = ['DontMess', 'WithTheSnake']
Mangler.tokenize('any.path.string[0]', 'path'); // = ['any', 'path', 'string', '0']You can also use a custom single-character delimiter in place of an underscore in '_', 'lower_' and 'upper_':
Mangler.tokenize('hash#delimited#string', '#'); // = ['hash', 'delimited', 'string']