How to use the @iarna/toml.stringify function in @iarna/toml

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 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 ChainSafe / lodestar / packages / lodestar / src / util / file.ts View on Github external
export function writeTomlConfig(fileName: string): void {
  const content = stringify(generateTomlConfig(defaults, BeaconNodeOptions));
  try {
    ensureDirectoryExistence(fileName);
    fs.writeFileSync(fileName, content);
  } catch {
    throw new CliError(`Could not write to ${fileName}`);
  }
}
github DavidWells / configorama / lib / parsers / toml.js View on Github external
function dump(object) {
  let toml
  try {
    toml = TOML.stringify(object)
  } catch (e) {
    throw new Error(e)
  }
  return toml
}
github ChatPlug / ChatPlug / src / configWizard / cli / CLICommands.ts View on Github external
const service = new Service()
    service.configured = true
    service.enabled = true
    service.primaryMode = false
    service.instanceName = newInstanceName
    service.moduleName = serviceModule.moduleName

    await serviceRepository.save(service)

    fs.writeFileSync(
      path.join(
        configFolderPath,
        service.moduleName + '.' + service.id + '.toml',
      ),
      TOML.stringify(configuration),
    )

    this.context.coreLogger.info(
      `Created and configured instance ${newInstanceName} of service ${serviceName}`,
    )
  }
github ChatPlug / ChatPlug / src / services / api / controllers / ServicesController.ts View on Github external
const schema = nativeRequire(serviceModule.modulePath).Config
    const fieldList = Reflect.getMetadata(
      fieldListMetadataKey,
      new schema(),
    ) as string[]
    if (!fieldList.every(el => configuration[el] !== undefined)) {
      throw new BadRequestError('Config does not match schema')
    }

    fs.writeFileSync(
      path.join(
        configFolderPath,
        service.moduleName + '.' + service.id + '.toml',
      ),
      TOML.stringify(configuration),
    )

    if (!serviceModule) {
      throw new NotFoundError('Service with given name does not exist')
    }

    service.configured = true

    await this.servicesRepository.save(service)
    if (!this.context.serviceManager.getServiceForId(service.id)) {
      await this.context.serviceManager.loadService(service)
    }
    const serviceModules = await this.context.serviceManager.getAvailableServices()

    service['serviceModule'] = serviceModules.find(
        sm => sm.moduleName === service.moduleName,
github ChatPlug / ChatPlug / src / configWizard / cli / CLICommands.ts View on Github external
}

    const wizard = new CLIConfigWizard()
    const confSchema = nativeRequire(serviceModule.modulePath).Config
    this.context.coreLogger.info(
      `Reconfiguring instance ${newInstanceName} of service ${serviceName}`,
    )
    const configuration: { [x: string]: any } = await wizard.promptForConfig(
      confSchema,
    )
    fs.writeFileSync(
      path.join(
        configFolderPath,
        serviceName + '.' + newInstanceName + '.toml',
      ),
      TOML.stringify(configuration),
    )

    this.context.coreLogger.info('New configuration saved.')
  }

@iarna/toml

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

ISC
Latest version published 5 years ago

Package Health Score

73 / 100
Full package analysis

Popular @iarna/toml functions