mqtt-wildcard

Match a MQTT Topic against Wildcards

Downloads in past

Stats

StarsIssuesVersionUpdatedCreatedSize
mqtt-wildcard
3.0.95 years ago5 years agoMinified + gzip package size for mqtt-wildcard in KB

Readme

mqtt-wildcard
NPM version Dependency Status Build Status Coverage Status XO code style !Licensemit-badgemit-url
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