Socket
Book a DemoInstallSign in
Socket

normalize-config

Package Overview
Dependencies
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

normalize-config

Normalize a declarative configuration with any combination of src-dest mappings, files arrays, files objects and options into a consistent format. Uses globule to expand glob patterns and rte for dynamically generating destination paths. Inspired by Grunt

Source
npmnpm
Version
0.3.1
Version published
Weekly downloads
73
-13.1%
Maintainers
1
Weekly downloads
 
Created
Source

normalize-config NPM version

Normalize a declarative configuration with any combination of src-dest mappings, files arrays, files objects and options into a consistent format. Uses globule to expand glob patterns and rte for dynamically generating destination paths. Inspired by Grunt's normalizeMultiTaskFiles method.

TOC

Install

Install with npm:

npm i normalize-config --save-dev

Usage

var normalize = require('normalize-config');
console.log(normalize({files: {'dist/': '*.js'}}));

Destination paths

Dynamically generate destination paths by defining a route property with the structure you want to use for the destination path(s).

Example:

var result = normalize({
  options: {
    route: 'foo/:dest/:basename.min.js'
  },
  src: ['*.js'],
  dest: 'scripts/'
});

//=> { files: [ { src: [ 'index.js' ], dest: 'foo/scripts/index.min.js' } ] }

See rte for all related options.

Config examples

All of these:

{files: {'dist/': '*.js'}}
{files: [{src: '*.js', dest: 'dist/'}]}
{src: '*.js', dest: 'dist/'}
{src: ['*.js'], dest: 'dist/'}

Would normalize to:

{files: [{src: ['index.js'], dest: 'dist/'}]}

All of the following:

var normalize = require('normalize-config');

var config = normalize({
  options: {
    expand: true,
    cwd: 'test/fixtures'
  },
  files: {
    'dist/a/': ['a/*.js'],
    'dist/b/': ['b/*.js']
  }
});

var result = normalize({
  options: {
    expand: true,
    cwd: 'test/fixtures'
  },
  files: [
    {dest: 'dist/a/', src: ['a/*.js']},
    {dest: 'dist/b/', src: ['b/*.js']}
  ]
});

var result = normalize({
  options: {
    cwd: 'test/fixtures'
  },
  files: [
    {expand: true, dest: 'dist/a/', src: ['a/*.js']},
    {expand: true, dest: 'dist/b/', src: ['b/*.js']}
  ]
});

var result = normalize({
  options: {
    cwd: 'test/fixtures'
  },
  files: [
    {options: {expand: true}, dest: 'dist/a/', src: ['a/*.js']},
    {options: {expand: true}, dest: 'dist/b/', src: ['b/*.js']}
  ]
});

console.log(config);

Would normalize to the following (see the test fixtures):

{ files:
   [ { src: [ 'a/x.js' ],
       dest: 'dist/a/a/x.js',
       orig:
        { options: { expand: true, cwd: 'test/fixtures' },
          src: [ 'a/*.js' ],
          dest: 'dist/a/' } },
     { src: [ 'a/y.js' ],
       dest: 'dist/a/a/y.js',
       orig:
        { options: { expand: true, cwd: 'test/fixtures' },
          src: [ 'a/*.js' ],
          dest: 'dist/a/' } },
     { src: [ 'b/x.js' ],
       dest: 'dist/b/b/x.js',
       orig:
        { options: { expand: true, cwd: 'test/fixtures' },
          src: [ 'b/*.js' ],
          dest: 'dist/b/' } },
     { src: [ 'b/y.js' ],
       dest: 'dist/b/b/y.js',
       orig:
        { options: { expand: true, cwd: 'test/fixtures' },
          src: [ 'b/*.js' ],
          dest: 'dist/b/' } },
     { src: [ 'b/z.js' ],
       dest: 'dist/b/b/z.js',
       orig:
        { options: { expand: true, cwd: 'test/fixtures' },
          src: [ 'b/*.js' ],
          dest: 'dist/b/' } } ] }

API

normalize

Normalize any combination of files arrays, files objects, src-dest pairings and options.

Example:

normalize({src: '*.js', dest: 'dist/'});

Params:

  • config {Object}: The config object to be normalized.
  • return{Object}

.multi

Normlize a config object with multiple files definitions.

Params:

  • config {Object}
  • options {Object}
  • return{Object}

.filePair

Normalize src, dest and options definitions to an array of files objects.

Params:

  • config {Object}
  • return{Object}

.normalizeObj

Normalize files objects with varied formats to an array of files objects.

Params:

  • config {Object}
  • return{Object}

Options are passed to globule. Visit globule to see all supported options.

Author

Jon Schlinkert

License

Copyright (c) 2014 Jon Schlinkert, contributors.
Released under the MIT license

This file was generated by verb-cli on June 22, 2014.

Keywords

config

FAQs

Package last updated on 28 Jun 2014

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