parse-string.js 415 B

123456789101112131415161718
  1. 'use strict'
  2. module.exports = parseString
  3. const TOMLParser = require('./lib/toml-parser.js')
  4. const prettyError = require('./parse-pretty-error.js')
  5. function parseString (str) {
  6. if (global.Buffer && global.Buffer.isBuffer(str)) {
  7. str = str.toString('utf8')
  8. }
  9. const parser = new TOMLParser()
  10. try {
  11. parser.parse(str)
  12. return parser.finish()
  13. } catch (err) {
  14. throw prettyError(err, str)
  15. }
  16. }