1.0.3 • Published 4 years ago

create-settings v1.0.3

Weekly downloads
2
License
MIT
Repository
github
Last release
4 years ago

Create Settings

Typesafe and lightweight tool for working with settings

npm version CircleCI codecov

Installation

npm i create-settings
# or
yarn add create-settings

Problem

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,

Usage

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);

API

createSettings(defaultSettings)

Create new settings object

Options:

NameTypeDescriptionDefault
defaultSettings[setting: string]: anyArray of AxiosLayer, this is the only required optionnone

Settings.configure

Configure settings object, you can provide function for configuration, or configure it inline i.e.

settings
  .configure()
  .setting1('value')
  .setting2('value2');

Settings.configureAsync

The same as configure but works with Promise API

Testing

  1. You can create factory and call that in tests

    const createUserSettings = () => createSettings({
      setting: 'settings'
    })

    and in each test create it with needed values,

  2. 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

Licence

MIT

1.0.2

4 years ago

1.0.3

4 years ago

1.0.1

4 years ago

0.0.1

4 years ago

1.0.0

4 years ago