New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@tsmx/json-traverse

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@tsmx/json-traverse - npm Package Compare versions

Comparing version 1.0.6 to 1.0.7

.github/workflows/npm-publish.yml

3

package.json
{
"name": "@tsmx/json-traverse",
"version": "1.0.6",
"version": "1.0.7",
"description": "Traverse and manipulate JSON objects.",

@@ -31,4 +31,5 @@ "main": "json-traverse.js",

"devDependencies": {
"eslint": "^8.41.0",
"jest": "^29.2.2"
}
}

@@ -7,3 +7,3 @@ describe('json-traverse test suite', () => {

const originalConsoleLog = console.log;
const testConsoleLog = (output) => { testOutput.push(output) };
const testConsoleLog = (output) => { testOutput.push(output); };

@@ -58,3 +58,3 @@ var simpleTestObj = {};

it('tests a manipulation of plain properties and array entries', async () => {
callbacksChangeValue = {
const callbacksChangeValue = {
processValue: (key, value, level, path, isObjectRoot, isArrayElement, cbSetValue) => {

@@ -83,8 +83,8 @@ if (key.startsWith('My')) {

it('tests a full traversal of a complex JSON object', async () => {
callbacks = {
processValue: (key, value, level, path, isObjectRoot, isArrayElement) => {
const callbacks = {
processValue: (key, value, level, path, _isObjectRoot, _isArrayElement) => {
console.log(level + ' ' + (path.length > 0 ? (path.join('.') + '.') : '') + key + ' = ' + value);
},
enterLevel: (level, path) => { console.log('Entering level ' + level + '...'); },
exitLevel: (level, path) => { console.log('Leaving level ' + level + '...'); }
enterLevel: (level, _path) => { console.log('Entering level ' + level + '...'); },
exitLevel: (level, _path) => { console.log('Leaving level ' + level + '...'); }
};

@@ -133,12 +133,12 @@ jt.traverse(complexTestObj, callbacks);

it('tests a conversion to a HTML list of a complex JSON object', async () => {
callbacksHtml = {
processValue: (key, value, level, path, isObjectRoot, isArrayElement) => {
const callbacksHtml = {
processValue: (key, value, level, path, isObjectRoot, _isArrayElement) => {
if (isObjectRoot) {
console.log((' ').repeat(level) + ' <li class=\"caret\">Key: ' + key + '</li>')
console.log((' ').repeat(level) + ' <li class="caret">Key: ' + key + '</li>');
}
else {
console.log((' ').repeat(level) + ' <li>Key: ' + key + ', Value: ' + value + '</li>')
};
console.log((' ').repeat(level) + ' <li>Key: ' + key + ', Value: ' + value + '</li>');
}
},
enterLevel: (level, path) => {
enterLevel: (level, _path) => {
if (level == 0) {

@@ -148,6 +148,6 @@ console.log('<ul>');

else {
console.log((' ').repeat(level) + '<ul class=\"nested\">');
};
console.log((' ').repeat(level) + '<ul class="nested">');
}
},
exitLevel: (level, path) => { console.log((' ').repeat(level) + '</ul>'); }
exitLevel: (level, _path) => { console.log((' ').repeat(level) + '</ul>'); }
};

@@ -177,3 +177,3 @@ jt.traverse(htmlTestobj, callbacksHtml, true);

jt.traverse(simpleTestObj);
const after = JSON.stringify(simpleTestObj)
const after = JSON.stringify(simpleTestObj);
expect(after).toBe(before);

@@ -186,3 +186,3 @@ expect(testOutput.length).toBe(0);

jt.traverse(complexTestObj);
const after = JSON.stringify(complexTestObj)
const after = JSON.stringify(complexTestObj);
expect(after).toBe(before);

@@ -193,3 +193,3 @@ expect(testOutput.length).toBe(0);

it('tests a manipulation of nested object in an array', async () => {
callbacksChangeValue = {
const callbacksChangeValue = {
processValue: (key, value, level, path, isObjectRoot, isArrayElement, cbSetValue) => {

@@ -207,3 +207,3 @@ if (key == 'array-sub-key') {

it('tests a complete exchange of nested object in an array', async () => {
callbacksChangeValue = {
const callbacksChangeValue = {
processValue: (key, value, level, path, isObjectRoot, isArrayElement, cbSetValue) => {

@@ -215,3 +215,3 @@ if (isArrayElement && isObjectRoot) {

};
expect(JSON.stringify(complexTestObj.parent.array[4])).toBe(JSON.stringify({ "array-sub-key": "zzz", "array-in-array": ["a", "b", "c"] }));
expect(JSON.stringify(complexTestObj.parent.array[4])).toBe(JSON.stringify({ 'array-sub-key': 'zzz', 'array-in-array': ['a', 'b', 'c'] }));
jt.traverse(complexTestObj, callbacksChangeValue);

@@ -222,3 +222,3 @@ expect(JSON.stringify(complexTestObj.parent.array[4])).toBe(JSON.stringify({ objname: 'new-object' }));

it('tests a complete exchange of nested object', async () => {
callbacksChangeValue = {
const callbacksChangeValue = {
processValue: (key, value, level, path, isObjectRoot, isArrayElement, cbSetValue) => {

@@ -225,0 +225,0 @@ if (key == 'child' && !isArrayElement && isObjectRoot) {

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc