deepwalker
Advanced tools
Comparing version 1.0.0 to 1.0.1
@@ -86,3 +86,3 @@ import { deepwalker } from './deepwalker' | ||
filter('compare.*.*.session_share', essential_share) | ||
function(el){ | ||
function byValue(el){ | ||
el.value | ||
@@ -92,2 +92,5 @@ el.dim1 | ||
} | ||
deepwalker(obj).get('compare.*.*.difference').sort(byValue).filter(essential_share).map(action) | ||
*/ |
@@ -12,2 +12,3 @@ | ||
_value: object, | ||
_result: null, | ||
get: function (queryPath: string): DeepwalkerResult { | ||
@@ -21,15 +22,29 @@ return instanceResult.setResult(walker(queryPath.split("."), object)); | ||
...instance, | ||
toValue: function () { | ||
return instanceResult?._result[0]?.value; | ||
toValue: function (path) { | ||
return path ? instanceResult?._result[0]?.value[path] : instanceResult?._result[0]?.value; | ||
}, | ||
filter: function (filterFn) { | ||
return instanceResult.setResult(instanceResult._result.call.filter(instanceResult, filterFn)) | ||
return instanceResult.setResult(instanceResult._result.filter(filterFn)) | ||
}, | ||
sort: function (sortFn) { | ||
return instanceResult.setResult(instanceResult._result.call.filter(instanceResult, sortFn)) | ||
instanceResult._result.sort(sortFn) | ||
return instanceResult; | ||
}, | ||
slice: function (number) { | ||
instanceResult._result = instanceResult._result.slice(0, number) | ||
return instanceResult; | ||
}, | ||
toValues: function () { | ||
return instanceResult._result.map(r => r.value); | ||
}, | ||
toMap: function () { | ||
toString: function (transformer) { | ||
if (!instanceResult._result || instanceResult._result.length == 0) return ''; | ||
return transformer(instanceResult._result) | ||
}, | ||
haveResults: function () { | ||
if (!instanceResult._result || instanceResult._result.length == 0) return false; | ||
return true; | ||
}, | ||
toMap: function (path) { | ||
return instanceResult._result.reduce((res, r, i) => { | ||
@@ -41,3 +56,3 @@ let deepResult = res; | ||
} | ||
if (i === (r.dimensions.length - 1)) deepResult[dim] = r.value; | ||
if (i === (r.dimensions.length - 1)) deepResult[dim] = path ? r.value[path] : r.value; | ||
deepResult = deepResult[dim]; | ||
@@ -44,0 +59,0 @@ }) |
{ | ||
"name": "deepwalker", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "", | ||
"main": "index.js", | ||
"main": "deepwalker.js", | ||
"types": "deepwalker.ts", | ||
"scripts": { | ||
"test": "node ./node_modules/jest/bin/jest.js", | ||
"test-dev": "node ./node_modules/jest/bin/jest.js --watch" | ||
"test-dev": "node ./node_modules/jest/bin/jest.js --watch", | ||
"build": "tsc deepwalker.ts" | ||
}, | ||
@@ -18,2 +20,2 @@ "author": "", | ||
} | ||
} | ||
} |
10454
6
287