How to use toml - 10 common examples

To help you get started, we’ve selected a few toml 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 numenta / numenta-web / numenta.org / gatsby-node.js View on Github external
// Numenta.org HTM Community website source code
// MIT License (see LICENSE.txt)
// Copyright © 2005—2016 Numenta 

import {createSitemap} from 'sitemap'
import ExtractTextPlugin from 'extract-text-webpack-plugin'
import FaviconsPlugin from 'favicons-webpack-plugin'
import fs from 'fs'
import htmlToText from 'html2plaintext'
import {ncp} from 'ncp'
// import {resolve} from 'path'
import toml from 'toml'

const config = toml.parse(fs.readFileSync(`${__dirname}/config.toml`))

// Default max of 10 EventEmitters is not enough for our MainSections, bump up.
require('events').EventEmitter.prototype._maxListeners = 20  // eslint-disable-line max-len, no-underscore-dangle

/**
 * Gatsby.js Node server-side specific functions.
 *  1. modifyWebpackConfig()
 *  2. postBuild()
 * @see https://github.com/gatsbyjs/gatsby#structure-of-a-gatsby-site
 */
/* eslint-disable no-console */


/**
 * Gatsby augment WebPack loaders config.
 * @param {Object} webpack - Previous Gatsby Webpack Configurator object
github vuejs / vuepress / packages / @vuepress / core / lib / node / loadConfig.js View on Github external
function parseConfig (file) {
  const content = fs.readFileSync(file, 'utf-8')
  const [extension] = /.\w+$/.exec(file)
  let data

  switch (extension) {
  case '.yml':
  case '.yaml':
    data = yamlParser.safeLoad(content)
    break

  case '.toml':
    data = tomlParser.parse(content)
    // reformat to match config since TOML does not allow different data type
    // https://github.com/toml-lang/toml#array
    const format = []
    if (data.head) {
      Object.keys(data.head).forEach(meta => {
        data.head[meta].forEach(values => {
          format.push([meta, values])
        })
      })
    }
    data.head = format
    break
  }

  return data || {}
}
github tjson / tjson.js / test / example_loader.ts View on Github external
let result = examples.map((example, index) => {
      let exampleParts = example.split(/\n\s*\n/m);
      let headerToml = exampleParts.shift();
      let body = exampleParts.shift();

      if (headerToml === undefined || body == undefined) {
        throw new Error(`error parsing whitespace in example ${index}`);
      }

      let header = toml.parse(headerToml);
      let name = header["name"];
      let description = header["description"];

      if (name === undefined || description === undefined) {
        throw new Error(`missing mandatory fields in header of example ${index}`);
      }

      let success;

      switch (header["result"]) {
        case "success":
          success = true;
          break;
        case "error":
          success = false;
          break;
github netlify / netlify-lambda / lib / config.js View on Github external
exports.load = function() {
  var configPath = path.join(process.cwd(), 'netlify.toml');
  if (!fs.existsSync(configPath)) {
    console.error(
      'No netlify.toml found. This is needed to configure the function settings. For more info: https://github.com/netlify/netlify-lambda#installation'
    );
    process.exit(1);
  }

  return toml.parse(fs.readFileSync(configPath));
};
github qgp9 / Vuetalisk / src / config.js View on Github external
addString (data, ext, _path) {
    if (!data) return
    let config
    try {
      if(ext === '.yaml' || ext === '.yml') {
        const yaml = require('js-yaml')
        config = yaml.safeLoad(data)
      } else if (ext === '.toml' || ext === '.tml') {
        const toml = require('toml')
        config = toml.parse(data)
      } else if (ext === '.json') {
        config = JSON.parse(data)
      }
    } catch (e) {
      console.error(`Errors while parsing config`)
      if (_path) console.error(`in  file ${_path}`)
      throw Error(e)
    }
    this._merge(config)
  }
github linksmart / border-gateway / bgw-external-interface / config.js View on Github external
dest_port: 5051,
                dest_address: "127.0.0.1"
            },
            {
                name: "websocket-proxy",
                bind_addresses: ["0.0.0.0"],
                bind_port: 9002,
                dest_port: 5052,
                dest_address: "127.0.0.1"
            }
        ]
};

let configFromFile = {};
try {
    configFromFile = toml.parse(fs.readFileSync('./config/config.toml'));
}
catch(e)
{
    console.log("Problem reading ./config/config.toml");
}

if(configFromFile[config.serviceName]) {
    Object.assign(config, configFromFile[config.serviceName]);
}

module.exports = config;
github be5invis / Iosevka / verdafile.js View on Github external
async function tryParseToml(str) {
	try {
		return toml.parse(fs.readFileSync(str, "utf-8"));
	} catch (e) {
		throw new Error(
			`Failed to parse configuration file ${str}.\n` +
				`Please validate whether there's syntax error.\n` +
				`${e}`
		);
	}
}
github facebookarchive / atom-ide-ui / modules / nuclide-commons-atom / ProjectManager.js View on Github external
function parseProject(raw: string): any {
  try {
    return toml.parse(raw);
  } catch (err) {
    if (err.name === 'SyntaxError') {
      return season.parse(raw);
    }
    throw err;
  }
}
github Sn8z / Poddr / node_modules / read-config-file / out / main.js View on Github external
async function readConfig(configFile) {
  const data = await (0, _fsExtraP().readFile)(configFile, "utf8");
  let result;

  if (configFile.endsWith(".json5") || configFile.endsWith(".json")) {
    result = require("json5").parse(data);
  } else if (configFile.endsWith(".toml")) {
    result = require("toml").parse(data);
  } else {
    result = (0, _jsYaml().safeLoad)(data);
  }

  return {
    result,
    configFile
  };
}

toml

TOML parser for Node.js (parses TOML spec v0.4.0)

MIT
Latest version published 5 years ago

Package Health Score

65 / 100
Full package analysis

Popular toml functions