JSPM

regex-join

2.1.0
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 141
  • Score
    100M100P100Q85176F
  • License MIT

Merge multiple regexes and strings into one, preserving all the flags, automatically escaping the strings

Package Exports

  • regex-join
  • regex-join/index.js

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 (regex-join) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

regex-join

Merge multiple regexes and strings into one, preserving all the flags, automatically escaping the strings

Install

npm install regex-join

Usage

import regexJoin, {regexJoinWithSeparator} from 'regex-join';

// Place a dynamic string inside a regex
regexJoin(/\s*\(/, getNumber(), /\)$/g);
// => /\s*\(1234\)$/g

// Specify parts of a regex without making them unreadable with escapes
const someDomain = 'api.github.com';
regexJoin(/^/, 'https://', someDomain, /$/);
// => /^https:\/\/api\.github\.com$/

// Split long regexes into multiple lines with comments
regexJoin(
    /^https?:\/\//, // Protocol
    /[^/]+/, // Hostname
    /[^?]+/ // Pathname
);
// => /^https?:\/\/[^/]+[^?]+/

API

regexJoin(part, part[, part,...])

Merges any number of RegExp or strings into one and returns a single RegExp

part

Type: RegExp | string

regexJoinWithSeparator(separator, parts)

Same as regexJoin, but allows you to specify a separator between the parts. Note that parts is an array.

separator

Type: string

parts

Type: Array<RegExp | string>

  • delegate-it - DOM event delegation, in <1KB.
  • select-dom - Lightweight querySelector/All wrapper that outputs an Array.
  • doma - Parse an HTML string into DocumentFragment or one Element, in a few bytes.
  • Refined GitHub - Uses this module.

License

MIT © Federico Brigante