1.5.0 • Published 1 year ago

regexies v1.5.0

Weekly downloads
8
License
MIT
Repository
github
Last release
1 year ago

Regexies

The library includes a list of popular regex functions for every project usage. You can use special builder functions to create your own regexes.

Please let us know if you see any bugs or need improvements to existing functions. Thank you!

Install

Install using npm:

npm i regexies

Import

Node.js

const regexies = require('regexies');
regexies.isPassword('sometestpassword');
// or
const isPassword = require('regexies').isPassword;

ES6

import regexies from 'regexies';
regexies.isPassword('sometestpassword');
// or
import { isPassword } from 'regexies';

Optimization

Import only functions you need to reduce bundle size.

// Node.js
const isPassword = require('regexies/src/isPassword');
// ES6
import isPassword from 'regexies/src/isPassword';

Use with babel-plugin-import:

{
  "libraryName": "regexies",
  "libraryDirectory": "src",
}

Documentation

Visit Regexies documentation on Github Pages to get full information about all available functions with examples and test tools.

Build your own regex using these functions:

  • is
  • createIs - create your own regex using our regex constructor

Escape special characters using these functions:

Verify strings using these functions:

escape

Use this function to escape special characters that should be escaped in Regex. The function decides which helper function to use escapeShort or escapeLong depends on length of the string.

/**
 * @param  {String} string String to escape
 */
escape(string) // .^$*+?()[]{}\|/- to \.\^\$\*\+\?\(\)\[\]\{\}\\\|\/\-

escapeShort and escapeLong

Use escapeShort to escape strings with length <= 60 and escapeLong for strings longer than 60 symbols.

/**
 * @param  {String} string String to escape
 */
escapeShort(string) // custom function with for loop
escapeLong(string)  // string.replace(/[\.\^\$\*\+\?\(\)\[\]\{\}\\\|\/\-]/g, '\\$&');

There is no big difference if you want to escape single string, but if your task requires hundrets of iteration then the impact could be significant. Let's take a look at table with performance results:
| String length | Iterations | escapeShort | escapeLong | | ------------- | ------------- | ------------- | ------------- | | 20 | 10k | 7ms | 7ms | | 20 | 100k | 30ms | 56ms | | 50 | 10k | 7ms | 10ms | | 50 | 100k | 73ms | 100ms | | 100 | 10k | 13ms | 11ms | | 100 | 100k | 133ms | 102ms | | 1000 | 10k | 134ms | 73ms | | 1000 | 100k | 1315ms | 732ms |

Tests

Tests are not included in regexies library if you install it through npm. Please clone git repo of the library to find tests.

1.5.0

1 year ago

1.4.0

3 years ago

1.3.2

3 years ago

1.3.1

3 years ago

1.3.0

3 years ago

1.2.0

3 years ago

1.1.2

3 years ago

1.1.1

3 years ago

1.1.0

3 years ago

1.0.6

3 years ago

1.0.5

4 years ago

1.0.4

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago