DevisPattern
A fast native pattern matcher addon on JavaScript object properties
Install / Use
/learn @Devisjs/DevisPatternREADME
DevisPattern
<img src="https://avatars3.githubusercontent.com/u/21971184?v=4&s=200" href="http://devisjs.surge.sh" width="250" /><p align="center"> <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(*.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 or a recent version of Visual C++ will do (the free Community 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
- Windows:
Install
npm install devisPattern
Or, if you download the project:
Generate the appropriate project build files for the current platform. Use configure for that:
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:
node-gyp build
Quick example
Here's how you register some patterns, and then search for matches:
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.
Related Skills
node-connect
349.7kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
109.7kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
349.7kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
qqbot-media
349.7kQQBot 富媒体收发能力。使用 <qqmedia> 标签,系统根据文件扩展名自动识别类型(图片/语音/视频/文件)。
