Typesafe and lightweight tool for working with settings
npm i create-settings
# or
yarn add create-settings
You need configurable module that will be configured in runtime with different values those depend on environment, you want it to be typesafe, lightweight and easy to use,
import createSettings from 'create-settings';
const settings = createSettings({
userMoney: 100,
userName: 'Jack',
});
// variant 1
settings
.configure()
.userMoney(100)
.userName('Tom');
// variant 2
function configureTomUser(configurator) {
configurator.userMoney(100).userName('Tom');
}
settings.configure(configureTomUser);
Create new settings object
Options:
Name | Type | Description | Default |
---|---|---|---|
defaultSettings | [setting: string]: any |
Object with default settings | none |
Configure settings object, you can provide function for configuration, or configure it inline i.e.
settings
.configure()
.setting1('value')
.setting2('value2');
The same as configure but works with Promise API
-
You can create factory and call that in tests
const createUserSettings = () => createSettings({ setting: 'settings' })
and in each test create it with needed values,
-
You can just export settings object and in test reset it in beforeEach hook
Library export ExtractSettingsObject
helper type in case when you need to get type of settings object itself
MIT