configstore

  • Version 7.1.0
  • Published
  • 11.2 kB
  • 4 dependencies
  • BSD-2-Clause license

Install

npm i configstore
yarn add configstore
pnpm add configstore

Overview

Easily load and save config without having to think about where and how

Index

Classes

class Configstore

class Configstore {}
  • Easily load and persist config without having to think about where and how.

    The config is stored in a JSON file located in $XDG_CONFIG_HOME or ~/.config. Example: ~/.config/configstore/some-id.json

constructor

constructor(id: string, defaults?: Record<string, unknown>, options?: Options);
  • Parameter id

    Name of your package.

    Parameter defaults

    Default config.

property all

all: Record<string, unknown>;
  • Get all the config as an object or replace the current config with an object.

property path

readonly path: string;
  • Get the path to the config file. Can be used to show the user where the config file is located or even better open it for them.

property size

readonly size: number;
  • Get the item count.

method clear

clear: () => void;
  • Delete all items.

method delete

delete: (key: string) => void;
  • Delete an item.

    Parameter key

    You can use [dot-notation](https://github.com/sindresorhus/dot-prop) in a key to access nested properties.

method get

get: <T = unknown>(key: string) => T | undefined;
  • Get an item.

    Parameter key

    The key of the item to get. You can use [dot-notation](https://github.com/sindresorhus/dot-prop) in a key to access nested properties.

method has

has: (key: string) => boolean;
  • Check if an item exists.

    Parameter key

    You can use [dot-notation](https://github.com/sindresorhus/dot-prop) in a key to access nested properties.

method set

set: {
(key: string, value: unknown): void;
(object: Record<string, unknown>): void;
};
  • Set an item.

    Parameter key

    You can use [dot-notation](https://github.com/sindresorhus/dot-prop) in a key to access nested properties.

    Parameter value

    Must be JSON serializable. Trying to set the type undefined, function, or symbol will result in a TypeError.

  • Set multiple items at once.

    Parameter object

    A hashmap of items to set at once.

Type Aliases

type Options

type Options = {
/**
Store the config at `$CONFIG/package-name/config.json` instead of the default `$CONFIG/configstore/package-name.json`.
This is not recommended as you might end up conflicting with other tools, rendering the "without having to think" idea moot.
@default false
*/
readonly globalConfigPath?: boolean;
/**
Set the path of the config file. Overrides the `packageName` and `globalConfigPath` options.
**Please don't use this option unless absolutely necessary and you know what you're doing.**
*/
readonly configPath?: string;
/**
Clear the config file if it contains invalid JSON. If set to `false`, a `SyntaxError` will be thrown instead of clearing the file. This allows you to recover corrupted config files manually.
@default true
*/
readonly clearInvalidConfig?: boolean;
};

    Package Files (1)

    Dependencies (4)

    Dev Dependencies (2)

    Peer Dependencies (0)

    No peer dependencies.

    Badge

    To add a badge like this onejsDocs.io badgeto your package's README, use the codes available below.

    You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/configstore.

    • Markdown
      [![jsDocs.io](https://img.shields.io/badge/jsDocs.io-reference-blue)](https://www.jsdocs.io/package/configstore)
    • HTML
      <a href="https://www.jsdocs.io/package/configstore"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>