Security News
Weekly Downloads Now Available in npm Package Search Results
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
lwmqn-util
Advanced tools
Utility for LWMQN mqtt-shepherd server and mqtt-node client libraries.
lwmqn-util is a utility for Lightweight Mqtt Machine Network Server(mqtt-shepherd) and Client(mqtt-node) modules. This utility provides some common methods of getting identifiers in string or in number, getting command ids, getting response codes, and tackling the path of resource alloaction.
$ npm install lwmqn-util --save
Returns an item of the Object identifier.
Arguments
oid
can be given with a string or a number. Notice that a numbered string will be recognized as a number, e.g. '128' is equal to 128.Returns:
{ key: 'sampleId', value: 1234 }
, otherwise returns undefined
if not found.Example
var ut = require('lwmqn-util');
ut.getOid('temperature'); // { key: 'temperature', value: 3303 }
ut.getOid(3303); // { key: 'temperature', value: 3303 }
ut.getOid('3303'); // { key: 'temperature', value: 3303 }
ut.getOid('xxxx'); // undefined
ut.getOid('9999'); // undefined
ut.getOid(9999); // undefined
Returns the string of an Object identifier.
Arguments
oid
can be given with a string or a number. Notice that a numbered string will be recognized as a number, e.g. '128' is equal to 128.Returns:
'oid'
ifself if not found.Example
ut.oidKey('temperature'); // 'temperature'
ut.oidKey(3303); // 'temperature'
ut.oidKey('3303'); // 'temperature'
ut.oidKey('xxxx'); // 'xxxx' (returns the argument itself if id not found)
ut.oidKey('9999'); // '9999'
ut.oidKey(9999); // 9999
Returns the number of an Object identifier.
Arguments
oid
can be given with a string or a number. Notice that a numbered string will be recognized as a number, e.g. '128' is equal to 128.Returns:
'oid'
ifself if not found.Example
ut.oidNum('temperature'); // 3303
ut.oidNum(3303); // 3303
ut.oidNum('3303'); // 3303
ut.oidKey('xxxx'); // 'xxxx' (returns the argument itself if id not found)
ut.oidKey('9999'); // 9999
ut.oidKey(9999); // 9999
Returns an item of the Resource identifier.
To query a Resource id specific to an Object, bothoid
andrid
should be given.
To query an unique Resource id, only the single argumentrid
is needed.
Arguments
oid
can be given with a string or a number. Notice that a numbered string will be recognized as a number, e.g. '128' is equal to 128.rid
can be given with a string or a number. Notice that a numbered string will be recognized as a number, e.g. '128' is equal to 128.Returns:
{ key: 'sampleId', value: 1234 }
, otherwise returns undefined
if not found.Example
// get a Resource id specific to an Object
ut.getRid('location', 'lon'); // { key: 'lon', value: 1 }
ut.getRid(6, 1); // { key: 'lon', value: 1 }
ut.getRid('temperature', 'sensorValue'); // { key: 'sensorValue', value: 5700 }
ut.getRid(3303, 5700); // { key: 'sensorValue', value: 5700 }
ut.getRid('temperature', '5700'); // { key: 'sensorValue', value: 5700 }
// get an unqiue Resource id
ut.getRid('appType'); // { key: 'appType', value: 5750 }
ut.getRid(5750); // { key: 'appType', value: 5700 }
ut.getRid('5750'); // { key: 'appType', value: 5750 }
Returns the string of an Resource identifier.
Arguments
oid
can be given with a string or a number. Notice that a numbered string will be recognized as a number, e.g. '128' is equal to 128.rid
can be given with a string or a number. Notice that a numbered string will be recognized as a number, e.g. '128' is equal to 128.Returns:
'rid'
ifself if not found.Example
// get a Resource id specific to an Object
ut.ridKey('location', 'lon'); // 'lon'
ut.ridKey(6, 1); // 'lon'
ut.ridKey('temperature', 'sensorValue'); // 'sensorValue'
ut.ridKey(3303, 5700); // 'sensorValue'
ut.ridKey('temperature', '5700'); // 'sensorValue'
// get an unqiue Resource id
ut.ridKey('appType'); // 'appType'
ut.ridKey(5750); // 'appType'
ut.ridKey('5750'); // 'appType'
// returns rid itself if not found
ut.ridKey('no_such_rid'); // 'no_such_rid'
ut.ridKey(3303, 'no_such_id'); // 'no_such_id'
Returns the number of an Resource identifier.
Arguments
oid
can be given with a string or a number. Notice that a numbered string will be recognized as a number, e.g. '128' is equal to 128.rid
can be given with a string or a number. Notice that a numbered string will be recognized as a number, e.g. '128' is equal to 128.Returns:
'rid'
ifself if not found.Example
// get a Resource id specific to an Object
ut.ridNum('location', 'lon'); // 1
ut.ridNum(6, 1); // 1
ut.ridNum('temperature', 'sensorValue'); // 5700
ut.ridNum(3303, 5700); // 5700
ut.ridNum('temperature', '5700'); // 5700
// get an unqiue Resource id
ut.ridNum('appType'); // 5750
ut.ridNum(5750); // 5750
ut.ridNum('5750'); // 5750
// returns rid itself if not found
ut.ridNum('no_such_rid'); // 'no_such_rid'
ut.ridNum('99999'); // 99999 (no such rid)
ut.ridNum(99999); // 99999 (no such rid)
ut.ridNum(3303, 7654); // 7654 (no such rid)
Returns an item of the Response code.
Arguments
code
can be given with a string or a number.Returns:
{ key: 'Created', value: 201 }
, otherwise returns undefined
if not found.Example
ut.getRspCode('BadRequest'); // { key: 'BadRequest', value: 400 }
ut.getRspCode(400); // { key: 'BadRequest', value: 400 }
ut.getRspCode(302); // undefined
Returns the string of an Response code.
Arguments
code
can be given with a string or a number.Returns:
undefined
if not found.Example
ut.rspCodeKey('BadRequest'); // 'BadRequest'
ut.rspCodeKey(400); // 'BadRequest'
ut.rspCodeKey(302); // undefined
Returns the number of an Response code.
Arguments
code
can be given with a string or a number.Returns:
undefined
if not found.Example
ut.rspCodeKey('BadRequest'); // 400
ut.rspCodeKey(400); // 400
ut.rspCodeKey(302); // undefined
Returns an item of the command idetifier.
Arguments
cmd
can be given with a string or a number.Returns:
{ key: 'discover', value: 2 }
, otherwise returns undefined
if not found.Example
ut.getCmd('read'); // { key: 'read', value: 0 }
ut.getCmd('write'); // { key: 'write', value: 1 }
ut.getCmd('discover'); // { key: 'discover', value: 2 }
ut.getCmd('writeAttrs'); // { key: 'writeAttrs', value: 3 }
ut.getCmd('execute'); // { key: 'execute', value: 4 }
ut.getCmd('observe'); // { key: 'observe', value: 5 }
ut.getCmd('notify'); // { key: 'execute', value: 6 }
ut.getCmd(0); // { key: 'read', value: 0 }
ut.getCmd(1); // { key: 'write', value: 1 }
ut.getCmd(2); // { key: 'discover', value: 2 }
ut.getCmd(3); // { key: 'writeAttrs', value: 3 }
ut.getCmd(4); // { key: 'execute', value: 4 }
ut.getCmd(5); // { key: 'observe', value: 5 }
ut.getCmd(6); // { key: 'execute', value: 6 }
Returns the string of an command identifier.
Arguments
cmd
can be given with a string or a number.Returns:
undefined
if unrecognized.Example
ut.cmdKey('read'); // 'read'
ut.cmdKey(4); // 'execute'
ut.cmdKey('no_such_cmd'); // undefined
ut.cmdKey(22); // undefined
Returns the number of an command identifier.
Arguments
cmd
can be given with a string or a number.Returns:
undefined
if unrecognized.Example
ut.cmdKey('read'); // 0
ut.cmdKey(4); // 4
ut.cmdKey('no_such_cmd'); // undefined
ut.cmdKey(22); // undefined
Returns a path string in conjunction of the given connector.
Arguments
'.'
or '/'
Returns:
Example
ut.createPath('.', 'dev', 0, 'sensor'); // 'dev.0.sensor'
ut.createPath('/', 'dev', 0, 'sensor', 'value'); // 'dev/0/sensor/value'
Returns a path with '/' separator.
Arguments
Returns:
'.'
or '/'
.Example
ut.slashPath('dev.0.sensor.value'); // 'dev/0/sensor/value'
ut.slashPath('.dev.0.sensor.value'); // 'dev/0/sensor/value'
ut.slashPath('/dev.0.sensor/value/'); // 'dev/0/sensor/value'
ut.slashPath('/dev/0/sensor/value/'); // 'dev/0/sensor/value'
Returns a path with '.' separator.
Arguments
Returns:
'.'
or '/'
.Example
ut.dotPath('dev.0.sensor.value'); // 'dev.0.sensor.value'
ut.dotPath('.dev.0.sensor.value'); // 'dev.0.sensor.value'
ut.dotPath('/dev.0.sensor/value/'); // 'dev.0.sensor.value'
ut.dotPath('/dev/0/sensor/value/'); // 'dev.0.sensor.value'
Returns an array of words that are separated by
'.'
or'/'
.
Arguments
Returns:
Example
ut.pathItems('dev.0.sensor.value'); // [ 'dev', '0', 'sensor', 'value' ]
ut.pathItems('.dev.0.sensor.value'); // [ 'dev', '0', 'sensor', 'value' ]
ut.pathItems('/dev.0.sensor/value/'); // [ 'dev', '0', 'sensor', 'value' ]
ut.pathItems('/dev/0/sensor/value/'); // [ 'dev', '0', 'sensor', 'value' ]
Returns an object in path-value pair.
Arguments
obj
attachs toReturns:
Example
var myObj = {
a: {
a1: {
a11: 1,
a12: 'hi',
},
a2: 'foo'
},
b: 'hello',
c: 3
};
var newObj = ut.buildPathValuePairs('/', myObj);
// newObj = {
// 'a.a1.a11': 1,
// 'a.a1.a12': 'hi',
// 'a.a2': 'foo',
// 'b': 'hello',
// 'c': 3
// }
var newObj = ut.buildPathValuePairs('/dev/0', myObj);
// newObj = {
// 'dev.0.a.a1.a11': 1,
// 'dev.0.a.a1.a12': 'hi',
// 'dev.0.a.a2': 'foo',
// 'dev.0.b': 'hello',
// 'dev.0.c': 3
// }
Check if a status code is a good response. The good responses are those with status codes in either one of 200, 201, 202, 204, and 205.
Arguments
status
can be given with a string or a number.Returns:
Example
ut.isGoodResponse(200); // true
ut.isGoodResponse('Deleted'); // true
ut.isGoodResponse('NotFound'); // false
ut.isGoodResponse(409); // false
Get the access control flag of an Resource. Please refer to lwm2m-id documentation.
Arguments
oid
can be given with a string or a number. Notice that a numbered string will be recognized as a number, e.g. '128' is equal to 128.rid
can be given with a string or a number. Notice that a numbered string will be recognized as a number, e.g. '128' is equal to 128.Returns:
Example
ut.getAccessCtrl('temperature', 'sensorValue'); // 'R'
ut.getAccessCtrl('lightCtrl', 5850); // 'RW'
ut.getAccessCtrl('xxxx', 1234); // undfined
Jsonify a string into a Javascript object.
Arguments
Returns:
Example
ut.jsonify('{"x": 3, "y": 'hi'}'); // { x: 3, y: 'hi' }
ut.jsonify('hello there'); // 'hello there'
FAQs
Utility for LWMQN mqtt-shepherd server and mqtt-node client libraries
The npm package lwmqn-util receives a total of 0 weekly downloads. As such, lwmqn-util popularity was classified as not popular.
We found that lwmqn-util demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
Security News
A Stanford study reveals 9.5% of engineers contribute almost nothing, costing tech $90B annually, with remote work fueling the rise of "ghost engineers."
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.