0.2.1 • Published 2 months ago

@stdlib/regexp-to-json v0.2.1

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
2 months ago

regexp2json

NPM version Build Status Coverage Status

Return a JSON representation of a regular expression.

Installation

npm install @stdlib/regexp-to-json

Usage

var regexp2json = require( '@stdlib/regexp-to-json' );

regexp2json( regexp )

Returns a JSON representation of a regular expression.

var json = regexp2json( /ab+c/ );
/* returns
    {
        'type': 'RegExp',
        'pattern': 'ab+c',
        'flags': ''
    }
*/

The returned object has the following properties:

  • type: value type. The assigned value is always 'RegExp'.
  • pattern: regular expression pattern.
  • flags: regular expression flags.

Examples

var regexp2json = require( '@stdlib/regexp-to-json' );

var out = regexp2json( /.*/ );
/* returns
    {
        'type': 'RegExp',
        'pattern': '.*',
        'flags': ''
    }
*/

out = regexp2json( /ab+c/g );
/* returns
    {
        'type': 'RegExp',
        'pattern': 'ab+c',
        'flags': 'g'
    }
*/

See Also


Notice

This package is part of stdlib, a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more.

For more information on the project, filing bug reports and feature requests, and guidance on how to develop stdlib, see the main project repository.

Community

Chat


License

See LICENSE.

Copyright

Copyright © 2016-2024. The Stdlib Authors.