@oclif/core
Advanced tools
Comparing version 4.0.27 to 4.0.28
@@ -5,2 +5,3 @@ type Options = { | ||
}; | ||
export declare function removeCycles(object: unknown): unknown; | ||
export declare function tokenize(json?: unknown, options?: Options): { | ||
@@ -7,0 +8,0 @@ type: string; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.removeCycles = removeCycles; | ||
exports.tokenize = tokenize; | ||
@@ -18,2 +19,33 @@ exports.default = colorizeJson; | ||
]; | ||
function removeCycles(object) { | ||
// Keep track of seen objects. | ||
const seenObjects = new WeakMap(); | ||
const _removeCycles = (obj) => { | ||
// Use object prototype to get around type and null checks | ||
if (Object.prototype.toString.call(obj) === '[object Object]') { | ||
// We know it is a "Record<string, unknown>" because of the conditional | ||
const dictionary = obj; | ||
// Seen, return undefined to remove. | ||
if (seenObjects.has(dictionary)) | ||
return; | ||
seenObjects.set(dictionary, undefined); | ||
for (const key in dictionary) { | ||
// Delete the duplicate object if cycle found. | ||
if (_removeCycles(dictionary[key]) === undefined) { | ||
delete dictionary[key]; | ||
} | ||
} | ||
} | ||
else if (Array.isArray(obj)) { | ||
for (const i in obj) { | ||
if (_removeCycles(obj[i]) === undefined) { | ||
// We don't want to delete the array, but we can replace the element with null. | ||
obj[i] = null; | ||
} | ||
} | ||
} | ||
return obj; | ||
}; | ||
return _removeCycles(object); | ||
} | ||
function formatInput(json, options) { | ||
@@ -27,3 +59,3 @@ return options?.pretty | ||
function tokenize(json, options) { | ||
let input = formatInput(json, options); | ||
let input = formatInput(removeCycles(json), options); | ||
const tokens = []; | ||
@@ -30,0 +62,0 @@ let foundToken = false; |
{ | ||
"name": "@oclif/core", | ||
"description": "base library for oclif CLIs", | ||
"version": "4.0.27", | ||
"version": "4.0.28", | ||
"author": "Salesforce", | ||
@@ -6,0 +6,0 @@ "bugs": "https://github.com/oclif/core/issues", |
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
402176
10128