Coder Social home page Coder Social logo

wallasfmorais / js-diacritic-regex Goto Github PK

View Code? Open in Web Editor NEW

This project forked from pocesar/js-diacritic-regex

0.0 1.0 0.0 8 KB

Creates the inverse of transliterated string to a regex. What? Basically, diacritic insensitiveness

License: MIT License

JavaScript 68.22% TypeScript 31.78%

js-diacritic-regex's Introduction

Build Status Coverage Status

NPM

Diacritic regex

Creates the inverse of transliterated string to a regex. What? Basically, a regex that is diacritic insensitive

Why?

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.

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?

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+'

Compatibility

Work in node and the browser, but needs polyfills for Array.reduce, Array.map and Object.keys

License

MIT

js-diacritic-regex's People

Contributors

pocesar avatar

Watchers

Wallas F Morais avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.