Comparing version 1.2.6 to 1.2.7
40
index.js
@@ -31,2 +31,14 @@ 'use strict'; | ||
function isValidArgType(param) { | ||
var isValid = true; | ||
if (typeof param !== 'number' && typeof param !== 'string') { | ||
isValid = false; | ||
} else if (typeof param === 'number') { | ||
isValid = !isNaN(param); | ||
} | ||
return isValid; | ||
} | ||
/*************************************************************************************************/ | ||
@@ -36,3 +48,3 @@ /*** DEFS Methods ***/ | ||
DEFS.getCmd = function (cmdId) { | ||
if (typeof cmdId !== 'number' && typeof cmdId !== 'string') | ||
if (!isValidArgType(cmdId)) | ||
throw new TypeError('cmdId should be type of string or number.'); | ||
@@ -44,3 +56,3 @@ | ||
DEFS.getRspCode = function (code) { | ||
if (typeof code !== 'number' && typeof code !== 'string') | ||
if (!isValidArgType(code)) | ||
throw new TypeError('code should be a type of string or number.'); | ||
@@ -52,3 +64,3 @@ | ||
DEFS.getOid = function (oid) { | ||
if (typeof oid !== 'number' && typeof oid !== 'string') | ||
if (!isValidArgType(oid)) | ||
throw new TypeError('oid should be a number or a string.'); | ||
@@ -70,2 +82,5 @@ | ||
if (typeof items !== 'object' || items === null || Array.isArray(items)) | ||
throw new TypeError('items should be a plain object.'); | ||
for (var key in items) { | ||
@@ -94,7 +109,7 @@ if (DEFS.getOid(key)) | ||
if (typeof oid === 'undefined') | ||
throw new Error('Bad arguments'); | ||
throw new TypeError('Bad arguments'); | ||
rid = oid; | ||
oid = undefined; | ||
if (typeof rid !== 'number' && typeof rid !== 'string') | ||
if (!isValidArgType(rid)) | ||
throw new TypeError('rid should be a number or a string.'); | ||
@@ -108,9 +123,9 @@ } | ||
if (typeof oid !== 'undefined') { // searching in MDEFS.RIDOFOID | ||
if (typeof oid !== 'number' && typeof oid !== 'string') | ||
if (!isValidArgType(oid)) | ||
throw new TypeError('rid should be a number or a string.'); | ||
if (typeof rid === 'undefined') | ||
throw new Error('rid should be given'); | ||
throw new TypeError('rid should be given'); | ||
if (typeof rid !== 'number' && typeof rid !== 'string') | ||
if (!isValidArgType(rid)) | ||
throw new TypeError('rid should be a number or a string.'); | ||
@@ -132,2 +147,5 @@ | ||
if (typeof items !== 'object' || items === null || Array.isArray(items)) | ||
throw new TypeError('items should be a plain object.'); | ||
for (var key in items) { | ||
@@ -161,2 +179,5 @@ if (DEFS.getRid(key)) | ||
if (typeof items !== 'object' || items === null || Array.isArray(items)) | ||
throw new TypeError('items should be a plain object.'); | ||
for (var key in items) { | ||
@@ -206,2 +227,5 @@ if (typeof _spfRid[oidKey][key] !== 'undefined') { | ||
if (typeof chars !== 'object' || chars === null || Array.isArray(chars)) | ||
throw new TypeError('chars should be a plain object.'); | ||
for (var rid in chars) { | ||
@@ -208,0 +232,0 @@ ridItem = DEFS.getRid(oid, rid); |
{ | ||
"name": "lwm2m-id", | ||
"version": "1.2.6", | ||
"version": "1.2.7", | ||
"description": "lwm2m-id is a module that implements a dictionary of ip-based smart object(IPSO) identifiers defined by lwm2m spec.", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
"test": "make test-all" | ||
}, | ||
@@ -27,4 +27,5 @@ "repository": { | ||
"devDependencies": { | ||
"should": "^7.1.1" | ||
"chai": "^3.5.0", | ||
"mocha": "^2.5.3" | ||
} | ||
} |
No tests
QualityPackage does not have any tests. This is a strong signal of a poorly maintained or low quality package.
Found 1 instance in 1 package
180251
12
2743
0
2