Security News
PyPI’s New Archival Feature Closes a Major Security Gap
PyPI now allows maintainers to archive projects, improving security and helping users make informed decisions about their dependencies.
@stone-js/config
Advanced tools
Fluent and simple API with deep dot access to manage configurations in JavaScript any project
Fluent and simple API with deep dot access to manage configurations in any JavaScript project.
@stone-js/config
is a versatile configuration management library that supports both vanilla JavaScript and TypeScript. It allows developers to easily manage application settings with features like nested configuration access, default value management, and proxy-based custom behavior for configuration properties.
To install the Config
utility, you need to add it to your project. Assuming it’s part of a package you manage.
NPM:
npm i @stone-js/config
Yarn:
yarn add @stone-js/config
PNPM:
pnpm add @stone-js/config
The Config
module can only be imported via ESM import syntax:
import * as Config from '@stone-js/config';
The Config
library is designed to simplify configuration management in JavaScript and TypeScript projects. The library provides a Config
class that allows you to create, access, modify, and clear configuration values, while also providing utility methods for managing defaults and nested properties.
The library is compatible with both vanilla JavaScript and TypeScript, providing strong type safety when used in TypeScript projects.
To use the Config
library, import the Config
class from the installed package:
import { Config } from '@stone-js/config';
You can create a Config
instance with an initial set of configuration values using the Config.create()
method:
import { Config } from '@stone-js/config';
const config = Config.create({
appName: 'MyApp',
settings: {
theme: 'dark',
notifications: true
}
});
You can access configuration values using the get
method. The get
method also allows you to specify a fallback value if the key does not exist:
console.log(config.get('appName')); // Outputs: 'MyApp'
console.log(config.get('settings.theme')); // Outputs: 'dark'
console.log(config.get('settings.language', 'en')); // Outputs: 'en' (fallback value)
You can add or update configuration values using the set
method:
config.set('settings.theme', 'light');
console.log(config.get('settings.theme')); // Outputs: 'light'
You can also set multiple values at once by passing an object:
config.set({
'settings.language': 'fr',
'settings.notifications': false
});
console.log(config.get('settings.language')); // Outputs: 'fr'
To check if a particular configuration value exists, use the has
method:
console.log(config.has('settings.theme')); // Outputs: true
console.log(config.has('settings.nonExistentKey')); // Outputs: false
The defaults
method allows you to set default values for keys that do not already exist:
config.defaults('settings.fontSize', 'medium');
console.log(config.get('settings.fontSize')); // Outputs: 'medium'
You can clear all configuration values using the clear
method:
config.clear();
console.log(config.all()); // Outputs: {}
The Config
class supports accessing and setting nested properties. You can use dot-notation strings to manage nested properties effectively:
console.log(config.get('settings.theme')); // Outputs: 'light'
config.set('settings.newFeature.enabled', true);
console.log(config.get('settings.newFeature.enabled')); // Outputs: true
The @stone-js/config
library is a powerful and flexible solution for managing configuration in JavaScript and TypeScript applications. With support for nested properties, default value handling, and proxy-based custom behaviors, it provides a robust toolset for configuration management.
Key Features:
Start using @stone-js/config
to simplify your application's configuration management and bring flexibility and robustness to your codebase.
See Contributing Guide.
FAQs
Fluent and simple API with deep dot access to manage configurations in JavaScript/TypeScript any project
The npm package @stone-js/config receives a total of 22 weekly downloads. As such, @stone-js/config popularity was classified as not popular.
We found that @stone-js/config demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
PyPI now allows maintainers to archive projects, improving security and helping users make informed decisions about their dependencies.
Research
Security News
Malicious npm package postcss-optimizer delivers BeaverTail malware, targeting developer systems; similarities to past campaigns suggest a North Korean connection.
Security News
CISA's KEV data is now on GitHub, offering easier access, API integration, commit history tracking, and automated updates for security teams and researchers.