UNPKG

yini-parser

Version:

Node.js parser for YINI — a clean, structured INI alternative with types, simple section nesting, comments, and strict mode.

117 lines (113 loc) 4.21 kB
"use strict"; /* https://github.com/YINI-lang/yini-parser-typescript/blob/main/docs/Project-Setup.md Run the code with the following command: npm start or npm run start:dev or npm run start:dev:debug /END */ var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; var _a, _b, _c; Object.defineProperty(exports, "__esModule", { value: true }); exports.parseFile = exports.parse = void 0; const env_1 = require("./config/env"); const print_1 = require("./utils/print"); const YINI_1 = __importDefault(require("./YINI")); exports.parse = YINI_1.default.parse; exports.parseFile = YINI_1.default.parseFile; exports.default = YINI_1.default; (0, print_1.debugPrint)(); (0, print_1.debugPrint)('-> Entered index.ts'); (0, print_1.debugPrint)(); if ((0, env_1.isDev)() || (0, env_1.isDebug)()) { console.log(`process.env?.NODE_ENV = '${(_a = process.env) === null || _a === void 0 ? void 0 : _a.NODE_ENV}'`); console.log(`process.env?.APP_ENV = '${(_b = process.env) === null || _b === void 0 ? void 0 : _b.APP_ENV}'`); console.log(`process.env?.IS_DEBUG = '${(_c = process.env) === null || _c === void 0 ? void 0 : _c.IS_DEBUG}'`); (0, print_1.debugPrint)(); console.log(`localNodeEnv = '${env_1.localNodeEnv}'`); console.log(` localAppEnv = '${env_1.localAppEnv}'`); console.log(' isProdEnv() = ' + (0, env_1.isProdEnv)()); console.log(' isDevEnv() = ' + (0, env_1.isDevEnv)()); console.log(' isTestEnv() = ' + (0, env_1.isTestEnv)()); console.log(); console.log(' isDev() = ' + (0, env_1.isDev)()); console.log(' isDebug() = ' + (0, env_1.isDebug)()); console.log(); } const debugTestObj = { name: 'e_test', lang: 'TypeScript', }; (0, print_1.debugPrint)('debugTestObj:'); (0, print_1.debugPrint)(debugTestObj); (0, print_1.debugPrint)(); if ((0, env_1.isProdEnv)()) { // Do nothing, and exit. } else { if (env_1.localAppEnv === 'local' && env_1.localNodeEnv !== 'test') { // parseUntilError(`^1 SectionName`, false, 2) // const validYini = ` // < user // username = 'tester two' // isSysOp = YES // << prefs // theme = "light" // notifications = OFF // ^1 user2 // ^2 prefs // ^3 deepSection // ^4 deeperSection // key = "Level 4 section" // ^5 yetDeeperSection // key = "Level 5 section" // item = 77 // <1 user3 // username = 'tester three' // isSysOp = NO // <<2 prefs // theme = "special-dark" // notifications = ON // ` // // Act. // const result = parseUntilError(validYini) // debugPrint(result) // const validYini = `^ App // id = 32403 # The correct app id. // title = "My Program" // ` const yini = ` ^ DozNumbers ^^ WithXE doz1 = 0z00 doz2 = 0z01 // One with leading zeros doz3 = 0z100 // Decimal 144 (X/A is digit for 10 in base-12) doz4 = 0z7EE // Decimal 1151 doz5 = 0zX00 // Decimal 1440 (E/B is digit for 11 in base-12) ^^ WithAB doz6 = 0z7BB // Decimal 1151 doz7 = 0zA00 // Decimal 1440 (E/B is digit for 11 in base-12) `; console.log((0, print_1.toPrettyJSON)(YINI_1.default.parse(yini, false))); // console.log( // toPrettyJSON(YINI.parseFile('comprehensive-example.yini', true)), // ) // const fileName = './tests/fixtures/valid/common/common-config-2.yini' // YINI.parseFile(fileName, false) // parseUntilError(` // ^ Section1 // ^^ Section2 // ^^^ Section3 // ^^^^ Section4 // Level 4. // ^^^^^ Section5 // ^^^^^^ Section6 // ^^^^^^^ Section7 // strVar = "These section header are valid!" // `) } }