0.9.1 • Published 2 years ago

@straw-hat/chainable-config v0.9.1

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

@straw-hat/chainable-config

Use a chaining API to generate and simplify the modification of configurations.

Usage

import {
  ChainedMap,
  OrderableChainedMap,
  ChainedSet,
} from '@straw-hat/chainable-config';

const chainedMap = new ChainedMap();

// ..or

export class DevServer<P> extends ChainedMap<P> {
  bonjour(value: boolean) {
    return this.set('bonjour', value);
  }
}

class Resolve<P> extends ChainedMap<P> {
  constructor(parent: P) {
    super(parent);
    this.set('extensions', new OrderableChainedMap(this, {
      // Its allows you to return the configuration as an array rather than an
      // object
      asArray: true,
      // Its allows you to return undefined in case there is not values set
      emptyAsUndefined: true,
    }))
  }
}

class WebpackChain extends ChainedMap {
  // your own methods here..
  constructor() {
    super(undefined);
    this.set('devServer', new DevServer(this));
    this.set('resolve', new Resolve(this));
  }

  get devServer(): DevServer<WebpackChain> {
    return this.get('devServer');
  }

  bail(value: boolean) {
    return this.set('bail', value);
  }
}

const myConfig = new WebpackChain();

myConfig.bail(true).devServer.bonjour(true);

// Return the config
myConfig.toConfig();
// {
//   bail: true,
//   devServer: {
//     bonjour: true
//   }
// }
0.9.1

2 years ago

0.9.0

3 years ago

0.8.0

3 years ago

0.7.1

3 years ago

0.7.0

3 years ago

0.5.0

3 years ago

0.6.0

3 years ago

0.4.0

3 years ago

0.3.0

3 years ago

0.2.0

3 years ago

0.1.0

4 years ago

0.0.1

4 years ago