1.1.0 • Published 1 year ago

tiny-configs v1.1.0

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

tiny-configs

Simple config files

npm i tiny-configs

Usage

You have a config file like this:

config.txt

# this is a comment
key1
key2 # another comment
key3
const configs = require('tiny-configs')

const file = await fs.promises.readFile('./config.txt')
const config = configs.parse(file)
console.log(config) // => ['key1', 'key2', 'key3']

Split

key-value.txt

name1 value1
name2
name3 value3

split the line values by spaces:

const config = configs.parse(file, { split: ' ' })
// => [['name1', 'value1'], ['name2'], ['name3', 'value3']]

length option filters out lines that don't reach the total amount of values:

const config = configs.parse(file, { split: ' ', length: 2 })
// => [['name1', 'value1'], ['name3', 'value3']]

API

const config = configs.parse(Buffer | String, [options])

Available options:

{
  split: null,
  length: 0,
  allowEmpty: false
}

License

MIT