oniguruma-to-js
Covert Oniguruma-flavor Regexp to JavaScript native RegExp
Last updated 3 months ago by antfu .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ npm install oniguruma-to-js 
SYNC missed versions from official npm registry.

oniguruma-to-js

npm version npm downloads bundle JSDocs License

Convert Oniguruma-flavor Regexp to JavaScript native RegExp.

Supported Oniguruma features:

  • [:alnum:], [:alpha:] etc. POSIX bracket expressions
  • (?x) extended, free-spacing mode
  • (?i:..) flags modifiers
  • (?>..) atomic group via regex
  • ..*+ possessive quantifiers via regex
  • \h \H hex digit shorthands
  • \p{Blank} \p{Print} etc. Oniguruma-flavored unicode property escapes

Usage

npm i oniguruma-to-js
import { onigurumaToRegexp } from 'oniguruma-to-js'

const re = onigurumaToRegexp(`[[:alnum:]_]+`)
console.log(re) // /^[a-zA-Z0-9_]+$/
import { construct, syntaxLowering } from 'oniguruma-to-js'

const pattern = syntaxLowering(`(?x:
  \d+    # Match one or more digits
  \s*    # Match zero or more whitespace characters
  [A-Z]+ # Match one or more uppercase letters
)`)
console.log(pattern) // "\d+\s*[A-Z]+"

const re = construct(pattern)
console.log(re) // /\d+\s*[A-Z]+/

Additional Features

Lowering TextMate Grammar

Traverse all the regex patterns in a TextMate grammar, and apply syntaxLowering to lower the syntax.

import { loweringTextmateGrammar } from 'oniguruma-to-js/textmate'
import grammar from '../path/to/grammars/json.json'

const lowered = loweringTextmateGrammar(grammar)

Note this function will not guarantee the correctness of the result, you may need to verify the result manually.

Sponsors

License

MIT License © 2024-PRESENT Anthony Fu

Current Tags

  • 0.4.3                                ...           latest (3 months ago)

17 Versions

  • 0.4.3                                ...           3 months ago
  • 0.4.2                                ...           3 months ago
  • 0.4.1                                ...           3 months ago
  • 0.4.0                                ...           3 months ago
  • 0.3.3                                ...           4 months ago
  • 0.3.2                                ...           4 months ago
  • 0.3.1                                ...           4 months ago
  • 0.3.0                                ...           4 months ago
  • 0.2.5                                ...           4 months ago
  • 0.2.4                                ...           4 months ago
  • 0.2.3                                ...           4 months ago
  • 0.2.2                                ...           4 months ago
  • 0.2.1                                ...           4 months ago
  • 0.2.0                                ...           4 months ago
  • 0.1.2                                ...           4 months ago
  • 0.1.1                                ...           4 months ago
  • 0.1.0                                ...           4 months ago
Maintainers (1)
Downloads
Total 17
Today 0
This Week 0
This Month 17
Last Day 0
Last Week 17
Last Month 0
Dependencies (1)
Dev Dependencies (19)

© 2010 - cnpmjs.org x YWFE | Home | YWFE