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

@dorianb/config-js

v0.1.3

Published

A simple library for NodeJS to deal with config files

Downloads

3

Readme

Config library

npm version npm version

Installation

To install the package, just run : bash npm install --save @dorianb/config-js

Then in the .js file :

const Config = require('@dorianb/config-js')

const config = new Config('path/to/the/config')

if (config.exists('key')) {
    let value = config.get('key')
    config.set('key', value)
}

Documentation

Classes

Typedefs

Config

new Config(name, opts)

constructor - create or retrieve a configuration

Returns: Config - the config object

| Param | Type | Description | | --- | --- | --- | | name | string | the name of the config (also the name of the file) | | opts | OptionsObject | |

Example

const keybindings = new Config('keybindings')
const settings = new Config('settings.json')

config.save()

save - Save the config file

Example

config.save()

config.getContent() ⇒ JSON5

getContent - get the parsed content of the file

Returns: JSON5 - the JSON5 content of the file
Example

let fileContent = config.getContent() // --> {_name: 'settings', ....}

config.set(key, value) ⇒ Config

set - Set an config value

Chainable
Throws:

  • ConfigKeyError

| Param | Type | | --- | --- | | key | string | | value | string |

Example

config.set('property', 'some value')
config.set(randomObject)
config
   .set({position: {x:1, y:5}})
   .set('speed', {vx: 2, vy: 0})

config.get(key) ⇒ any

get - Get a key of the config

Returns: any - the value associated with the key

| Param | Type | | --- | --- | | key | string |

Example

config.get()      // --> return the whole config
config.get('key') // --> value

config.exists(key) ⇒ boolean

exists - If a key exists

| Param | Type | | --- | --- | | key | string |

Example

config.exists('key') // --> true/false

config.toJSON() ⇒ JSON

toJSON - Convert the config to a JSON compatible format

Returns: JSON - The JSON object
Example

const JsonConfig = config.toJSON()

Config.version ⇒ string

Returns: string - The version of the library
Example

const version = Config.version --> 0.1.1

Config.create(name, opts) ⇒ Config

Chainable
Returns: Config - the config object

| Param | Type | Description | | --- | --- | --- | | name | string | the name of the config (also the name of the file) | | opts | OptionsObject | |

Example

const settings = Config.create('settings', {extension: '.config'}) // same as `new Config(...)`

OptionsObject : Object

Properties

| Name | Type | Default | Description | | --- | --- | --- | --- | | [extension] | string | "'json5'" | The extensions to use | | [filename] | string | "'config.json5'" | The name of the default config file | | [folder] | string | "'./config'" | The folder of the default config file | | [overwrite] | boolean | false | If the file should be re-create during initialization |


2020 © Dorian Beauchesne