This module can be used to generate clean strings that can be used in URIs, etc. Its implementation is based on and intended to be used in parallel with the Drupal module pathauto‘s pathauto_cleanstring method.
Constant for remove action.
Type: string
Constant for replace action.
Type: string
Constant for do nothing action.
Type: string
Constructs a method for cleaning strings.
Note: passed in config is merged with the default config, but not recursively. Therefore, if you override one of the arrays or objects in the config you must provide all the members that you would like that array or object to contain.
Parameters
config
CleanstringConfig The config object to use for cleaning. Anything passed in here will be
merged with the default config, but not recursively, i.e. if you override
config.punctuation you will need to provide values for every punctionation
character you wish to handle. (optional, default defaultConfig
)config.case
boolean True if the generated string should be lowercased. (optional, default true
)config.ignoreWords
Array<string> The list of words to strip from the passed in string. (optional, default ['a','an','as','at','before','but','by','for','from','is','in','into','like','of','off','on','onto','per','since','than','the','this','that','to','up','via','with']
)config.maxComponentLength
int The maximum length of the resulting string. The string will be split on
boundaries so it may be shorter than this value, but will never be longer. (optional, default 100
)config.punctuation
Object The punctuation directives, each member of this object will have a value of
CLEANSTRING_REMOVE, CLEANSTRING_REPLACE, or CLEANSTRING_DONOTHING which
will determine how the characters are handled during cleaning (optional, default {
'"':CLEANSTRING_REMOVE,
"'":CLEANSTRING_REMOVE,
'`':CLEANSTRING_REMOVE,
',':CLEANSTRING_REMOVE,
'.':CLEANSTRING_REMOVE,
'-':CLEANSTRING_REMOVE,
_:CLEANSTRING_REMOVE,
':':CLEANSTRING_REMOVE,
';':CLEANSTRING_REMOVE,
'|':CLEANSTRING_REMOVE,
'{':CLEANSTRING_REMOVE,
'}':CLEANSTRING_REMOVE,
'[':CLEANSTRING_REMOVE,
']':CLEANSTRING_REMOVE,
'+':CLEANSTRING_REMOVE,
'
)config.reduceAscii
boolean True if the generated string should have all non-ascii characters removed. (optional, default false
)config.separator
string The character to use to separate words on boundaries. (optional, default '-'
)config.transliterate
boolean True if the generated string should have non-ascii characters
transliterated. (optional, default false
)Returns CleanstringCallback A function which can be used to clean strings. Accepts a string as its only parameter and will return a string cleaned according to the settings provided.
Method to clean a string according to config.
Type: Function
Parameters
string
string The string to clean.