npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

uniparse

v1.0.7

Published

Config parsing library with a unified API for different types of configs.

Downloads

7

Readme

uniparse

Config parsing library with a unified API for different types of configs.

Supported filetypes:

  • Yaml
  • Properties
  • JSON

Usage

Install the module:

npm install uniparse

Use the module:

var uniparse = require('uniparse');

var serverConfig = '/path/to/config/file/server.properties';
uniparse.readConfig(serverConfig, function(err, config) {
	// config is a plain JS object. You can easily JSON encode and decode it and no data will be lost.

	config['server-port'] = 25566;
	config['gamemode'] = 1;

	uniparse.writeConfig(serverConfig, config, function(err) {
		// Saved if there is no error
	});
});

API

uniparse.readConfig(file[, options], callback)

Reads a file as a config and returns the object representation via the callback.

  • file can be either a file path (String) or the file contents as either a String or a Buffer. For the latter please provide the extension and data properties. extension should be the extension of the file (with or without leading dot) and data should be set to true.

The options parameter is optional.

Options:

  • data - Boolean By default readConfig() assumes that the first argument is a file path, if you are prividing a String or a Buffer object with the actual config data this option needs to be set to true. When using this option, make sure to also set the extension option.

  • extension | ext - String This option forces a certain extension to be used. When used uniparse will use the parser for this type of file.

Example:

uniparse.readConfig('{"some": "JSON", "object": true}', {extension: 'json', data: true}, function(err, object) {});

uniparse.writeConfig(file, object[, options], callback)

Writes a config to disk.

Options:

  • extension | ext - String This option forces a certain extension to be used. When used uniparse will use the parser for this type of file.

  • extend - Boolean Will extend the config file with the object. This uses lodash.extend(fileConfig, yourExtension). Extend will overwrite properties that are already defined in the original file.

  • pretty - Boolean Returns a pretty version of the config (where applicable, like JSON). Will prettify by default.

uniparse.stringifyConfig(object[, options], callback)

Stringifies a config object. Useful when sending the config file.

Options:

  • extension | ext - String This option forces a certain extension to be used. When used uniparse will use the parser for this type of file.

  • pretty - Boolean Returns a pretty version of the config (where applicable, like JSON).

Writing your own parser

  • Create a new file in the lib/parsers folder. Make sure to name it something meaningful.
  • Make sure to write the following 4 methods:
    • readConfig(file, options, callback) // Options: none - Reads the config from a file.
    • writeConfig(file, data, options, callback) // Options: extend, pretty - Writes the config to a file
    • parseConfig(string, options, callback) // Options: none - Parses the config from a string.
    • stringifyConfig(object, options, callback) // Options: pretty - Converts a plain JS object to a string.
  • The methods don't need to worry about undefined parameters, the main program handles those.
  • Make sure you pass on the options object to the parsing library, so the user can provide extra options for that too.
  • Export a property called extensions that includes all the extensions you support (without leading dot).
  • Make sure gulp lint doesn't throw errors.
  • Submit a PR.

Exceptions to GPLv2 license

If the config format you're coding is proprietary, you are not required to disclose the source.