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