mqtt-wildcard
Version:
Match a MQTT Topic against Wildcards
54 lines (35 loc) • 1.85 kB
Markdown
//badge.fury.io/js/mqtt-wildcard.svg)](http://badge.fury.io/js/mqtt-wildcard)
[](https://gemnasium.com/github.com/hobbyquaker/mqtt-wildcard)
[](https://travis-ci.org/hobbyquaker/mqtt-wildcard)
[](https://coveralls.io/github/hobbyquaker/mqtt-wildcard?branch=master)
[](https://github.com/sindresorhus/xo)
[![License][mit-badge]][mit-url]
> Match a MQTT Topic against Wildcards
```
$ npm install mqtt-wildcard
```
```javascript
var mqttWildcard = require('mqtt-wildcard');
```
Alternatively you can use bower to install mqtt-wildcard, AMD is also supported.
_array|null_ **mqttWildcard** **(**_string_ **topic,** _string_ **wildcard)**
Returns `null` if not matched, otherwise an array containing the wildcards contents will be returned.
Examples:
```javascript
mqttWildcard('test/foo/bar', 'test/foo/bar'); // []
mqttWildcard('test/foo/bar', 'test/+/bar'); // ['foo']
mqttWildcard('test/foo/bar', 'test/#'); // ['foo/bar']
mqttWildcard('test/foo/bar/baz', 'test/+/#'); // ['foo', 'bar/baz']
mqttWildcard('test/foo/bar/baz', 'test/+/+/baz'); // ['foo', 'bar']
mqttWildcard('test', 'test/#'); // []
mqttWildcard('test/', 'test/#'); // ['']
mqttWildcard('test/foo/bar', 'test/+'); // null
mqttWildcard('test/foo/bar', 'test/nope/bar'); // null
```
MIT (c) 2017 [Sebastian Raff](https://github.com/hobbyquaker)
[ ]: https://img.shields.io/badge/License-MIT-blue.svg?style=flat
[ ]: LICENSE
[![NPM version](https: