npm install --save preserve-case
console// baz qux BAZ_QUX baz-qux bazQux baz-Qux
replace(str, query, replacement, [options])
Works exactly like
str.replace(query, replacement), except that:
- it preserves the case of what it replaces (using the marvelous
queryis a string, it matches
queryin any case. (Under the hood, it creates and uses a
queryjoined together, e.g.
str.replace(/foo bar|FOO BAR|fooBar|FooBar|.../, ...))
options.caseTypes defaults to all types built into the
This may be more than you want, so look into it. For instance, the other cases of 'foo bar' include, but may not be
'Foo Bar' 'Foo bar' 'FOO BAR' 'fooBar' 'FooBar' 'foo-bar' 'Foo-Bar' 'foo_bar' 'FOO_BAR'
replace.all(str, query, replacement, [options])
replace, this replaces all occurrences of
query, not just the first one, even if
query is a
RegExp without the
g (global) flag.
Thanks to Nathan Bubna for his
case package, which powers
RegExp that matches for any case of the given
Like the other functions,
options.caseTypes defaults to all types built into
You may also pass a
flags option for the
RegExp flags (e.g.