@nexssp/data
Advanced tools
Comparing version 1.0.2 to 1.0.3
@@ -70,2 +70,19 @@ const _log = require('@nexssp/logdebug') | ||
// Maybe there is better function, this works for us. | ||
function isJson(item) { | ||
item = typeof item !== 'string' ? JSON.stringify(item) : item | ||
try { | ||
item = JSON.parse(item) | ||
} catch (e) { | ||
return false | ||
} | ||
if (typeof item === 'object' && item !== null) { | ||
return true | ||
} | ||
return false | ||
} | ||
const isFile = (v) => { | ||
@@ -97,2 +114,4 @@ const stat = lstatSync(v) | ||
return v.startsWith('http://') || v.startsWith('https://') | ||
case 'json': | ||
return isJson(v) | ||
default: | ||
@@ -99,0 +118,0 @@ break |
@@ -40,4 +40,5 @@ const stream = require('stream') | ||
url: () => ['https://abc.ce', 'https://abc.de'], | ||
json: () => ['{"x":1}', '{"val":{"nested":5}}'], | ||
// Exists: () => [`${__dirname}/guard.js`, `${__dirname}/../datatype`], | ||
// async *[Symbol.asyncIterator]() {} | ||
} |
{ | ||
"name": "@nexssp/data", | ||
"main": "lib/data.js", | ||
"version": "1.0.2", | ||
"version": "1.0.3", | ||
"description": "Checking and comparing datatypes", | ||
@@ -6,0 +6,0 @@ "keywords": [ |
@@ -32,4 +32,4 @@ # @nexssp/data | ||
- **type (value)** -> return one of the datatype: **object, string, array, number, boolean, undefined, function, null, map, set, generatorfunction, promise, stream** | ||
- **is (type, value)** -> check for the types + **is('directory',v)**, **is('dir',v)**, **is('file',v)** | ||
- **type (value)** -> return one of the datatype: **object, string, array, number, boolean, undefined, function, null, map, set, generatorfunction, promise, stream, url, json** | ||
- **is (type, value)** -> check for the types + **is('directory',v)**, **is('dir',v)**, **is('file',v), **is('url',v), , **is('json',v)** | ||
- **compare (v1, v2)** -> compares 2 values. If any of them is function, it will run first and then compare | ||
@@ -78,3 +78,4 @@ - **isEmpty (value)** -> check if anything is empty like array, object, string. | ||
url: () => ['https://abc.com', 'http://abc.com'], | ||
json: () => ['{"x":1}', '{"val":{"nested":5}}'], | ||
} | ||
``` |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
20491
343
80