How to use the js-yaml.parse function in js-yaml

To help you get started, we’ve selected a few js-yaml 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 AnuraConfig / anura-server / server / constants / configs.js View on Github external
function loadConfig(configs) {
    let configFileObject = {}
    console.log(`reading config file at '${configs.config_file}'`)
    if (configs.config_file) {
        const file = fs.readFileSync(configs.config_file, 'utf8')
        configFileObject = YAML.parse(file)
    }
    config = Object.assign({}, defaultConfig, configFileObject, configs)
    return config
}
github dworthen / js-yaml-front-matter / lib / js-yaml-front.js View on Github external
jsYaml.loadFront = function (context, name) {
  var contents;
  if(fs.existsSync(context)) {
    contents = fs.readFileSync(context, 'utf8');
    if (contents instanceof Error) return contents;
    return jsYaml.parse(contents, name);
  } else if (Buffer.isBuffer(context)) {
    return jsYaml.parse(context.toString(), name);
  } else {
    return jsYaml.parse(context, name);
  }
  return false;
};
github dworthen / js-yaml-front-matter / lib / js-yaml-front.js View on Github external
jsYaml.loadFront = function (context, name) {
  var contents;
  if(fs.existsSync(context)) {
    contents = fs.readFileSync(context, 'utf8');
    if (contents instanceof Error) return contents;
    return jsYaml.parse(contents, name);
  } else if (Buffer.isBuffer(context)) {
    return jsYaml.parse(context.toString(), name);
  } else {
    return jsYaml.parse(context, name);
  }
  return false;
};
github OfficeDev / script-lab / client / src / store / gists / sagas.ts View on Github external
try {
    if (action.payload.gistId) {
      const { response, error } = yield call(github.request, {
        method: 'GET',
        path: `gists/${action.payload.gistId}`,
      })
      if (response) {
        const gistFiles = response.files
        const snippet = YAML.parse(gistFiles[Object.keys(gistFiles)[0]].content)
        const solution = convertSnippetToSolution(snippet)
        yield put(gists.importSnippet.success({ solution }))
      } else {
        throw error
      }
    } else if (action.payload.gist) {
      const snippet = YAML.parse(action.payload.gist)
      const solution = convertSnippetToSolution(snippet)
      yield put(gists.importSnippet.success({ solution }))
    } else {
      throw new Error('Either a gistId or gist must be specified')
    }
  } catch (e) {
    yield put(gists.importSnippet.failure(e))
  }
}
github OfficeDev / script-lab / client / src / store / gists / sagas.ts View on Github external
function* importSnippetSaga(action: ActionType) {
  try {
    if (action.payload.gistId) {
      const { response, error } = yield call(github.request, {
        method: 'GET',
        path: `gists/${action.payload.gistId}`,
      })
      if (response) {
        const gistFiles = response.files
        const snippet = YAML.parse(gistFiles[Object.keys(gistFiles)[0]].content)
        const solution = convertSnippetToSolution(snippet)
        yield put(gists.importSnippet.success({ solution }))
      } else {
        throw error
      }
    } else if (action.payload.gist) {
      const snippet = YAML.parse(action.payload.gist)
      const solution = convertSnippetToSolution(snippet)
      yield put(gists.importSnippet.success({ solution }))
    } else {
      throw new Error('Either a gistId or gist must be specified')
    }
  } catch (e) {
    yield put(gists.importSnippet.failure(e))
  }
}
github dworthen / js-yaml-front-matter / lib / js-yaml-front.js View on Github external
jsYaml.loadFront = function (context, name) {
  var contents;
  if(fs.existsSync(context)) {
    contents = fs.readFileSync(context, 'utf8');
    if (contents instanceof Error) return contents;
    return jsYaml.parse(contents, name);
  } else if (Buffer.isBuffer(context)) {
    return jsYaml.parse(context.toString(), name);
  } else {
    return jsYaml.parse(context, name);
  }
  return false;
};