Socket
Book a DemoInstallSign in
Socket

@quase/config

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@quase/config

Configuration utilities

0.1.0
latest
Source
npmnpm
Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

@quase/config

About

Provides utilities to get configuration (from a file or package.json), apply defaults and validate options.

import { getConfig, applyDefaults, t, validate, printError } from "@quase/config";

const schema = {
  foo: {
    type: "boolean",
    deprecated: true
  },
  bar: {
    type: "boolean",
    default: true
  },
  object: {
    type: t.object( {
      prop: {
        type: "number",
        example: 10
      }
    } )
  },
  tuple: {
    type: t.tuple( [
      {
        type: "string"
      },
      {
        type: "string"
      }
    ] )
  },
  array: {
    // Array of numbers
    type: t.array( {
      type: "number"
    } ),
    merge: "concat"
  },
  value: {
    choices: [ 0, 1, 2 ]
  }
};

const config = getConfig( {
  cwd: process.cwd(),
  configFiles: [],
  configKey: "",
  failIfNotFound: false
} );

const options = applyDefaults( schema, config ); // The first object passed (after schema) takes precedence

try {
  validate( schema, options );
} catch ( e ) {
  printError( e );
}

Merge mode

It is used to customize how values are merged when applying defaults and merging multiple objects.

  • "override": Just sets the value without merging.
  • "merge": If they are arrays, merge them.
  • "concat": If they are arrays, just concats them.
  • "spreadMeansConcat": If they are arrays, concat them when the value with higher precedence has "..." as its first element.
  • You can also provide a function of the form ( obj, src ) => any.

FAQs

Package last updated on 17 Feb 2018

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

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.