diff --git a/README.md b/README.md index 246eac6..a2ce22a 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,6 @@ # jsonkdiff -![Build status](https://github.com/grrtbrtr/jsonkdiff/actions/workflows/test.yml/badge.svg) -![NPM version](https://img.shields.io/npm/v/@grrtbrtr/jsonkdiff) +![NPM version](https://img.shields.io/npm/v/@grrtbrtr/jsonkdiff?color=blue) ![License](https://img.shields.io/github/license/grrtbrtr/jsonkdiff) ![Build](https://img.shields.io/github/actions/workflow/status/grrtbrtr/jsonkdiff/test.yml) ![Bundle size](https://img.shields.io/bundlephobia/min/@grrtbrtr/jsonkdiff) A lightweight, zero-dependency CLI tool to compare multiple JSON files and identify missing (non-common) keys. It generates a per-file report of unique keys to help identify schema drift. diff --git a/package-lock.json b/package-lock.json index c86a021..e7db798 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@grrtbrtr/jsonkdiff", - "version": "1.0.1", + "version": "1.0.2", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@grrtbrtr/jsonkdiff", - "version": "1.0.1", + "version": "1.0.2", "license": "GPL-3.0-only", "bin": { "jsonkdiff": "bin/cli.js" diff --git a/package.json b/package.json index 54d1e6a..a894515 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@grrtbrtr/jsonkdiff", - "version": "1.0.1", + "version": "1.0.2", "description": "Compare multiple JSON files and find non-common keys. Generates a per-file report of unique keys to help identify schema drift.", "keywords": [ "json", diff --git a/src/utils/object-utils.js b/src/utils/object-utils.js index 180dc3e..3019813 100644 --- a/src/utils/object-utils.js +++ b/src/utils/object-utils.js @@ -7,14 +7,17 @@ * @returns {Array.} An array of keys. */ export function getDeepKeys(obj, prefix = '') { - let keys = []; - for (const key in obj) { + return Object.keys(obj).reduce((allKeys, key) => { const fullPath = prefix ? `${prefix}.${key}` : key; - keys.push(fullPath); - - if (typeof obj[key] === 'object' && obj[key] !== null && !Array.isArray(obj[key])) { - keys = keys.concat(getDeepKeys(obj[key], fullPath)); + allKeys.push(fullPath); + + if ( + typeof obj[key] === 'object' && + obj[key] !== null && + !Array.isArray(obj[key]) + ) { + allKeys.push(...getDeepKeys(obj[key], fullPath)); } - } - return keys; + return allKeys; + }, []); } \ No newline at end of file