dict-of-dicts-to-ini-lines-pmb
v1.0.3
Published
Translate your dictionary object of dictionary objects to an array of strings that could be lines of a .ini file.
Readme
dict-of-dicts-to-ini-lines-pmb
Translate your dictionary object of dictionary objects to an array of strings that could be lines of a .ini file.
API
This module exports one function that holds some methods:
dod2ini(sectionsDict[, opt])
Where sectionsDict is an object that maps section titles to dictionaries
that will be used as the key-value-pairs.
- Array values are processed by repeating the key for each value.
- But only if they are encountered directly in the 2nd level dictionary.
- Pairs with
undefinedas the value are skipped unless configured otherwise.
opt is an optional options object that supports these keys:
sort: Whether and how to sort sections (ifsectSortis false-y) and/or keys (ifkeySortis false-y). This does not affect the order of multiple values for one key. Iftrue, sort with default algorithm. Any another truthy value is assumed to be, and used as, a custom comparison function.sectSort: If truthy, overridesortwith respect to sections.keySort: If truthy, overridesortwith respect to keys.eol: Append this string to each line. Defaults to empty string.pairSep: Put this string between key and value. Defaults to'='.pairInd: Put this string before the key. Defaults to the empty string.translateValues: If truthy, try to translate values. This can be used to not suppressundefinedvalues (by translating them to e.g. the empty string), and to suppress unwanted values (by translating them toundefined).- If set to a function, it will be invoked with arguments
(val, key, sect). - If set to an object or Array, translate empty string values and non-string,
values by property lookup.
- Objects are stringified for this lookup, and thus can masquerade as other values. Just avoid using objects or nested Arrays as values.
- A result of
undefinedmeans "keep the original value", andnullmeans "skip this pair".
- If set to a function, it will be invoked with arguments
skipSectionName: If string, omit section header line for the section with this name. Can also befalseto add header lines for all sections. Default:'\n'
dod2ini.cfg(opt)
return function custom(sectionsDict) { return dod2ini(sectionsDict, opt); };Usage
see test.usage.js.
Known issues
- Needs more/better tests and docs.
License
ISC
