# stupex

> A package to convert Stupex expressions to Regex and vice versa.

Latest version **1.0.6** (published 2023-04-02) · 0 weekly downloads

## Install

```sh
npm install stupex
pnpm add stupex
yarn add stupex
bun add stupex
```

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.6 |
| Published | 2023-04-02 |
| First published | 2023-03-31 |
| Weekly downloads | 0 |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 121.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Amir Guterman |
| Maintainers | amirguterman |

## Links

- npm: https://www.npmjs.com/package/stupex
- npm.io page: https://npm.io/package/stupex

## Recent versions

- 1.0.6 (latest) — 2023-04-02
- 1.0.5 — 2023-04-02
- 1.0.4 — 2023-04-02
- 1.0.3 — 2023-04-02
- 1.0.2 — 2023-04-02
- 1.0.1 — 2023-04-02
- 1.0.0 — 2023-03-31

## README

# Table of Contents

- [Table of Contents](#table-of-contents)
- [Installation](#installation)
  - [Install the `stupex` package using npm:](#install-the-stupex-package-using-npm)
- [Summary](#summary)
  - [Stupex is a user-friendly, intuitive syntax for working with regular expressions, designed to make it easier for non-programmers and those with minimal technical skills to create, read, and understand regex patterns.](#stupex-is-a-user-friendly-intuitive-syntax-for-working-with-regular-expressions-designed-to-make-it-easier-for-non-programmers-and-those-with-minimal-technical-skills-to-create-read-and-understand-regex-patterns)
- [Why Stupex](#why-stupex)
- [Features](#features)
- [Usage](#usage)
  - [The Stupex package provides two main functions for converting between Stupex and regex expressions:](#the-stupex-package-provides-two-main-functions-for-converting-between-stupex-and-regex-expressions)
  - [NorEx-to-RegEx](#stupex-to-regex)
    - [`stupexToRegex()` Converts a Stupex expression to a regex pattern.](#stupextoregex-converts-a-stupex-expression-to-a-regex-pattern)
  - [RegEx-to-NorEx](#regex-to-stupex)
    - [`regexToStupex()` Converts a regex pattern to a Stupex expression.](#regextostupex-converts-a-regex-pattern-to-a-stupex-expression)
  - [These functions can be used to seamlessly integrate Stupex into your existing codebase and simplify the process of working with regular expressions.](#these-functions-can-be-used-to-seamlessly-integrate-stupex-into-your-existing-codebase-and-simplify-the-process-of-working-with-regular-expressions)
    - [`Available Expressions`](#available-expressions)
- [Examples](#examples)
- [Table of Expressions](#table-of-expressions)
- [Contributing](#contributing)

# Installation

## Install the `stupex` package using npm:

```
npm install stupex
```

# Summary

## Stupex is a user-friendly, intuitive syntax for working with regular expressions, designed to make it easier for non-programmers and those with minimal technical skills to create, read, and understand regex patterns.

# Why Stupex

- ## `Regular expressions` can be quite powerful, but their syntax is often considered cryptic and hard to grasp, especially for beginners. The purpose of the Stupex package is to provide a more accessible alternative to regex, using a simplified and descriptive syntax.
- ## `Stupex expressions` can be easily translated to regular expressions and vice versa using the provided functions, making it simple to integrate Stupex into your existing projects or learn regex patterns from their Stupex counterparts.
-
- ## By using Stupex, you can harness the power of regular expressions without getting lost in their complex syntax.

# Features

- ## Intuitive, human-readable syntax for defining regular expressions
- ## Bi-directional conversion between Stupex and regex expressions
- ## Compatibility with existing JavaScript regex patterns

# Usage

## The Stupex package provides two main functions for converting between Stupex and regex expressions:

## NorEx-to-RegEx

### `stupexToRegex()` Converts a Stupex expression to a regex pattern.

## RegEx-to-NorEx

### `regexToStupex()` Converts a regex pattern to a Stupex expression.

## These functions can be used to seamlessly integrate Stupex into your existing codebase and simplify the process of working with regular expressions.

### `Available Expressions`

For a complete list of available Stupex expressions and their corresponding regex patterns, please refer to the Stupex Expressions Table.

# Examples

Search for `http://` or `https://`:

```
# Stupex

// Syntax #1

line-start:
  "http"
  optional "s"
  "://"


// Syntax #2

line-start:
  "http"
  optional("s")
  "://"


// Syntax #3

line-start("http" optional("s") "://")
```

```
# Regex

^http(?:s)?://
```

Search for `hello world`:

```
# Stupex

// Syntax #1

"hello"
any:
  whitespace
  non-whitespace
"world"


// Syntax #2

"hello"
any whitespace non-whitespace
"world"


// Syntax #3
"hello" any(whitespace non-whitespace) "world"
```

```
# Regex

hello[\s\S]*?world
```

# Table of Expressions

| Regex Expression                                     | Stupex Expression                       | Description                                         |
| ---------------------------------------------------- | --------------------------------------- | --------------------------------------------------- |
| `.`                                                  | `(char)`                                | Any character                                       |
| `^`exp                                               | `starts-with(`exp`)`                    | Starts with expression                              |
| exp`$`                                               | `ends-with(`exp`)`                      | Ends with expression                                |
| `^`exp`$`                                            | `is-within(`exp`)`                      | Is within expression                                |
| exp`*`                                               | `optional(`exp`)`                       | Zero or more repetitions                            |
| exp`+`                                               | `at-least-once(`exp`)`                  | One or more repetitions                             |
| exp`?`                                               | `once-at-most(`exp`)`                   | Zero or one repetition                              |
| `{`n`}`                                              | `repeat-`n`-times(`exp`)`               | Repeat n times                                      |
| `{`n`,}`                                             | `repeat-`n`-or-more(`exp`)`             | Repeat n or more times                              |
| `{`n`,`m`}`                                          | `repeat-`n`-to-`m`(`exp`)`              | Repeat n to m times                                 |
| `[`chars`]`                                          | `with(`chars`)`                         | Any character in set                                |
| `[^`chars`]`                                         | `without(`chars`)`                      | Any character not in set                            |
| exp`\|`alt                                           | `either-or(`exp`, `alt`)`               | Either expression or alternative                    |
| `\(`exp`\)`                                          | `group(`exp`)`                          | Group expression                                    |
| `\\`                                                 | `escape-symbol`                         | Escape symbol                                       |
| `\d`                                                 | `(digit)`                               | Digit character                                     |
| `\D`                                                 | `(non-digit)`                           | Non-digit character                                 |
| `\w`                                                 | `(word-char)`                           | Word character                                      |
| `\W`                                                 | `(non-word-char)`                       | Non-word character                                  |
| `\s`                                                 | `(whitespace)`                          | Whitespace character                                |
| `\S`                                                 | `(non-whitespace)`                      | Non-whitespace character                            |
| `\b`exp                                              | `word(`exp`)`                           | Word boundary expression                            |
| `\B`exp                                              | `non-word(`exp`)`                       | Non-word boundary expression                        |
| `(?=`exp`)`                                          | `will-occur(`exp`)`                     | Positive lookahead                                  |
| `(?!`exp`)`                                          | `will-not-occur(`exp`)`                 | Negative lookahead                                  |
| `(?<=`exp`)`                                         | `has-occurred(`exp`)`                   | Positive lookbehind                                 |
| `(?<!`exp`)`                                         | `has-not-occurred(`exp`)`               | Negative lookbehind                                 |
| `(?:`exp`)`                                          | `non-capture-group(`exp`)`              | Non-capturing group                                 |
| `(?=`exp-1`)(?=`exp-2`)`...`(?=`exp-n`)`             | all-of(exp-1, ..., exp-n)               | All expressions occur                               |
| exp-1`\|`exp-2`\|`...`\|`exp-n                       | `one-of(`exp-1`,` ...`,` exp-n`)`       | One of the expressions occurs                       |
| `(?=`exp-1`) (?=`exp-2`) (?!(?=`exp-1`) (?=`exp-2`)` | `some-of(`exp-1`,` ...`,` exp-n`)`      | Some of the expressions occur                       |
| exp-1`(?=.*`exp-2`)(?=.*`exp-3`)`...                 | all-of-by-this-order(exp-1, ..., exp-n) | All expressions occur in order                      |
| Custom implementation                                | `js-symbol(`exp`)`                      | Any JS symbol with name returned from expression    |
| Custom implementation                                | `js-class(`exp`)`                       | Any JS class with name returned from expression     |
| Custom implementation                                | `js-function(`exp`)`                    | Any JS function with name returned from expression  |
| Custom implementation                                | `js-interface(`exp`)`                   | Any JS interface with name returned from expression |
| Custom implementation                                | `js-arg(`exp`)`                         | Any JS argument with a name described as expression |

- Additional expressions available, see package documentation for details.

# Contributing

We welcome contributions to improve and expand the Stupex package. If you have ideas for new expressions or improvements to the syntax, please feel free to submit a pull request or open an issue on the project's GitHub repository.

---
_Source: https://npm.io/package/stupex · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
