# devisPattern

> A fast native pattern matcher addon on JavaScript object properties

Latest version **1.2.1** (published 2017-10-07) · MIT license · 9 weekly downloads

## Install

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

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 1.2.1 |
| Published | 2017-10-07 |
| First published | 2016-09-14 |
| Weekly downloads | 9 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Known vulnerabilities | 0 |
| Install scripts | yes |
| GitHub stars | 10 |
| Author | ismail reida |
| Maintainers | ismailrei |
| Keywords | pattern, matcher, object, property, json |

## Links

- npm: https://www.npmjs.com/package/devisPattern
- Repository: https://github.com/Devisjs/devisPattern
- Issues: https://github.com/Devisjs/devisPattern/issues
- npm.io page: https://npm.io/package/devisPattern

## Dependencies (2)

- [nan](https://npm.io/package/nan.md) ^2.7.0
- [cmake-js](https://npm.io/package/cmake-js.md) ^3.5.0

## Alternatives

- [@mapbox/jsonlint-lines-primitives](https://npm.io/package/@mapbox/jsonlint-lines-primitives.md) — 5.3M weekly downloads
- [reftools](https://npm.io/package/reftools.md) — 3.5M weekly downloads
- [@hey-api/openapi-ts](https://npm.io/package/@hey-api/openapi-ts.md) — 3.5M weekly downloads
- [@mapbox/geojson-rewind](https://npm.io/package/@mapbox/geojson-rewind.md) — 2.4M weekly downloads
- [turbo-stream](https://npm.io/package/turbo-stream.md) — 1.7M weekly downloads

## Recent versions

- 1.2.1 (latest) — 2017-10-07
- 1.1.0 — 2017-05-06
- 1.0.2 — 2016-11-24
- 1.0.1 — 2016-11-16
- 1.0.0 — 2016-10-12
- 0.2.2 — 2016-09-20
- 0.2.1 — 2016-09-20
- 0.2.0 — 2016-09-19
- 0.1.0 — 2016-09-14

## README

# DevisPattern

<img src="https://8zzp5w.dm2302.livefilestore.com/y3mfmEBf29sGXflOWN_Hk0yFy3debRCUbdQiTEuttJh0bAg3axpzhmJspRFdOnaLwKylPPYewtA8M-z1_RO2YgjBkOU75s18kvWdqPeT5z7wXXdjKBu3tPeKu4L_FFGn_R5UKIH6LspIBhy-JMYBVT6vT0GusOzoPkbBdXGxN0rnNk?width=600&height=600&cropmode=none" width="250"/>


<p align="center">
  <a href="https://circleci.com/gh/Devisjs/devis/tree/master"><img src="https://img.shields.io/circleci/project/Devisjs/devisPattern/master.svg" alt="Build Status"></a>
  <a href="https://www.npmjs.com/package/devisPattern"><img src="https://img.shields.io/npm/v/devisPattern.svg" alt="Version"></a>
  <a href="https://www.npmjs.com/package/devisPattern"><img src="https://img.shields.io/npm/l/devisPattern.svg" alt="License"></a>
  <a href="https://www.bithound.io/github/Devisjs/devisPattern"><img src="https://www.bithound.io/github/Devisjs/devisPattern/badges/score.svg" alt="bitHound Overall Score"></a>
  
  <a href="https://www.bithound.io/github/Devisjs/devisPattern"><img src="https://www.bithound.io/github/Devisjs/devisPattern/badges/code.svg" alt="bitHound Overall Score"></a>
  <a href="https://travis-ci.org/Devisjs/devisPattern"><img src="https://travis-ci.org/Devisjs/devisPattern.svg?branch=master" alt="travis"></a>
  
  <br>

</p>


>A fast native pattern matcher addon on JavaScript object properties.


This addon is used by the devis framework to pattern match actions.

**Requirements:**

It's necessary, before using DevisPattern to install:
- [CMake](http://www.cmake.org/download/)(*.msi version for windows: You must check the addition of the path for all users, And restart your computer after installation)
- A proper C/C++ compiler toolchain of the given platform
    - **Windows**:
        - [Visual C++ Build Tools](http://landinghub.visualstudio.com/visual-cpp-build-tools)
        or a recent version of Visual C++ will do ([the free Community](https://www.visualstudio.com/products/visual-studio-community-vs) version works well)             
    - **Unix/linux-gnu**:
        - Clang or GCC
        - Ninja or Make (Ninja will be picked if both present)
        - Xcode with command line tools if you are under **mac os**



## Install

```sh
npm install devisPattern
```
Or, if you download the project:

Generate the appropriate project build files for the current platform. Use `configure` for that:
```sh
node-gyp configure
```
Now you will have either a `Makefile` (on Unix platforms) or a `vcxproj` file (on Windows) in the `build/` directory. Next invoke the build command:
```sh
node-gyp build
```

### Quick example
Here's how you register some patterns, and then search for matches:

```JavaScript
const devisPattern =require("devisPattern"); //or require("./devisPattern/devisPattern"); if you download the project 

devisPattern.add({
    action: 'game',
    cmd: 'play'
}, (args, done) => {

    done({
        result: 'play'
    });
});
devisPattern.add({
    action: 'game',
    cmd: 'pause'
}, (args, done)=> {

    done({
        result: 'pause'
    });
});

devisPattern.call({
    action: 'game',
    cmd: 'play'
}, (result)=> {

    console.log(result);

});

devisPattern.call({
    action: 'game',
    cmd: 'pause'
}, (result) =>{


    console.log(result);
});

```


# The Why

This addon lets you build a simple decision tree so you can avoid writing if statements. It tries to make the minimum number of comparisons necessary to pick out the most specific match.

# API

### devisPattern

Generates a new pattern matcher instance. 


### .add( {...pattern...}, object )

Register a pattern, and the object that will be returned if an input
matches.  Both keys and values are considered to be strings. Other
types are converted to strings.

### .find( {...pattern...})

Return the unique match for this pattern, or null if not found. 

### .call({...pattern...},{...arguments...},callback)

Act this pattern.

### .list( )

Return the list of registered patterns that contain this partial
pattern.

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