Match a MQTT Topic against Wildcards
$ npm install mqtt-wildcard
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:
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