UNPKG

@intlayer/core

Version:

Includes core Intlayer functions like translation, dictionary, and utility functions shared across multiple packages.

82 lines 2.82 kB
"use strict"; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __hasOwnProp = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); var getMarkdownMetadata_exports = {}; __export(getMarkdownMetadata_exports, { getMarkdownMetadata: () => getMarkdownMetadata }); module.exports = __toCommonJS(getMarkdownMetadata_exports); const parseToObject = (input) => { let normalizedInput = input.trim().replace(/^\[/, "[").replace(/^\{/, "{").replace(/\]$/, "]").replace(/\}$/, "}").replace(/([\w\d_]+)\s*:/g, '"$1":').replace(/:\s*([a-zA-Z_][\w\d_]*)/g, ': "$1"'); normalizedInput = normalizedInput.replace( /\[([^\[\]]+?)\]/g, (_match, arrayContent) => { const newContent = arrayContent.split(",").map((item) => { const trimmed = item.trim(); if (trimmed.startsWith('"') && trimmed.endsWith('"') || !isNaN(Number(trimmed))) { return trimmed; } return `"${trimmed}"`; }).join(", "); return `[${newContent}]`; } ); return JSON.parse(normalizedInput); }; const getMarkdownMetadata = (markdown) => { try { const lines = markdown.split(/\r?\n/); const firstNonEmptyLine = lines.find((line) => line.trim() !== ""); if (!firstNonEmptyLine || firstNonEmptyLine.trim() !== "---") { return {}; } const metadata = {}; let inMetadataBlock = false; for (const line of lines) { const trimmedLine = line.trim(); if (trimmedLine === "---") { if (!inMetadataBlock) { inMetadataBlock = true; continue; } else { break; } } if (inMetadataBlock) { const match = line.match(/^([^:]+)\s*:\s*(.*)$/); if (match) { const key = match[1].trim(); const value = match[2].trim(); try { metadata[key] = parseToObject(value); } catch (e) { metadata[key] = value; } } } } return metadata; } catch (e) { return void 0; } }; // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { getMarkdownMetadata }); //# sourceMappingURL=getMarkdownMetadata.cjs.map