Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/pansyjs/mqtt-pattern
Fast library for matching MQTT patterns with named wildcards
https://github.com/pansyjs/mqtt-pattern
mqtt mqtt-pattern
Last synced: about 2 months ago
JSON representation
Fast library for matching MQTT patterns with named wildcards
- Host: GitHub
- URL: https://github.com/pansyjs/mqtt-pattern
- Owner: pansyjs
- Created: 2022-05-04T14:57:54.000Z (over 2 years ago)
- Default Branch: master
- Last Pushed: 2023-12-15T02:57:29.000Z (about 1 year ago)
- Last Synced: 2024-04-16T05:19:15.451Z (9 months ago)
- Topics: mqtt, mqtt-pattern
- Language: TypeScript
- Homepage:
- Size: 115 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
@pansy/mqtt-pattern
Fast library for matching MQTT patterns with named wildcards。
[![npm version][npm-v-image]][npm-url]
[![npm download][download-image]][download-url]
[![stars-image][stars-image]][stars-url]
[![forks-image][forks-image]][forks-url]
**约定:**
- `+` 约定单个变量使用
- `#` 约定多个变量使用例如
```ts
const pattern = `/foo/+id/world/#paths`;const topic = `/foo/1519699178931773441/world/test/channel`;
{
id: '1519699178931773441',
paths: ['test', 'channel'],
}
```## 🏗 安装
```
// npm
npm install @pansy/mqtt-pattern --save// yarn
yarn add @pansy/mqtt-pattern// pnpm
pnpm i @pansy/mqtt-pattern
```## API
### fill
回填 `pattern` 中的指定变量,获取通道。
```ts
function fill(pattern: string, params: Record): string;
```例如:
```ts
fill('foo/+hello/#world', {
hello: 'Hello',
world: ['the', 'world', 'wow'],
});// 'foo/Hello/the/world/wow'
```### exec
验证并解析通道
```ts
function exec(pattern: string, topic: string): Record | null;
```例如:
```ts
exec('foo/+hello/#world', 'foo/Hello/the/world/wow');// {
// hello: 'Hello',
// world: ['the', 'world', 'wow'],
// }
```### matches
验证通道
```ts
function matches(pattern: string, topic: string): boolean;
``````ts
matches('foo/+hello/#world', 'foo/Hello/the/world/wow');// true
```### extract
解析通道
```ts
function extract(pattern: string, topic: string): Record;
```例如:
```ts
extract('foo/+hello/#world', 'foo/Hello/the/world/wow');// {
// hello: 'Hello',
// world: ['the', 'world', 'wow'],
// }
```### clean
清除变量中的名称
```ts
function clean(pattern: string): string;
```例如:
```ts
exec('foo/+hello/#world');// 'foo/+/#'
```[npm-v-image]: https://img.shields.io/npm/v/@pansy/mqtt-pattern.svg
[npm-url]: http://npmjs.org/package/@pansy/mqtt-pattern
[forks-image]: https://img.shields.io/github/forks/pansyjs/mqtt-pattern.svg
[forks-url]: https://github.com/pansyjs/mqtt-pattern/network/members
[stars-image]: https://img.shields.io/github/stars/pansyjs/mqtt-pattern.svg
[stars-url]: https://github.com/pansyjs/mqtt-pattern/stargazers
[download-image]: https://img.shields.io/npm/dm/@pansy/mqtt-pattern
[download-url]: https://npmjs.org/package/@pansy/mqtt-pattern