@@ -42,8 +42,19 @@ A clean class-based API for parsing, editing, and creating INI files.
4242npm i ini-api
4343```
4444
45+ Note: As of v2.0.1, this library ships with both ESM and CommonJS builds. Use whichever import style matches your project.
46+
47+ ### Using ES modules (recommended)
48+ ``` js
49+ import { Ini , IniSection , IniLine , lineTypes } from ' ini-api' ;
50+
51+ const myIni = new Ini (' ; ini text here' );
52+ ```
53+
54+ ### Using CommonJS
55+
4556``` javascript
46- let {Ini, IniSection, IniLine, lineTypes} = require (' ini-api' );
57+ let { Ini, IniSection, IniLine, lineTypes } = require (' ini-api' );
4758let myIni = new Ini (' ; ini text here' );
4859```
4960
@@ -64,20 +75,19 @@ The new Ini.
6475
6576** examples:**
6677``` javascript
78+ import { Ini } from ' ini-api' ;
79+ import fs from ' fs' ;
80+ import path from ' path' ;
81+
6782// creates an empty Ini file
68- let emptyIni = new Ini ();
83+ const emptyIni = new Ini ();
6984
7085// creates an ini file with a section named "section"
71- let newIni = new Ini (' [section]\r\n a=b\r\n ; comment' );
86+ const newIni = new Ini (' [section]\r\n a=b\r\n ; comment' );
7287
7388// loading an ini file from disk
74- let fs = require (' fs' ),
75- path = require (' path' );
76-
77- let filePath = path .resolve (__dirname , ' config.ini' ),
78- text = fs .readFileSync (filePath);
79-
80- let configIni = new Ini (text);
89+ const text = fs .readFileSync (' config.ini' );
90+ const configIni = new Ini (text);
8191```
8292
8393### ` getSection(name) `
@@ -159,10 +169,10 @@ The new merged Ini.
159169
160170** examples:**
161171``` javascript
162- let ini1 = new Ini (' [section]\r\n a=b\r\n\r\n ; comment' ),
163- ini2 = new Ini (' [section]\r\n\r\n a=c\r\n ' ),
164- ini3 = new Ini (' ; global comment\r\n\r\n [section 2]\r\n hello=world' );
165- let mergedIni = Ini .merge (ini1, ini2, ini3);
172+ const ini1 = new Ini (' [section]\r\n a=b\r\n\r\n ; comment' );
173+ const ini2 = new Ini (' [section]\r\n\r\n a=c\r\n ' );
174+ const ini3 = new Ini (' ; global comment\r\n\r\n [section 2]\r\n hello=world' );
175+ const mergedIni = Ini .merge (ini1, ini2, ini3);
166176console .log (mergedIni .stringify ());
167177/*
168178; global comment
@@ -191,10 +201,10 @@ The new IniSection.
191201** examples:**
192202``` javascript
193203// creates an empty IniSection with no name or lines
194- let emptySection = new IniSection (' ' );
204+ const emptySection = new IniSection (' ' );
195205
196206// creates a section named "section"
197- let section = new IniSection (' [section]' );
207+ const section = new IniSection (' [section]' );
198208```
199209
200210### ` addLine(text) `
@@ -282,7 +292,7 @@ The value of the IniLine if present. Returns undefined if a matching line wasn'
282292
283293** examples:**
284294``` javascript
285- let section = new IniSection (' [section]' );
295+ const section = new IniSection (' [section]' );
286296section .addLine (' a=b' );
287297section .getValue (' a' ); // returns b
288298```
@@ -300,7 +310,7 @@ The matching IniLine if present. Returns undefined if a matching line wasn't fo
300310
301311** examples:**
302312``` javascript
303- let section = new IniSection (' [section]' );
313+ const section = new IniSection (' [section]' );
304314section .addLine (' a=b' );
305315section .getValue (' a' ); // returns b
306316```
@@ -317,7 +327,7 @@ An array of the values found. Returns an empty array if no matching lines were
317327
318328** examples:**
319329``` javascript
320- let section = new IniSection (' [section]' );
330+ const section = new IniSection (' [section]' );
321331section .addLines ([' a[]=1' , ' a[]=2' , ' a[]=3' ]);
322332section .getArray (' a' ); // returns [1, 2, 3]
323333```
@@ -335,7 +345,7 @@ An array of the created IniLines.
335345
336346** examples:**
337347``` javascript
338- let section = new IniSection (' [section]' );
348+ const section = new IniSection (' [section]' );
339349section .addLines ([' a[]=1' , ' a[]=2' , ' a[]=3' ]);
340350section .setArray (' a' , [9 , 8 , 7 ]);
341351section .getArray (' a' ); // returns [9, 8, 7]
@@ -357,10 +367,10 @@ The new IniLine.
357367
358368** examples:**
359369``` javascript
360- let blankLine = new IniLine (' ' );
361- let commentLine = new IniLine (' ; comment' );
362- let headerLine = new IniLine (' [header]' );
363- let pairLine = new IniLine (' key = value ; comment' );
370+ const blankLine = new IniLine (' ' );
371+ const commentLine = new IniLine (' ; comment' );
372+ const headerLine = new IniLine (' [header]' );
373+ const pairLine = new IniLine (' key = value ; comment' );
364374```
365375
366376### ` key `
@@ -369,7 +379,7 @@ Getter/setter for line key. Note: attempting to set the key of a line that does
369379
370380** examples:**
371381``` javascript
372- let line = new IniLine (' a=b ; comment' )
382+ const line = new IniLine (' a=b ; comment' )
373383console .log (line .key ); // output: 'a'
374384line .key = ' new key' ;
375385console .log (line .text ); // output: new key=b ; comment
@@ -381,7 +391,7 @@ Getter/setter for line value. Note: attempting to set the value of a line that
381391
382392** examples:**
383393``` javascript
384- let line = new IniLine (' a=b ; comment' )
394+ const line = new IniLine (' a=b ; comment' )
385395console .log (line .value ); // output: 'b'
386396line .value = ' new value' ;
387397console .log (line .text ); // output: a=new value ; comment
@@ -393,7 +403,7 @@ Getter/setter for line comment. Set to an empty string to remove a comment from
393403
394404** examples:**
395405``` javascript
396- let line = new IniLine (' a=b ; comment' )
406+ const line = new IniLine (' a=b ; comment' )
397407console .log (line .comment ); // output: 'comment'
398408line .comment = ' new comment' ;
399409console .log (line .text ); // output: a=b ; new comment
@@ -405,7 +415,7 @@ Getter/setter for line text.
405415
406416** examples:**
407417``` javascript
408- let line = new IniLine (' a=b ; comment' )
418+ const line = new IniLine (' a=b ; comment' )
409419console .log (line .text ); // output: 'a=b ; comment'
410420line .text = ' new=text ; here' ;
411421```
0 commit comments