2.0.2 • Published 5 months ago

indexed-config v2.0.2

Weekly downloads
-
License
MIT
Repository
github
Last release
5 months ago

indexed-config

Indexed Config Wrapper

Installation

yarn add indexed-config -D

Usage

import { IndexedConfig, TypedJSONObject, ConfigScheme } from '@tdio/indexed-config'

const spec = {
  name: 'Indexed Config', // alias of { value: 'Indexed Config' }
  auth: {
    type: 'object'
  },
  count: {
    type: 'number',
    getter () {
      return '255'
    }
  },
  uiEmbed: {
    type: 'boolean',
    getter () {
      return process.env.NODE_ENV === 'development'
    }
  },
  settings: {
    foo: 'str',
    bar: 100
  }
}

const cfg = new IndexedConfig(null, spec)

cfg.get('name')     // Indexed Config
cfg.get('count')    // 255
cfg.get('auth')     // undefined
cfg.get('uiEmbed')  // true when NODE_ENV='development'

cfg.apply({
  auth: {
    token: 'test'
  },
  count: 1024 // no effect (computer property)
})

cfg.get('auth')         // { token: 'test' }
cfg.get('count')        // 255, as it's a computed property (with getter)
cfg.get('settings.bar') // 100

cfg.set('settings.bar', 200)
cfg.get('settings')     // get bundle  { foo: 'str', bar: 200 }
cfg.get('settings.bar') // 200

cfg.entries()

License

MIT Copyright (c) tdio