Skip to content

Commit 544cd55

Browse files
distribute both commonjs and esm modules
1 parent a8e0337 commit 544cd55

27 files changed

+1458
-894
lines changed

.github/workflows/tests.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ jobs:
2727
- name: Install dependencies
2828
run: npm ci
2929

30+
- name: Build dist
31+
run: npm run build
32+
3033
- name: Run tests with coverage
3134
run: npm run coverage
3235

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ node_modules/
22
.idea/
33
*.zip
44
coverage/
5+
dist

README.md

Lines changed: 38 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,19 @@ A clean class-based API for parsing, editing, and creating INI files.
4242
npm 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');
4758
let 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\na=b\r\n; comment');
86+
const newIni = new Ini('[section]\r\na=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\na=b\r\n\r\n; comment'),
163-
ini2 = new Ini('[section]\r\n\r\na=c\r\n'),
164-
ini3 = new Ini('; global comment\r\n\r\n[section 2]\r\nhello=world');
165-
let mergedIni = Ini.merge(ini1, ini2, ini3);
172+
const ini1 = new Ini('[section]\r\na=b\r\n\r\n; comment');
173+
const ini2 = new Ini('[section]\r\n\r\na=c\r\n');
174+
const ini3 = new Ini('; global comment\r\n\r\n[section 2]\r\nhello=world');
175+
const mergedIni = Ini.merge(ini1, ini2, ini3);
166176
console.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]');
286296
section.addLine('a=b');
287297
section.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]');
304314
section.addLine('a=b');
305315
section.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]');
321331
section.addLines(['a[]=1', 'a[]=2', 'a[]=3']);
322332
section.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]');
339349
section.addLines(['a[]=1', 'a[]=2', 'a[]=3']);
340350
section.setArray('a', [9, 8, 7]);
341351
section.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')
373383
console.log(line.key); // output: 'a'
374384
line.key = 'new key';
375385
console.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')
385395
console.log(line.value); // output: 'b'
386396
line.value = 'new value';
387397
console.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')
397407
console.log(line.comment); // output: 'comment'
398408
line.comment = 'new comment';
399409
console.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')
409419
console.log(line.text); // output: 'a=b ; comment'
410420
line.text = 'new=text ; here';
411421
```

build.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import esbuild from "esbuild";
2+
3+
const commonOptions = {
4+
entryPoints: ["src/index.js"],
5+
bundle: true,
6+
sourcemap: true,
7+
minify: false,
8+
target: "node14",
9+
platform: "node",
10+
};
11+
12+
await esbuild.build({
13+
...commonOptions,
14+
format: "esm",
15+
outfile: "dist/index.mjs",
16+
});
17+
18+
await esbuild.build({
19+
...commonOptions,
20+
format: "cjs",
21+
outfile: "dist/index.cjs",
22+
});
23+
24+
console.log("Build complete: ESM and CJS outputs created.");

jasmine.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"spec_dir": ".",
33
"spec_files": [
4-
"test/**/*.test.js"
4+
"test/runners/*.test.js"
55
],
66
"random": false,
77
"stopSpecOnExpectationFailure": false

0 commit comments

Comments
 (0)