1.0.3 • Published 8 years ago

gulp-self-execute v1.0.3

Weekly downloads
3
License
MIT
Repository
github
Last release
8 years ago

gulp-self-execute

NPM version License Build Status Coverage Status Dependency Status

DEPRECATED: This package is no longer maintained

A Gulp plugin that wraps the contents of a JavaScript file with a self-executing anonymous function.

Install

Install via npm:

npm install --save-dev gulp-self-execute

Example

Suppose we want to wrap this code:

/* some masterpiece */

We run it through the plugin:

var gulp = require('gulp');
var selfExecute = require('gulp-self-execute');

gulp.task('self-execute', function() {
    return gulp.src('path/to/our/masterpiece.js')
        .pipe(selfExecute({
            'window', 'window',
            'jQuery': '$'
        }))
        .pipe(gulp.dest('some/excellent/directory'));
});

And we get this:

(function(window, $, undefined) {

/* some masterpiece */

}(window, jQuery));

API

selfExecute(options)

  • options (optional) Array | Object | null - Specifies the arguments to be passed to the function and their corresponding parameter names.

If options is a plain Object, its keys will be the arguments to be passed to the function and its values the corresponding parameter names.

selfExecute({
    'arg1': 'param1',
    'arg2': 'param2'
});

// Becomes:

(function(param1, param2, undefined) {
/* code */
}(arg1, arg2));

If options is an Array, each element will identify both an argument to be passed in and a parameter of the same name:

selfExecute([
    'thing1',
    'thing2'
]);

// Becomes:

(function(thing1, thing2, undefined) {
/* code */
}(thing1, thing2));

If options is null, no arguments or parameters will be defined.

selfExecute(null);

// Becomes:

(function(undefined) {
/* code */
}());

If options is undefined, our arguments/parameters will default to 'window' and 'document'.

selfExecute();

// Becomes:

(function(window, document, undefined) {
/* code */
}(window, document));

License

Copyright © 2015 Akim McMath. Licensed under the MIT License.