Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

fi-di-regex

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fi-di-regex

String to a regex that is diacritic insensitive

  • 1.0.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

Fi Di Regex

Diacritic RegExp builder.

Build a diacritic insensitive regular expression ideal to match names when making searches.

This module exists thanks to this project.

Installation

npm i fi-di-regex

Usage

const diregex = require('fi-di-regex');

const regex = diregex.build('juan', { flags: 'gi' }); // /j[uùúûü][aàáâãäå][nñńņǹ]/gi

regex.test('Juán'); // true

Options

OptionsTypeDescription
stringBooleanWhether to return a String instead of a RegExp.
upperBooleanWhether to return an uppercase String or RegExp.
lowerBooleanWhether to return a lowercase String or RegExp.
flagsStringAny valid RegExp flags.
mappingsObjectMappings to merge with the default ones. If a property with the same name of an existing mapping is passed, it will overwrite the default completely.

Use Case

Assume we are looking for an employee named Juán but the user isn't aware that computers are not diacritic insensitive.

There will be no results and this is will really annoy our user.

With this library you can create a regex that will match juan with Juán as expected by the user:

diregex.build('juan', { flags: 'gi' }); // /j[uùúûü][aàáâãäå][nñńņǹ]/gi

Our user is happy again.

A Note On Mappings

We've taken the time to map many of the diacritic equivalents on multiple letters but there may be some missing or unnecessary. If you happen to found either a missing or unnecessary mapping, then please open an issue or, better yet, open a pull request.

Every little bit counts.

Current Mappings

{
  A: 'AÀÁÂÃÄÅ',
  a: 'aàáâãäå',
  C: 'CÇĆĈČ',
  c: 'cçćĉč',
  E: 'EÈÉÊËĘĚ',
  e: 'eèéêëęě',
  I: 'IÌÍÎÏ',
  i: 'iìíîï',
  N: 'NÑŃŅǸ',
  n: 'nñńņǹ',
  O: 'OÒÓÔÕÖØ',
  o: 'oòóôõöø',
  S: 'SŚŜŞŠ',
  s: 'sśŝşš',
  U: 'UÙÚÛÜ',
  u: 'uùúûü',
  Y: 'YÝŸŶỲ',
  y: 'yýÿŷỳ',
  Z: 'ZŽ',
  z: 'zž'
}

Important

There is a bug in V8 which is not matching Ÿ with ÿ when the i flag is set.

Please see https://bugs.chromium.org/p/v8/issues/detail?id=6940 for details.

Keywords

FAQs

Package last updated on 17 Oct 2017

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc