UNPKG

yini-parser

Version:

Readable configuration without YAML foot-guns or JSON noise. The official Node.js parser for YINI config format — An INI-inspired configuration format with clear nesting, explicit types, and predictable parsing.

40 lines 1.74 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const env_1 = require("../config/env"); const print_1 = require("../utils/print"); const parseStringLiteral = (raw) => { (0, print_1.debugPrint)('-> Entered parseStringLiteral(..)'); (0, print_1.debugPrint)('raw = >>>' + raw + '<<<'); /* Extracts an optional prefix (C, c, H, or h) and identifies whether the string is triple-quoted, double-quoted, or single-quoted. */ const prefixMatch = raw.match(/^(C|c|H|h|R|r)?("""|"|')/); (0, print_1.debugPrint)('prefixMatch:'); if ((0, env_1.isDebug)()) { console.debug(prefixMatch); } let prefix = prefixMatch ? prefixMatch[1]?.toUpperCase() : ''; (0, print_1.debugPrint)(' prefix = ' + prefix); let quoteType = prefixMatch ? prefixMatch[2] : ''; (0, print_1.debugPrint)(' quoteType = ' + quoteType); (0, print_1.debugPrint)('quoteType.length = ' + quoteType.length); // Extracts the substring after removing the initial prefix (if any) // and quotes at the start (prefix.length + quoteType.length) and the // quotes at the end (-quoteType.length). let inner = raw.slice((prefix?.length || 0) + quoteType.length, -quoteType.length); (0, print_1.debugPrint)('inner (raw) = ' + inner); if (prefix === 'C') { inner = inner .replace(/\\n/g, '\n') .replace(/\\t/g, '\t') .replace(/\\r/g, '\r'); } else if (prefix === 'H') { inner = inner.replace(/[\s\n\r]+/g, ' ').trim(); } (0, print_1.debugPrint)('inner (reformat) = ' + inner); return inner; }; exports.default = parseStringLiteral; //# sourceMappingURL=parseString.js.map