Package Exports
- regexator
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (regexator) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
Regexator
Creates the inverse of transliterated string to a regex. What? Basically, a regex that is diacritic insensitive
Why?
Sometimes you are looking for déja vu, but your database is dumb and doesn't understand collations and diacritic insensitiveness, but it can compare stuff using regex, so there ya go.
How?
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? In the same way, you're looking for Charles de Gaulle or Dont'a Hightower but you can't remember where the spaces are. You'll be able to find them even if you're looking for Charles degaulle or Donta Hightower
The optional 'strong' option converts all characters, including consonants.
The optional 'spaces' option includes a space or a dash(-) or a single quotation mark (') between each characters
import { stringToRegex } from 'regexator';
stringToRegex()('résumé'); // => /r[eEÉéÈèÊêëË]s[úùÚÙüÜuU]m[eEÉéÈèÊêëË]/i;
stringToRegex({ flags: 'mu' })('résumé'); // => /r[eEÉéÈèÊêëË]s[úùÚÙüÜuU]m[eEÉéÈèÊêëË]/mu;
stringToRegex({
flags: '',
mappings: {
e: 'eéÉ',
},
})('résumé'); // => /r[eéÉ]s[úùÚÙüÜuU]m[eéÉ]/;
stringToRegex({ strong: true })('résumé'); // => /[RrŔŕŖŗŘřȐȑȒȓṘṙṚṛṜṝṞṟ][EeÈèÉéÊêËëĒēĔĕĖėĘęĚěȄȅȆȇȨȩḔḕḖḗḘḙḚḛḜḝẸẹẺẻẼẽẾếỀềỂểỄễỆệ][SsŚśŜŝŞşŠšȘșṠṡṢṣṤṥṦṧṨṩ][UuÙùÚúÛûÜüŨũŪūŬŭŮůŰűŲųǓǔǕǖǗǘǙǚǛǜȔȕȖȗṲṳṴṵṶṷṸṹṺṻỤụỦủỨứỪừỬửỮữỰự][MmḾḿṀṁṂṃ][EeÈèÉéÊêËëĒēĔĕĖėĘęĚěȄȅȆȇȨȩḔḕḖḗḘḙḚḛḜḝẸẹẺẻẼẽẾếỀềỂểỄễỆệ]/i
stringToRegex({ spaces: true })('résumé'); // => /r(?:\s|'|-)*[EeÈèÉéÊêËë](?:\s|'|-)*s(?:\s|'|-)*[UuÙùÚúÛûÜü](?:\s|'|-)*m(?:\s|'|-)*[EeÈèÉéÊêËë]/i
stringToRegex({ spaces: true, strong: true })('résumé'); // => /[RrŔŕŖŗŘřȐȑȒȓṘṙṚṛṜṝṞṟ](?:\s|'|-)*[EeÈèÉéÊêËëĒēĔĕĖėĘęĚěȄȅȆȇȨȩḔḕḖḗḘḙḚḛḜḝẸẹẺẻẼẽẾếỀềỂểỄễỆệ](?:\[SsŚśŜŝŞşŠšȘșṠṡṢṣṤṥṦṧṨṩ]|'|-)*[SsŚśŜŝŞşŠšȘșṠṡṢṣṤṥṦṧṨṩ](?:\[SsŚśŜŝŞşŠšȘșṠṡṢṣṤṥṦṧṨṩ]|'|-)*[UuÙùÚúÛûÜüŨũŪūŬŭŮůŰűŲųǓǔǕǖǗǘǙǚǛǜȔȕȖȗṲṳṴṵṶṷṸṹṺṻỤụỦủỨứỪừỬửỮữỰự](?:\[SsŚśŜŝŞşŠšȘșṠṡṢṣṤṥṦṧṨṩ]|'|-)*[MmḾḿṀṁṂṃ](?:\[SsŚśŜŝŞşŠšȘșṠṡṢṣṤṥṦṧṨṩ]|'|-)*[EeÈèÉéÊêËëĒēĔĕĖėĘęĚěȄȅȆȇȨȩḔḕḖḗḘḙḚḛḜḝẸẹẺẻẼẽẾếỀềỂểỄễỆệ]/iIf you want to change the mappings for all instances:
import { charCodes } from 'regexator';
mappings['*'] = ['[\\S\\s]+'];Caveats
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
Compatibility
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
License
MIT