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
undefined
as the value are skipped unless configured otherwise.
opt
is an optional options object that supports these keys:
sort
: Whether and how to sort sections (ifsectSort
is false-y) and/or keys (ifkeySort
is 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, overridesort
with respect to sections.keySort
: If truthy, overridesort
with 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 suppressundefined
values (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
undefined
means "keep the original value", andnull
means "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 befalse
to add header lines for all sections. Default:'\n'
dod2ini.cfg(opt)
return { return ; };
Usage
see test.usage.js.
Known issues
- Needs more/better tests and docs.
License
ISC