PHP WebShell

Текущая директория: /opt/BitGoJS/node_modules/nx/src/utils

Просмотр файла: json.js

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.serializeJson = exports.parseJson = exports.stripJsonComments = void 0;
const jsonc_parser_1 = require("jsonc-parser");
Object.defineProperty(exports, "stripJsonComments", { enumerable: true, get: function () { return jsonc_parser_1.stripComments; } });
const lines_and_columns_1 = require("lines-and-columns");
const code_frames_1 = require("./code-frames");
/**
 * Parses the given JSON string and returns the object the JSON content represents.
 * By default javascript-style comments and trailing commas are allowed.
 *
 * @param input JSON content as string
 * @param options JSON parse options
 * @returns Object the JSON content represents
 */
function parseJson(input, options) {
    try {
        return JSON.parse(input);
    }
    catch (_a) { }
    options = Object.assign({ allowTrailingComma: true }, options);
    const errors = [];
    const result = (0, jsonc_parser_1.parse)(input, errors, options);
    if (errors.length > 0) {
        throw new Error(formatParseError(input, errors[0]));
    }
    return result;
}
exports.parseJson = parseJson;
/**
 * Nicely formats a JSON error with context
 *
 * @param input JSON content as string
 * @param parseError jsonc ParseError
 * @returns
 */
function formatParseError(input, parseError) {
    const { error, offset, length } = parseError;
    let { line, column } = new lines_and_columns_1.LinesAndColumns(input).locationForIndex(offset);
    line++;
    column++;
    return (`${(0, jsonc_parser_1.printParseErrorCode)(error)} in JSON at ${line}:${column}\n` +
        (0, code_frames_1.codeFrameColumns)(input, {
            start: { line, column },
            end: { line, column: column + length },
        }) +
        '\n');
}
/**
 * Serializes the given data to a JSON string.
 * By default the JSON string is formatted with a 2 space indentation to be easy readable.
 *
 * @param input Object which should be serialized to JSON
 * @param options JSON serialize options
 * @returns the formatted JSON representation of the object
 */
function serializeJson(input, options) {
    var _a;
    return JSON.stringify(input, null, (_a = options === null || options === void 0 ? void 0 : options.spaces) !== null && _a !== void 0 ? _a : 2) + '\n';
}
exports.serializeJson = serializeJson;
//# sourceMappingURL=json.js.map

Выполнить команду


Для локальной разработки. Не используйте в интернете!