1.1.0 • Published 3 years ago
tiny-configs v1.1.0
tiny-configs
Simple config files
npm i tiny-configsUsage
You have a config file like this:
config.txt
# this is a comment
key1
key2 # another comment
key3const 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 value3split 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