How to use @iarna/toml - 10 common examples

To help you get started, we’ve selected a few @iarna/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 clio-lang / clio / package / packageConfig.js View on Github external
function getPackageConfig(filepath = path.join(process.cwd(), configFileName)) {
  const file = fs.readFileSync(filepath);
  const packageConfig = toml.parse(file);

  return {
    title: packageConfig.title,
    description: packageConfig.description,
    version: packageConfig.version,
    license: packageConfig.license,
    main: packageConfig.main,
    authors: packageConfig.authors,
    keywords: packageConfig.keywords,
    // eslint-disable-next-line camelcase
    git_repository: packageConfig.git_repository,
    documentation: packageConfig.documentation,

    scripts: packageConfig.scripts,
    dependencies: Object.entries(packageConfig.dependencies).map(dep => {
      return { name: dep[0], version: dep[1] };
github entropic-dev / entropic / cli / lib / load-package-toml.js View on Github external
async function load(dir) {
  do {
    try {
      const src = await fs.readFile(path.join(dir, 'Package.toml'), 'utf8');
      return { location: dir, content: toml.parse(src) };
    } catch (err) {
      if (err.code !== 'ENOENT') {
        throw err;
      }
    }

    const newDir = path.resolve(dir, '..');
    if (newDir === dir) {
      throw new Error('Could not find Package.toml.');
    }

    dir = newDir;
  } while (true); // eslint-disable-line no-constant-condition
}
github Financial-Times / polyfill-library / tasks / node / buildsources.js View on Github external
.then(data => {
				this.config = TOML.parse(data);

				// Each internal polyfill needs to target all supported browsers at all versions.
				if (this.path.relative.startsWith('_')) {
					const supportedBrowsers = Object.keys(UA.getBaselines()).sort((a, b) => a.localeCompare(b));
					if (!supportedBrowsers.every(browser => this.config.browsers[browser] === "*")){
						const browserSupport = {};
						supportedBrowsers.forEach(browser => browserSupport[browser] = "*");
						throw new Error("Internal polyfill called " + this.name + " is not targeting all supported browsers correctly. It should be: \n" + TOML.stringify(browserSupport));
					}
				}

				this.config.detectSource = '';
				this.config.baseDir = this.path.relative;

				if ('licence' in this.config) {
					throw new Error(`Incorrect spelling of license property in ${this.name}`);
				}

				this.config.hasTests = fs.existsSync(path.join(this.path.absolute, 'tests.js'));
				this.config.isTestable = !('test' in this.config && 'ci' in this.config.test && this.config.test.ci === false);
				this.config.isPublic = this.name.indexOf('_') !== 0;

				if (fs.existsSync(this.detectPath)) {
					this.config.detectSource = fs.readFileSync(this.detectPath, 'utf8').replace(/\s*$/, '') || '';
github codeforamerica / civic-tech-taxonomy / import.js View on Github external
tagsCount++;
    }


    // build tree
    const progressBar = new ProgressBar('building tree :percent [:bar] :rate/s :etas', { total: tagsCount });

    for (const prefix in tagsByPrefix) {
        const tags = tagsByPrefix[prefix];

        for (const tag in tags) {
            const tagData = {
                ...tags[tag],
                handle: null
            };
            const toml = TOML.stringify(sortKeys(tagData, { deep: true }));
            const blob = await tree.writeChild(`${prefix}/${tag}.toml`, toml);

            progressBar.tick();
        }
    }

    // write tree
    return await tree.write();
}
github codeforamerica / civic-tech-taxonomy / import.js View on Github external
.on('end', async () => {

                // build tree
                const progressBar = new ProgressBar('building tree :percent [:bar] :rate/s :etas', { total: tags.length });

                for (const tagData of tags) {
                    const category = tagData.category
                        .replace(/\s+/, '-')
                        .replace(/\(s\)/, 's')
                        .toLowerCase();

                    const toml = TOML.stringify(sortKeys({
                        ...tagData,
                        category: null,
                        canonical_name: null,
                        parent: tagData.parent || null,
                        subcategory: tagData.subcategory || null,
                        caption: tagData.caption || null
                    }, { deep: true }));

                    const blob = await tree.writeChild(`${category}/${tagData.canonical_name}.toml`, toml);

                    progressBar.tick();
                }

                tree.write()
                    .then(resolve)
                    .catch(reject);
github Financial-Times / polyfill-library / test / polyfills / updatebrowserstacklist.js View on Github external
automateClient.getBrowsers(function(error, browsers) {
	console.log("Updated the browser list for automated testing via BrowserStack.");
	fs.writeFileSync(path.join(__dirname, "browserstackBrowsers.toml"), TOML.stringify({browsers}));
	fs.writeFileSync(
		path.join(__dirname, "browsers.toml"),
		TOML.stringify({
			browsers: Array.from(new Set(browsers.map(b => (b.browser_version ? `${b.browser}/${b.browser_version}` : `${b.os}/${b.os_version}`)))).sort()
		})
	);
});
github Financial-Times / polyfill-library / test / polyfills / test-individual-feature.js View on Github external
const thirdPartyDependenciesForFeature = filesRequiredByFeature.filter(file => file.endsWith('/config.toml')).map(file => {
        const config = TOML.parse(fs.readFileSync(path.join(__dirname, '../../', file), 'utf-8'));
        return config.install && config.install.module;
    }).filter(thirdPartyPolyfills => thirdPartyPolyfills !== undefined);
github ChatPlug / ChatPlug / src / ChatPlugConfig.ts View on Github external
readConfigForService(service: Service) {
    return TOML.parse(fs.readFileSync(
      path.join(
        configFolderPath,
        service.moduleName + '.' + service.id + '.toml',
      ),
      'utf8',
    ) as string)
  }
github DavidWells / configorama / lib / parsers / toml.js View on Github external
function parse(contents) {
  let object
  try {
    object = TOML.parse(contents)
  } catch (e) {
    throw new Error(e)
  }
  return object
}
github Voxelum / minecraft-launcher-core-node / packages / forge / index.ts View on Github external
async function tomlMetadata(fs: FileSystem, modidTree: ModidTree, manifest: any) {
    const existed = await fs.existsFile("META-INF/mods.toml");
    if (existed) {
        const str = await fs.readFile("META-INF/mods.toml", "utf-8");
        const map = parseToml(str);
        if (map.mods instanceof Array) {
            for (const mod of map.mods) {
                const tomlMod = mod as any;
                const modObject: Partial = {
                    modid: tomlMod.modId,
                    authorList: typeof map.authors === "string" ? [map.authors] : [],
                    version: tomlMod.version === "${file.jarVersion}"
                        ? manifest?.["Implementation-Version"] : tomlMod.version,
                    name: typeof tomlMod.displayName === "string" ? tomlMod.displayName : "",
                    displayName: tomlMod.displayName,
                    description: tomlMod.description,
                    loaderVersion: map.loaderVersion as string,
                    url: typeof map.displayURL === "string" ? map.displayURL : undefined,
                }
                if (typeof modObject.modid === "string") {
                    if (modObject.modid in modidTree) {

@iarna/toml

Better TOML parsing and stringifying all in that familiar JSON interface.

ISC
Latest version published 4 years ago

Package Health Score

73 / 100
Full package analysis

Popular @iarna/toml functions