-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: added + and # wildcard support (#78)
- Loading branch information
Showing
7 changed files
with
74 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"vue-paho-mqtt": minor | ||
--- | ||
|
||
feat: added + and # wildcard support |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/** | ||
* Create a list of possible topics from a topic string that may contain wildcards | ||
* @param topic A topic string that may contain wildcards | ||
*/ | ||
export function createTopicList(topic: string): string[] { | ||
const parts = topic.split('/'); | ||
const result: string[] = []; | ||
|
||
for (let i = 0; i < parts.length; i++) { | ||
let generatedTopic = | ||
parts.slice(0, i).join('/') + '/+/' + parts.slice(i + 1).join('/'); | ||
if (generatedTopic.startsWith('/')) | ||
generatedTopic = generatedTopic.slice(1); | ||
if (generatedTopic.endsWith('/')) | ||
generatedTopic = generatedTopic.slice(0, -1); | ||
result.push(generatedTopic); | ||
} | ||
|
||
for (let i = 0; i < parts.length; i++) { | ||
const generatedTopic = | ||
parts.slice(0, i + 1).join('/') + (i < parts.length - 1 ? '/#' : ''); | ||
result.push(generatedTopic); | ||
} | ||
|
||
return result; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters