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

oniguruma-to-js

Package Overview
Dependencies
Maintainers
1
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

oniguruma-to-js

Covert Oniguruma-flavor Regexp to JavaScript native RegExp

  • 0.4.3
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
529K
decreased by-15.52%
Maintainers
1
Weekly downloads
 
Created
Source

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

Keywords

FAQs

Package last updated on 13 Sep 2024

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