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.

339 lines (325 loc) 10.8 kB
"use strict"; /* * This includes of dev / debug / demo / custom-tesing code. * * https://github.com/YINI-lang/yini-parser-typescript/blob/main/docs/Project-Setup.md * * Run this code with the following commands: * npm run start:dev * or * npm run start:dev:debug */ var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const env_1 = require("../config/env"); const print_1 = require("../utils/print"); const YINI_1 = __importDefault(require("../YINI")); const defect_inputs_1 = require("./quick-test-samples/defect-inputs"); require("./quick-test-samples/valid-inputs"); // validConfigComplex, (0, print_1.debugPrint)(); (0, print_1.debugPrint)('-> Entered dev/main.ts'); (0, print_1.debugPrint)(); if ((0, env_1.isDev)() || (0, env_1.isDebug)()) { console.log(`process.env?.NODE_ENV = '${process.env?.NODE_ENV}'`); console.log(`process.env?.APP_ENV = '${process.env?.APP_ENV}'`); console.log(`process.env?.IS_DEBUG = '${process.env?.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 = ` @yini ^ NumberFormats ^^ HexFormat // Hexadecimal (base-16) hex = #FF0066 // Default notation altHex = 0xFF0066 // Alternative notation ^^ BinFormat // Binary (base-2) bin = %10101111 // Default notation altBin = 0b10101111 // Alternative notation ^^ OctFormat // Octal (base-8) oct = 0o755 // ( = decimal 493) ^^ DozFormat // Duodecimal (base-12) doz = 0z10XE // Default notation: X=10, E=11 altDoz = 0z10AB // Alternative notation: A=10, B=11 ` // End. */ /* const yini = ` @yini @YINI ///dfsf < User nullKey = nullKey2 = NULL username = 'tester two' userId = 234 userColor = #ffaa99 userPerm = 0O733 userFearues = %01101 isSysOp = YES map = { a: 3, b: 4, cc: 5, \`d d\`: 3453 } listValueB: 3, 4, 5 listValue2 = ["a", "b"] listValue3 = [434] listValue4 = [] listValue5 = [1, ["a", "b", "c", [null, TRUE]], 3] --listObject = { a: 1, b: 2} colonList: 1, 2, 3, << Prefs theme = "light" notifications = OFF nullValue = NULL ^1 User2 ^2 PrefsOfUser2 ^3 DeepSection ^4 DeeperSection key = "Level 4 section" ^5 YetDeeperSection key = "Level 5 section" item = 77 <1 User3 username = 'tester three' isSysOp = NO <2 Prefs2 theme = "special-dark" notifications = ON <2 Special value = 123 ` */ // npm run start:dev // "timing": { // "totalMs": 158.421, // "phase1Ms": 151.36, // "phase2Ms": 6.92, // "phase3Ms": 0.14 // } //console.log(toPrettyJSON(YINI.parse(yini, false, 'auto', true))) // const yini = ` // < SubTitle // theme = "special-dark" // notifications = ON // < SubTitle // NOT OK, SubTitle already exists // theme2 = "special-dark" // ` /* const errorYini = ` ^ Section1 333="oops" // invalid key => error ` const warnYini = ` ^ Section2 // => warning, if requireDocTerminator: 'warn-if-missing' ` console.log( toPrettyJSON( YINI.parse( ` ^ App title = 'My App' items = 25 darkMode = true // "ON"/"YES" also work ^^ Special primaryColor = #336699 keywords = [ "alpha", "beta", "release" ] `, { // failLevel: 'errors', throwOnError: false, // requireDocTerminator: 'warn-if-missing', strictMode: true, silent: false, includeMetadata: true, }, ), ), ) */ // const yini = ` // /*sdfsdf*/ // @yini // @include 'sdf' // --@invalid // @deprecated // ^ window // --^^ window2 // title = 'Sample Window' // Strings can be enclosed in either ' or ". // @deprecated // id = 'window_main' // // @bla // --@include 'wrongplace' // --@yini // This is an error should be catched in the parser. // /end // ` // YINI.setTabSize(2) // debugPrint('tab size = ' + YINI.getTabSize()) // const yini = ` @yini // --@yini // ^ Header // INVALID: Must start with atleast one 1-level section. // key = 33254 // /END // --/END // ` // console.log( // toPrettyJSON( // YINI.parse(yini, { // strictMode: false, // failLevel: 'errors', // includeMetadata: false, // requireDocTerminator: 'optional', // }), // ), // ) // const yini = ` // ^ Booleans // bool1 = true // bool2 = false // bool3 = on // bool4 = off // bool5 = yes // bool6 = no // ` // const yiniContent = `#!/usr/bin/env yini // ^ App // name = "Shebang-demo"` const yiniContent = ` #!/usr/bin/env yini ^ App name = "Shebang-demo"`; console.log('--!!!------------------------------------------'); console.log((0, print_1.toPrettyJSON)( // YINI.parse(validConfig, { YINI_1.default.parse(defect_inputs_1.defectConfig2Combo3, { strictMode: true, failLevel: 'ignore-errors', includeMetadata: true, includeDiagnostics: true, // requireDocTerminator: 'optional', }))); // console.log('--!!!------------------------------------------') // console.log( // toPrettyJSON( // // YINI.parse(validConfig, { // YINI.parse(defectConfigCombo3, { // strictMode: true, // // failLevel: 'auto', // failLevel: 'ignore-errors', // includeMetadata: true, // includeDiagnostics: true, // // requireDocTerminator: 'optional', // }), // ), // ) // console.log( // toPrettyJSON( // YINI.parseFile( // 'comprehensive-example.yini', // false, // 'auto', // true, // ), // ), // ) // const result: YiniParseResult = YINI.parseFile( // 'comprehensive-example.yini', // { includeMetadata: true }, // ) // console.log(toPrettyJSON('' + result.meta)) // console.log( // toPrettyJSON( // YINI.parseFile('comprehensive-example.yini', { // strictMode: false, // failLevel: 'auto', // includeMetadata: true, // }), // ), // ) // const fileName = './tests/fixtures/invalid/corrupt-config-2.yini' // const result = YINI.parseFile(fileName, { // strictMode: true, // failLevel: 'ignore-errors', // }) // printObject(result) // let parserOptions: any = getDefaultUserOptions('lenient') // debugPrint('** parserOptions: (lenient)') // isDebug() && printObject(parserOptions) // isDebug() && // console.log( // 'derived mode = ' + matchModeFromParseOptions(parserOptions), // ) // parserOptions = getDefaultUserOptions('strict') // debugPrint('** parserOptions: (strict)') // isDebug() && printObject(parserOptions) // isDebug() && // console.log( // 'derived mode = ' + // matchModeFromCoreOptions(toCoreOptions(parserOptions)), // ) // const fileName = // './tests/fixtures/invalid/bad-user-profile-config-2.yini' // YINI.parseFile(fileName, { // strictMode: false, // failLevel: 'auto', // includeMetadata: true, // }) } } //# sourceMappingURL=main.js.map