mqtt-wildcard
v3.0.9
Published
Match a MQTT Topic against Wildcards
Downloads
3,581
Maintainers
Readme
mqtt-wildcard
Match a MQTT Topic against Wildcards
Install and Usage
$ npm install mqtt-wildcard
var mqttWildcard = require('mqtt-wildcard');
Alternatively you can use bower to install mqtt-wildcard, AMD is also supported.
API
array|null mqttWildcard (string topic, string wildcard)
Returns null
if not matched, otherwise an array containing the wildcards contents will be returned.
Examples:
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
License
MIT (c) 2017 Sebastian Raff