Skip to content

Commit

Permalink
feat: add INI API
Browse files Browse the repository at this point in the history
  • Loading branch information
antongolub committed Jul 6, 2022
1 parent f12141a commit b633945
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 2 deletions.
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,20 @@ await copy({
})
```

### `INI`
Provides [INI API](https://github.com/npm/ini#readme).
```js
import {INI} from 'zx-extra'

const ini = `[database]
user = dbuser
password = dbpassword
`
const parsed = INI.parse(ini)
parsed.database.user // 'dbuser'
INI.stringify(parsed, {whitespace: true}) // ini
```

### `SSRI`
Exposes [SSRI API](https://github.com/npm/ssri#readme)
```js
Expand Down
2 changes: 1 addition & 1 deletion src/main/js/goods.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export * as tempy from 'tempy'
export { default as ip } from 'ip'
export { semver, SSRI } from './reexport.mjs'
export { semver, SSRI, INI } from './reexport.mjs'
export { default as tcping } from 'is-reachable'
export { copy } from 'globby-cp'
1 change: 1 addition & 0 deletions src/main/js/reexport.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ const reexport = (name) => require(join(

export const semver = reexport('semver')
export const SSRI = reexport('ssri')
export const INI = reexport('ini')
13 changes: 12 additions & 1 deletion src/test/js/test.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {strict as assert} from 'node:assert'
import {$, semver, createHook, ip, tempy, tcping, ctx, copy, fs, path, SSRI} from '../../main/js/index.mjs'
import {$, semver, createHook, ip, tempy, tcping, ctx, copy, fs, path, SSRI, INI} from '../../main/js/index.mjs'

// $.verbose
{
Expand Down Expand Up @@ -44,6 +44,17 @@ import {$, semver, createHook, ip, tempy, tcping, ctx, copy, fs, path, SSRI} fro
assert.equal(parsed.toString(), integrity)
}

// INI
{
const ini = `[database]
user = dbuser
password = dbpassword
`
const parsed = INI.parse(ini)
assert.equal(parsed.database.user, 'dbuser')
assert.equal(INI.stringify(parsed, {whitespace: true}), ini)
}

// opt
{
const nothrow = $.opt({nothrow: true})
Expand Down

0 comments on commit b633945

Please sign in to comment.