1.0.1 • Published 3 years ago

@mangar2/topicmap v1.0.1

Weekly downloads
2
License
LGPL-3.0-or-later
Repository
github
Last release
3 years ago

Abstract

Contents

Meta

Class TopicMap

new TopicMap(configuration)

Creates a class to map topics from internal to external representation and vice versa if there is a matching mapping rule in configuration . It keeps unchanged if there is no mapping rule

Example

const configuration =
  fs20: {
      'fs20/2111': 'ground/livingroom/zwave/switch/multimedia/set'
  },
  location: {
      'location/33/#': 'first/bedroom/main/#'
}
const topicMap = new topicMap(configuration)
const map = topicMap('location/33/a/b') // returns 'first/bedroom/main/a/b'
const map = topicMap('anything/not/mapped') // returns 'anything/not/mapped'

TopicMap Parameters

NameTypeDescription
configurationObjectmapping configuration with topic : map pairs that might be organized in trees like { 1 : { topic : map , . . . } , 2 : { topic : map , . . . } }

TopicMap Methods

mapExternalToInternal

mapExternalToInternal (topic) => {string}

Maps a topic from external representation to internal representation

mapExternalToInternal Parameters
NameTypeDescription
topicstringexternal topic to map
mapExternalToInternal returns
TypeDescription
stringinternal topic

mapInternalToExternal

mapInternalToExternal (topic) => {string}

Maps a topic from internal representation to external representation

mapInternalToExternal Parameters
NameTypeDescription
topicstringinternal topic to map
mapInternalToExternal returns
TypeDescription
stringexternal topic