โจparse .ini file
Last updated
Was this helpful?
Last updated
Was this helpful?
Was this helpful?
JS โฉ value โฉ object โฉ regex โฉ example โฉ parse .ini file
// using "ini" package from npm
const { parse: parseINI } = require("ini");
parseINI("x = 10\ny = 20"), // { x: '10', y: '20' }
replit โฉ parse .ini file, INIParser (old code)
// โญ .ini file format
// ---------------------------
// 1. Blank lines and lines starting with semicolons are ignored.
// 2. Lines wrapped in [ and ] start a new section.
// 3. Lines containing an alphanumeric identifier followed by an = character
// add a setting to the current section.
// 4. Anything else is invalid.
function parseINI(string) {
let result = {}; // object to hold the top-level fields
๐็ฏไพ๏ผ
// โญ example of an .ini file
const ini = `
; comments are preceded by a semicolon...
; [sectionName] starts a new section.
; 'key=value' adds a new setting to current section.
game=God Of War
[larry]
fullname=Larry Doe
type=kindergarten bully
[davaeorn]
fullname=Davaeorn
type=evil wizard`;
// test run
parseINI(ini) // string -> object
// {
// game: 'God Of War',
// larry: { fullname: 'Larry Doe', type: 'kindergarten bully' },
// davaeorn: { fullname: 'Davaeorn', type: 'evil wizard' }
// }