How to use the @uiengine/util/src/parsing.fromFile function in @uiengine/util

To help you get started, we’ve selected a few @uiengine/util examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github dennisreimann / uiengine / packages / cli / src / yaml.js View on Github external
const parseString = (string, filename, sourcePaths) => {
  try {
    const IncludeYamlType = includeYamlType(filename, sourcePaths)
    const DataYamlType = dataYamlType(filename, sourcePaths)
    const schema = yaml.Schema.create([IncludeYamlType, DataYamlType, MarkdownYamlType])
    const json = true // duplicate keys in a mapping will override values rather than throwing an error

    return yaml.safeLoad(string.trim(), { schema, filename, json })
  } catch (err) {
    throw new UiengineInputError(['Could not parse YAML!', markSample(string)], err)
  }
}

const fromFileSync = R.partial(parsing.fromFileSync, [parseString])
const fromFile = R.partial(parsing.fromFile, [parseString])
const fromString = R.partial(parsing.fromString, [parseString])

module.exports = {
  parseString,
  fromFileSync,
  fromFile,
  fromString
}
github dennisreimann / uiengine / packages / cli / src / frontmatter.js View on Github external
}

  if (i === lines.length) { // second '---' is missing; assume entire `str` is body
    return bodyOnly
  }

  return {
    attributes: attributes.length ? YamlUtil.parseString(attributes.join(NEWLINE), filename, sourcePaths) : {},
    body: lines.slice(i + 1).join(NEWLINE)
  }
}

const parseString = (string, filename, sourcePaths) =>
  fastmatter(string.trim(), filename, sourcePaths)

const fromFile = R.partial(ParsingUtil.fromFile, [parseString])

const fromString = R.partial(ParsingUtil.fromString, [parseString])

module.exports = {
  parseString,
  fromFile,
  fromString
}