bitran
Version:
📜 Highly customizable text processor and transpiler.
85 lines (84 loc) • 2.4 kB
JavaScript
var __defProp = Object.defineProperty;
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
import YAML from "yaml";
import { N as Node } from "./group-HQBJ3zxp.js";
function normalizeText(text) {
if (!text)
return text;
text = text.replace(/\r/gm, "");
return text;
}
function textToStrBlocks(text) {
if (!text) return [];
return text.trim().split(/\n^\s*\n(?! |\n|})/gm);
}
function splitFirstLine(text) {
const parts = text.split("\n");
return {
firstLine: parts[0],
restText: parts.slice(1).join("\n")
};
}
function textToObj(text) {
const fallback = {};
try {
const obj = YAML.parse(text);
return Object.getPrototypeOf(obj) === Object.prototype ? obj : fallback;
} catch {
return fallback;
}
}
function indent(text, indentSize = 4) {
return text.replace(/^(.+)$/gm, (match, group) => {
return group.trim() ? " ".repeat(indentSize) + group : match;
});
}
function tryParseInt(text) {
const parsedInt = parseInt(text);
return Number.isNaN(parsedInt) ? text : parsedInt;
}
var ProductLayout = /* @__PURE__ */ ((ProductLayout2) => {
ProductLayout2["Block"] = "block";
ProductLayout2["Inliner"] = "inliner";
return ProductLayout2;
})(ProductLayout || {});
class ProductNode extends Node {
constructor() {
super(...arguments);
__publicField(this, "layout");
__publicField(this, "parseData");
__publicField(this, "renderData");
__publicField(this, "generated", {});
__publicField(this, "meta", {});
}
getId() {
var _a, _b;
return ((_a = this.meta) == null ? void 0 : _a.id) || ((_b = this.generated) == null ? void 0 : _b.autoId) || null;
}
}
class BlockNode extends ProductNode {
constructor() {
super(...arguments);
__publicField(this, "layout", "block");
}
}
class InlinerNode extends ProductNode {
constructor() {
super(...arguments);
__publicField(this, "layout", "inliner");
}
}
export {
BlockNode as B,
InlinerNode as I,
ProductLayout as P,
ProductNode as a,
tryParseInt as b,
textToStrBlocks as c,
indent as i,
normalizeText as n,
splitFirstLine as s,
textToObj as t
};
//# sourceMappingURL=productNode-C0XZsQy2.js.map