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.

78 lines 4.2 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const env_1 = require("./config/env"); const errorDataHandler_1 = require("./core/errorDataHandler"); const optionsFunctions_1 = require("./core/options/optionsFunctions"); const runtime_1 = require("./core/runtime"); const print_1 = require("./utils/print"); const DEFAULT_TAB_SIZE = 4; // De facto "modern default" (even though traditionally/historically it's 8). /** * This class is the public API, which exposes only parse(..) and * parseFile(..), rest of the implementation details are hidden. * @note Only parse and parseFile are public. */ class YINI { /** * @returns The number of spaces per tab character used in error messages. */ static getTabSize() { return this.g_tabSize; } /** * Overrides the number of spaces per tab character used in error messages. * Allowed range: 1-32. */ static setTabSize(spaces) { if (spaces < 1 || spaces > 32) { new errorDataHandler_1.ErrorDataHandler('None/Ignore').pushOrBail(null, 'Fatal-Error', `Invalid tab size ${spaces} is out of range.`, 'Tab size must be between 1 and 32 spaces.'); throw new RangeError(`Tab size ${spaces} is out of range (1–32).`); } this.g_tabSize = spaces; } // --- Single implementation -------------------------------------------- // Implementation method (not declared with arrow function) for both method overload signatures. // NOTE: Must be method declaration with NO =, arrow functions not (currently) supported for this type of method overloading. static parse(yiniContent, arg2, // strictMode | options failLevel = 'auto', includeMetadata = false) { (0, print_1.debugPrint)('-> Entered static parse(..) in class YINI\n'); (0, print_1.debugPrint)(); (0, print_1.debugPrint)('==== Call runParse(..) in runtime =========================='); const runtime = new runtime_1.YiniRuntime('Inline'); const result = (0, optionsFunctions_1.isOptionsObjectForm)(arg2) ? runtime.runParse(yiniContent, arg2) // Overload #2: (content, options) : runtime.runParse( // Overload #1: (content, strict?, failLevel?, includeMeta?) yiniContent, arg2, failLevel, includeMetadata); (0, print_1.debugPrint)('==== End call parse ==========================\n'); if ((0, env_1.isDev)()) { console.log(); (0, print_1.devPrint)('YINI.parse(..): result:'); console.log(result); (0, print_1.devPrint)('Complete result:'); (0, print_1.printObject)(result); } return result; } // --- Single implementation -------------------------------------------- // Implementation method (not declared with arrow function) for both method overload signatures. // NOTE: Must be method declaration with NO =, arrow functions not (currently) supported for this type of method overloading. static parseFile(filePath, arg2, // strictMode | options failLevel = 'auto', includeMetadata = false) { (0, print_1.debugPrint)('-> Entered static parseFile(..) in class YINI\n'); (0, print_1.debugPrint)('Current directory = ' + process.cwd()); (0, print_1.debugPrint)(); (0, print_1.debugPrint)('==== Call doParseFile(..) in runtime =========================='); const runtime = new runtime_1.YiniRuntime('File'); const result = (0, optionsFunctions_1.isOptionsObjectForm)(arg2) ? runtime.doParseFile(filePath, arg2) // Overload #2: (content, options) : runtime.doParseFile( // Overload #1: (content, strict?, failLevel?, includeMeta?) filePath, arg2, failLevel, includeMetadata); (0, print_1.debugPrint)('==== End call parse ==========================\n'); return result; } } // @todo In future move/change this to not be a global and suffer from possible race conditions, possibly move this into YiniRuntime class. YINI.g_tabSize = DEFAULT_TAB_SIZE; // Global tab size used in error messages. exports.default = YINI; //# sourceMappingURL=YINI.js.map