parse.js
function parse (src, path) {
  const pathSep = typeof path === 'string' ? path : '.'
  return parseLines(src).reduce((res, line) => {
    if (Array.isArray(line)) {
      const [key, value] = line
      if (path) {
        const keyPath = key.split(pathSep)
        let parent = res
        while (keyPath.length >= 2) {
          const p = keyPath.shift()
          if (!parent[p]) {
            parent[p] = {}
          } else if (typeof parent[p] !== 'object') {
            parent[p] = { '': parent[p] }
          }
          parent = parent[p]
        }
        const leaf = keyPath[0]
        if (typeof parent[leaf] === 'object') {
          parent[leaf][''] = value
        } else {
          parent[leaf] = value
        }
      } else {
        res[key] = value
      }
    }
    return res
  }, {})
}
function parse (src, path) {
  const pathSep = typeof path === 'string' ? path : '.'
  return parseLines(src).reduce((res, line) => {
    if (Array.isArray(line)) {
      const [key, value] = line
      if (path) {
        const keyPath = key.split(pathSep)
        let parent = res
        while (keyPath.length >= 2) {
          const p = keyPath.shift()
          if (!parent[p]) {
            parent[p] = {}
          } else if (typeof parent[p] !== 'object') {
            parent[p] = { '': parent[p] }
          }
          parent = parent[p]
        }
        const leaf = keyPath[0]
        if (typeof parent[leaf] === 'object') {
          parent[leaf][''] = value
        } else {
          parent[leaf] = value
        }
      } else {
        res[key] = value
      }
    }
    return res
  }, {})
}
function parse ( src , path ) { const pathSep = typeof path === 'string' ? path : '.' return parseLines ( src ) . reduce ( ( res , line ) => { if ( Array . isArray ( line ) ) { const [ key , value ] = line if ( path ) { const keyPath = key . split ( pathSep ) let parent = res while ( keyPath . length >= 2 ) { const p = keyPath . shift ( ) if ( ! parent [ p ] ) { parent [ p ] = { } } else if ( typeof parent [ p ] !== 'object' ) { parent [ p ] = { '' : parent [ p ] } } parent = parent [ p ] } const leaf = keyPath [ 0 ] if ( typeof parent [ leaf ] === 'object' ) { parent [ leaf ] [ '' ] = value } else { parent [ leaf ] = value } } else { res [ key ] = value } } return res } , { } ) }
Parses an input string read from a .properties file into a JavaScript Object

If the second `path` parameter is true, dots '.' in keys will result in a
multi-level object (use a string value to customise). If a parent level is
directly assigned a value while it also has a child with an assigned value,
the parent value will be assigned to its empty string '' key. Repeated keys
will take the last assigned value. Key order is not guaranteed, but is likely
to match the order of the input lines.

@param {string} src
@param {boolean | string} [path=false]
Parses an input string read from a . properties file into a JavaScript Object