1.0.0 • Published 6 years ago

loose-text-configs v1.0.0

Weekly downloads
4
License
GPL-3.0
Repository
github
Last release
6 years ago

loose-text-configs

Stop hand-writing JSON for configurations that you can easily process like it's text! Small helper library that processes a multi-line string, ignoring empty lines and trims spacing, and runs a function for each line.

yarn add loose-text-configs

Example

import createConfig from 'loose-text-configs';
createConfig(
    `
    ADJ = JJR JJS
    BW = RBR RBS WRB
    LID = DT PDT WDT
    VG = CC
    `, 
    line => {
        let [dutchCode, enCodes] = line.split(' = ')
        enCodes.split(' ').map(code => {
            en2nlCodeMapping[code] = dutchCode
        })
    }
)

/*
Returns:

{
 "JJR": "ADJ",
 "JJS": "ADJ",
 "RBR": "BW",
 "RBS": "BW",
 "WRB": "BW",
 "DT": "LID",
 "PDT": "LID",
 "WDT": "LID",
 "CC": "VG"
}
*/