A curated drawer of JavaScript string and text-processing utilities, grouped by the job they do.
Fuzzy matching & similarity
Search & match
| Resource | Why it is useful |
|---|
| nlp-pattern-match | Pattern-based find and replace over natural language. |
| sql-string-search | Search for SQL-like queries in code via AST. |
| js-search | Client-side full-text search over a collection of objects. |
Search & replace
| Resource | Why it is useful |
|---|
| easy-replace | Replace strings without writing regexes. |
| string-apostrophes | HTML-entities-aware tool to typographically correct apostrophes and single/double quotes. |
Diffing
| Resource | Why it is useful |
|---|
| striff | Very simple string diffing. |
Casing
| Resource | Why it is useful |
|---|
| case-anything | Convert between camelCase, kebab-case, snake_case, and more. |
| Resource | Why it is useful |
|---|
| wordwrapjs | Word-wrap text to a given width. |
| splitTitle | Split titles into balanced lines for nicer wrapping. |
| commafy-anything | Add thousands separators to any number string. |
| node-ts-dedent | Strip leading indentation from template literals. |
| common-tags | Many template tags for formatting interpolated strings. |
Unicode & emoji
| Resource | Why it is useful |
|---|
| unistring | Unicode-aware emoji and text utilities. |
| emoji-regex | Regex that matches all emoji as defined by Unicode. |
Validation
| Resource | Why it is useful |
|---|
| allowed-characters | Check if a string only contains an allowed character set. |
Hashing
| Resource | Why it is useful |
|---|
| djb2a | Fast non-cryptographic hash function. |
Splitting
A small escape-aware split helper that ignores separators prefixed with \\ (used by get/set/has utilities):
/**
* Splits a string with the given separator, unless the separator
* is escaped with `\\`. Used by the get, set, has, and hasOwn utils.
* @param {String} str The string to split.
* @param {String} sep Separator, `.` by default.
* @return {Array}
*/
const split = exports.split = (str, sep = '.') => {
let segs = str.split(sep)
for (let i = 0; i < segs.length; i++) {
while (segs[i] && segs[i].slice(-1) === '\\') {
segs[i] = segs[i].slice(0, -1) + sep + segs.splice(i + 1, 1)
}
}
return segs
}