# rsre-wasm

> This package is a (currently very minimal) wrapper around the rust crate `regex` through WebAssembly in JavaScript. The main goal is to provide a safe regex without using node-gyp. You can use it in both Node and the Browser (assuming the platform suppo

Latest version **0.1.10** (published 2020-12-23) · MIT license · 0 weekly downloads

## Install

```sh
npm install rsre-wasm
pnpm add rsre-wasm
yarn add rsre-wasm
bun add rsre-wasm
```

## Health

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

Positive: has types; esm support; no vulnerabilities.

Warnings: low downloads; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.10 |
| Published | 2020-12-23 |
| First published | 2020-12-19 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 1.5 MB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | nerix |

## Links

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

## Recent versions

- 0.1.10 (latest) — 2020-12-23
- 0.1.9 — 2020-12-23
- 0.1.8 — 2020-12-22
- 0.1.7 — 2020-12-22
- 0.1.6 — 2020-12-22
- 0.1.5 — 2020-12-20
- 0.1.4 — 2020-12-19
- 0.1.3 — 2020-12-19
- 0.1.2 — 2020-12-19
- 0.1.1 — 2020-12-19
- 0.1.0 — 2020-12-19

## README

# RsRe-Wasm

This package is a (currently very minimal) wrapper around the rust crate `regex` through WebAssembly in JavaScript.
The main goal is to provide a safe regex without using node-gyp.
You can use it in both Node and the Browser (assuming the platform supports WebAssembly).
There's no glue-code for the Browser at the moment.

The naming isn't final as it's confusing.

## Example 
```typescript
import { RsReWasm } from 'rsre-wasm';

const regex = new RsReWasm(/(?<year>\d+)-(?<month>\d+)-(?<day>\d+)/g);
const string = "Foo happened on 2020-03-02 and bar happened on 2020-04-10.";
for (const { groups } of string.matchAll(regex)) {
    console.log(groups);
}

// Logs:
//
// { day: "02", month: "03", year: "2020" }
// { day: "10", month: "04", year: "2020" }
```

## Traps

* The creation of this Regex is **expensive**, so you should only instantiate it once:

**Bad**
```typescript
for(const input of inputs) {
    // This creates a regex on **every** iteration
    const regex = new RsReWasm(/(?<year>\d+)-(?<month>\d+)-(?<day>\d+)/g);
    if(regex.test(input)) {
        // do something
    }
}
```

**Good**
```typescript
 // Create the regex once, use it multiple times
const regex = new RsReWasm(/(?<year>\d+)-(?<month>\d+)-(?<day>\d+)/g);
for(const input of inputs) {
    if(regex.test(input)) {
        // do something
    }
}
```

### Building

```
node build.node.mjs
```

### Publish to NPM with `wasm-pack publish`

```
wasm-pack publish
```

### Known Issues

* The constructor throws strings as errors
* Naming is confusing
* Rust code is not checked (probably copying many things unnecessarily)
* ~~The flags are not checked and may contain duplicate flags~~

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