Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@oclif/core

Package Overview
Dependencies
Maintainers
2
Versions
405
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@oclif/core - npm Package Compare versions

Comparing version 4.0.28 to 4.0.29

2

lib/ux/colorize-json.d.ts

@@ -5,3 +5,3 @@ type Options = {

};
export declare function removeCycles(object: unknown): unknown;
export declare function stringifyInput(json?: unknown, options?: Options): string;
export declare function tokenize(json?: unknown, options?: Options): {

@@ -8,0 +8,0 @@ type: string;

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.removeCycles = removeCycles;
exports.stringifyInput = stringifyInput;
exports.tokenize = tokenize;

@@ -19,42 +19,44 @@ 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];
}
}
function stringify(value, replacer, spaces) {
return JSON.stringify(value, serializer(replacer, replacer), spaces);
}
// Inspired by https://github.com/moll/json-stringify-safe
function serializer(replacer, cycleReplacer) {
const stack = [];
const keys = [];
if (!cycleReplacer)
cycleReplacer = function (key, value) {
if (stack[0] === value)
return '[Circular ~]';
return '[Circular ~.' + keys.slice(0, stack.indexOf(value)).join('.') + ']';
};
return function (key, value) {
if (stack.length > 0) {
// @ts-expect-error because `this` is not typed
const thisPos = stack.indexOf(this);
// @ts-expect-error because `this` is not typed
// eslint-disable-next-line no-bitwise
~thisPos ? stack.splice(thisPos + 1) : stack.push(this);
// eslint-disable-next-line no-bitwise
~thisPos ? keys.splice(thisPos, Number.POSITIVE_INFINITY, key) : keys.push(key);
// @ts-expect-error because `this` is not typed
if (stack.includes(value))
value = cycleReplacer.call(this, key, value);
}
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;
else
stack.push(value);
// @ts-expect-error because `this` is not typed
return replacer ? replacer.call(this, key, value) : value;
};
return _removeCycles(object);
}
function formatInput(json, options) {
return options?.pretty
? JSON.stringify(typeof json === 'string' ? JSON.parse(json) : json, null, 2)
function stringifyInput(json, options) {
const str = options?.pretty
? stringify(typeof json === 'string' ? JSON.parse(json) : json, undefined, 2)
: typeof json === 'string'
? json
: JSON.stringify(json);
: stringify(json);
return str;
}
function tokenize(json, options) {
let input = formatInput(removeCycles(json), options);
let input = stringifyInput(json, options);
const tokens = [];

@@ -61,0 +63,0 @@ let foundToken = false;

{
"name": "@oclif/core",
"description": "base library for oclif CLIs",
"version": "4.0.28",
"version": "4.0.29",
"author": "Salesforce",

@@ -40,3 +40,3 @@ "bugs": "https://github.com/oclif/core/issues",

"@types/indent-string": "^4.0.1",
"@types/mocha": "^10.0.8",
"@types/mocha": "^10.0.9",
"@types/node": "^18",

@@ -43,0 +43,0 @@ "@types/pnpapi": "^0.0.5",

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