
Security News
TC39 Advances 11 Proposals for Math Precision, Binary APIs, and More
TC39 advances 11 JavaScript proposals, with two moving to Stage 4, bringing better math, binary APIs, and more features one step closer to the ECMAScript spec.
diacritic-regex
Advanced tools
Creates the inverse of transliterated string to a regex. What? Basically, a regex that is diacritic insensitive
Sometimes the user will search for blasé, but your database is dumb and doesn't understand collations and diacritic insensitiveness, but it can compare stuff using regex, so there ya go.
Suppose you have the word résumé but written improperly in the database as resume. The user is clever, and types it correctly into the search box. Gets nothing. How to search for all the weird cases people mistype stuff when comes to accents?
import { toRegex, toString } from 'diacritic-regex';
toRegex()('résumé') // => /r[eEÉéÈèÊêëË]s[úùÚÙüÜuU]m[eEÉéÈèÊêëË]/i;
toRegex({flags: 'mu'})('résumé') // => /r[eEÉéÈèÊêëË]s[úùÚÙüÜuU]m[eEÉéÈèÊêëË]/mu;
toRegex({
flags: '',
mappings: {
'e': 'eéÉ'
}
})('résumé') // => /r[eéÉ]s[úùÚÙüÜuU]m[eéÉ]/;
toString({
mappings: {
'*': ['\\S+'] // literals, won't try to wrap in []'s,
'u': ['u']
}
})('résumé*') // => 'r[eEÉéÈèÊêëË]sum[eEÉéÈèÊêëË]\S+'
If you want to change the mappings for all instances:
import { mappings } from 'diacritic-regex'
mappings['*'] = ['[\\S\\s]+']
Be aware of RegExp.prototype.exec with g
flag being stateful
The i
flag is appended to the RegExp flags if you don't pass any flags to toRegex
Work in node and the browser, but needs polyfills for Array.reduce
, Array.map
and Object.keys
depending on how old your target browser is
MIT
FAQs
String to a regex that is diacritic insensitive
The npm package diacritic-regex receives a total of 2,853 weekly downloads. As such, diacritic-regex popularity was classified as popular.
We found that diacritic-regex demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
TC39 advances 11 JavaScript proposals, with two moving to Stage 4, bringing better math, binary APIs, and more features one step closer to the ECMAScript spec.
Research
/Security News
A flawed sandbox in @nestjs/devtools-integration lets attackers run code on your machine via CSRF, leading to full Remote Code Execution (RCE).
Product
Customize license detection with Socket’s new license overlays: gain control, reduce noise, and handle edge cases with precision.