New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

dsl-config

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

dsl-config

Generate a DSL config with generators

  • 1.0.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
decreased by-100%
Maintainers
1
Weekly downloads
 
Created
Source

dsl-config

Build Status Coverage Status

Generate an asynchronous DSL to generate a configuration object

Install

npm install dsl-config

Usage

Define the DSL (note that methods are chainable but have been spaced out here to accomodate comments)

const DSLConfig = require('dsl-config');

// create an instance
const dslConfig = new DSLConfig();

// define some values
dslConfig
.value('value1');
.value('value2');

// and lists of values
dslConfig
.list('list1');
.list('list2');

// you can define a DSL for a value or list
const subDSLConfig = new DSLConfig();
subDSLConfig
.value('value1');
.value('value2');
dslConfig.value('value3', subDSLConfig);

// you can reuse DSLs
dslConfig.list('list3', subDSLConfig);

// you can clone and extend or override DSLs
const cloneDSLConfig = new DSLConfig(subDSLConfig);

// override value2 to convert it to a list
cloneDSLConfig.list('value2');

// extend with value3
cloneDSLConfig.value('value3');

dslConfig.value('value4', cloneDSLConfig);

The above would generate a DSL to create a configuration object with the following possible structure

{
  value1: 'value',
  value2: 'value',
  list1: [
    'value',
    'value'
  ],
  list2: [
    'value',
    'value'
  ],
  value3: {
    value1: 'value',
    value2: 'value'
  },
  list3: [{
    value1: 'value',
    value2: 'value'
  }, {
    value1: 'value',
    value2: 'value'
  }],
  value4: {
    value1: 'value',
    value2: [
      'value',
      'value'
    ],
    value3: 'value'
  }
}

Then to synchronously create a configuration

const config = dslConfig.configure(config => {
  config
  .value1('value')
  .value2('value')
  .list1('value')
  .list1('value')
  .list2('value')
  .list2('value')
  .value3(value3 => {
    value3
    .value1('value')
    .value2('value');
  })
  .list3(list3 => {
    list3
    .value1('value')
    .value2('value');
  })
  .list3(list3 => {
    list3
    .value1('value')
    .value2('value');
  })
  .value4(value4 => {
    value4
    .value1('value')
    .value2('value')
    .value2('value')
    .value3('value');
  });
});

You can also use generators to asynchronously create a configuration (when asynchronous, #configure will actually return a Promise)

dslConfig.configure(function * (dsl) {
  dsl = yield config.value3(function * (value3) {
    // etc...
  });
  // etc...
}).then(config => {
  // do something with config
});

Or the DSL callbacks can return promises

dslConfig.configure(dsl => {
  return dsl.value3(value3 => {
    return Promise.resolve()
    .then(() => {
      // etc...
    });
  })
  .then(dsl => {
    // etc...
  });
}).then(config => {
  // do something with config
});

NB. Any fields not set using #configure will be left undefined

Keywords

FAQs

Package last updated on 18 Jul 2016

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc