openapi-minifier
Version:
A CLI tool by Treblle tp minify OpenAPI V3 Specs by removing redundant information not relevant to AI Agents and LLMs.
59 lines • 2.34 kB
JavaScript
import pc from 'picocolors';
export const colors = {
red: pc.red,
green: pc.green,
yellow: pc.yellow,
blue: pc.blue,
cyan: pc.cyan,
gray: pc.gray,
bold: pc.bold,
};
export function getTreblleAsciiArt() {
const asciiArt = `
████████╗██████╗ ███████╗██████╗ ██╗ ██╗ ███████╗
╚══██╔══╝██╔══██╗██╔════╝██╔══██╗██║ ██║ ██╔════╝
██║ ██████╔╝█████╗ ██████╔╝██║ ██║ █████╗
██║ ██╔══██╗██╔══╝ ██╔══██╗██║ ██║ ██╔══╝
██║ ██║ ██║███████╗██████╔╝███████╗███████╗███████╗
╚═╝ ╚═╝ ╚═╝╚══════╝╚═════╝ ╚══════╝╚══════╝╚══════╝`;
const tagline = ' API Intelligence platform - https://treblle.com';
return colors.blue(asciiArt) + '\n\n' + colors.gray(tagline);
}
export function isObject(value) {
return value !== null && typeof value === 'object' && !Array.isArray(value);
}
export function deepClone(obj) {
if (obj === null || typeof obj !== 'object')
return obj;
if (obj instanceof Date)
return new Date(obj.getTime());
if (Array.isArray(obj))
return obj.map(deepClone);
if (typeof obj === 'object') {
const cloned = {};
for (const key in obj) {
if (Object.prototype.hasOwnProperty.call(obj, key)) {
cloned[key] = deepClone(obj[key]);
}
}
return cloned;
}
return obj;
}
export function countNestedKey(obj, key) {
let count = 0;
if (isObject(obj)) {
if (key in obj)
count++;
for (const value of Object.values(obj)) {
count += countNestedKey(value, key);
}
}
else if (Array.isArray(obj)) {
for (const item of obj) {
count += countNestedKey(item, key);
}
}
return count;
}
//# sourceMappingURL=utils.js.map