plist2
Version:
Converts between .tmLanguage(.plist), .json, .cson and .yaml formats
68 lines (65 loc) • 2.18 kB
JavaScript
/* eslint-disable */
/*
dester builds:
js2json.ts
*/
;
Object.defineProperty(exports, '__esModule', {
value: true
});
var lib = require('../lib');
/* filename: js2json.ts
timestamp: 2024-12-13T15:18:07.204Z */
var __js2json__ = (source, indent, deep) => {
deep++;
var INDENT = lib.__EMPTY__;
var NEW_LINE = lib.__EMPTY__;
var INDENT_LAST = lib.__EMPTY__;
var SEPARATOR = indent ? ' ' : lib.__EMPTY__;
var res = lib.__EMPTY__;
var isMod;
var arr = [];
if (lib.isArray(source)) {
source.forEach(v => {
if (!isMod && (lib.isArray(v) || lib.isObject(v))) {
isMod = true;
INDENT = lib.setIndent(indent, deep);
NEW_LINE = indent ? '\n' : lib.__EMPTY__;
INDENT_LAST = lib.setIndent(indent, deep - 1);
SEPARATOR = lib.__EMPTY__;
}
arr.push(__js2json__(v, indent, deep));
});
res = '[' + arr.map(v => NEW_LINE + INDENT + v).join(',' + SEPARATOR) + NEW_LINE + INDENT_LAST + ']';
} else if (lib.isObject(source)) {
NEW_LINE = SEPARATOR;
lib.keys(source).forEach(k => {
if (k !== lib.__COMMENTS_KEY__) {
if (!isMod && (lib.isArray(source[k]) || lib.isObject(source[k]))) {
isMod = true;
INDENT = lib.setIndent(indent, deep);
NEW_LINE = indent ? '\n' : lib.__EMPTY__;
INDENT_LAST = lib.setIndent(indent, deep - 1);
}
arr.push([lib.jsonStringify(k) + ':', __js2json__(source[k], indent, deep)]);
}
});
res = '{' + arr.map(v => NEW_LINE + INDENT + v[0] + SEPARATOR + v[1]).join(',') + NEW_LINE + INDENT_LAST + '}';
// } else if (source && source[__BINARY64_KEY__]) {
// res =
// '{' +
// SEPARATOR +
// jsonStringify(__BINARY64_KEY__) +
// ':' +
// SEPARATOR +
// jsonStringify(source[__BINARY64_KEY__]) +
// SEPARATOR +
// '}'
} else {
res = lib.jsonStringify(source, null, indent);
}
return res;
};
// prettier-ignore
var js2json = (source, indent = 2) => __js2json__(source, !indent ? lib.__EMPTY__ : indent === +indent ? lib.repeat(' ', indent) : lib.__EMPTY__ + indent, 0);
exports["default"] = js2json;