Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

grunt-lib-contrib

Package Overview
Dependencies
Maintainers
4
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

grunt-lib-contrib - npm Package Compare versions

Comparing version 0.6.1 to 0.7.0

70

lib/contrib.js

@@ -15,2 +15,3 @@ /*

var path = require('path');
var maxmin = require('maxmin');

@@ -36,78 +37,13 @@ exports.getNamespaceDeclaration = function(ns) {

// Convert an object to an array of CLI arguments
exports.optsToArgs = function(options) {
var args = [];
Object.keys(options).forEach(function(flag) {
var val = options[flag];
flag = flag.replace(/[A-Z]/g, function(match) {
return '-' + match.toLowerCase();
});
if (val === true) {
args.push('--' + flag);
}
if (grunt.util._.isString(val)) {
args.push('--' + flag, val);
}
if (grunt.util._.isNumber(val)) {
args.push('--' + flag, '' + val);
}
if (grunt.util._.isArray(val)) {
val.forEach(function(arrVal) {
args.push('--' + flag, arrVal);
});
}
});
return args;
};
// Strip a path from a path. normalize both paths for best results.
exports.stripPath = function(pth, strip) {
if (strip && strip.length >= 1) {
strip = path.normalize(strip);
pth = path.normalize(pth);
pth = grunt.util._(pth).strRight(strip);
pth = grunt.util._(pth).ltrim(path.sep);
}
exports.stripPath = require('strip-path');
return pth;
};
// Log min and max info
function gzipSize(src) {
return src ? require('zlib-browserify').gzipSync(src).length : 0;
}
exports.minMaxInfo = function(min, max, report) {
if (report === 'min' || report === 'gzip') {
grunt.log.writeln('Original: ' + String(max.length).green + ' bytes.');
grunt.log.writeln('Minified: ' + String(min.length).green + ' bytes.');
grunt.log.writeln(maxmin(max, min, report === 'gzip'))
}
if (report === 'gzip') {
// Note this option is pretty slow so it is not enabled by default
grunt.log.write('Gzipped: ');
grunt.log.writeln(String(gzipSize(min)).green + ' bytes.');
}
};
exports.formatForType = function(string, type, namespace, filename) {
namespace = namespace || false;
if (type === 'amd' && namespace === false) {
string = 'return ' + string;
} else if (type === 'commonjs' && namespace === false) {
string = 'module.exports = ' + string;
} else if (type === 'amd' && namespace !== false || type === 'commonjs' && namespace !== false || type === 'js' && namespace !== false) {
string = namespace+'['+JSON.stringify(filename)+'] = '+string+';';
}
return string;
};
return exports;
};

11

package.json
{
"name": "grunt-lib-contrib",
"description": "Common functionality shared across grunt-contrib tasks.",
"version": "0.6.1",
"version": "0.7.0",
"homepage": "http://github.com/gruntjs/grunt-lib-contrib",

@@ -24,3 +24,3 @@ "author": {

"engines": {
"node": ">= 0.8.0"
"node": ">=0.8.0"
},

@@ -31,4 +31,4 @@ "scripts": {

"devDependencies": {
"grunt-contrib-jshint": "~0.1.1",
"grunt-contrib-nodeunit": "~0.1.2",
"grunt-contrib-jshint": "~0.8.0",
"grunt-contrib-nodeunit": "~0.3.0",
"grunt": "~0.4.0"

@@ -38,4 +38,5 @@ },

"dependencies": {
"zlib-browserify": "0.0.1"
"maxmin": "^0.1.0",
"strip-path": "^0.1.0"
}
}
# grunt-lib-contrib [![Build Status](https://secure.travis-ci.org/gruntjs/grunt-lib-contrib.png?branch=master)](http://travis-ci.org/gruntjs/grunt-lib-contrib)
**DEPRECATED - DO NOT USE**
> Common functionality shared across grunt-contrib tasks.
The purpose of grunt-lib-contrib is to explore solutions to common problems task writers encounter, and to ease the upgrade path for contrib tasks.
**These APIs should be considered highly unstable. Depend on them at your own risk!**
_Over time, some of the functionality provided here may be incorporated directly into grunt for mainstream use. Until then, you may require `grunt-lib-contrib` as a dependency in your projects, but be very careful to specify an exact version number instead of a range, as backwards-incompatible changes are likely to be introduced._
### Helper Functions
#### getNamespaceDeclaration(ns)
#### stripPath(path, stripPath)
This helper is used to build JS namespace declarations.
**Deprecated. Use [strip-path](https://github.com/sindresorhus/strip-path) instead.**
#### optsToArgs(options)
Strip a path from a path. Normalize both paths for best results.
Convert an object to an array of CLI arguments, which can be used with `child_process.spawn()`.
#### minMaxInfo(min, max, report)
```js
// Example
{
fooBar: 'a', // ['--foo-bar', 'a']
fooBar: 1, // ['--foo-bar', '1']
fooBar: true, // ['--foo-bar']
fooBar: false, //
fooBar: ['a', 'b'] // ['--foo-bar', 'a', '--foo-bar', 'b']
}
```
**Deprecated. Use [maxmin](https://github.com/sindresorhus/maxmin) instead.**
#### stripPath(pth, strip)
Strip a path from a path. normalize both paths for best results.
#### minMaxInfo(min, max, report)
Helper for logging compressed, uncompressed and gzipped sizes of strings.
#### report
##### report
Choices: `false`, `'min'`, `'gzip'`

@@ -63,4 +44,8 @@ Default: `false`

#### getNamespaceDeclaration(ns)
This helper is used to build JS namespace declarations.
--
*Lib submitted by [Tyler Kellen](https://goingslowly.com/).*
*Lib submitted by [Tyler Kellen](https://goingslowly.com/).*

@@ -60,20 +60,2 @@ var grunt = require('grunt');

},
optsToArgs: function(test) {
'use strict';
test.expect(1);
var fixture = {
key: 'a',
key2: 1,
key3: true,
key4: false,
key5: ['a', 'b']
};
var expected = ['--key', 'a', '--key2', '1', '--key3', '--key5', 'a', '--key5', 'b' ].toString();
var actual = helper.optsToArgs(fixture).toString();
test.equal(expected, actual, 'should convert object to array of CLI arguments');
test.done();
},
stripPath: function(test) {

@@ -138,4 +120,3 @@ 'use strict';

expected = [
'Original: 495 bytes.',
'Minified: 396 bytes.'
'495 B → 396 B'
].join(grunt.util.linefeed) + grunt.util.linefeed;

@@ -149,5 +130,3 @@

expected = [
'Original: 495 bytes.',
'Minified: 396 bytes.',
'Gzipped: 36 bytes.'
'495 B → 396 B → 36 B (gzip)'
].join(grunt.util.linefeed) + grunt.util.linefeed;

@@ -161,77 +140,3 @@

test.done();
},
formatToType: {
amd: function(test) {
'use strict';
test.expect(2);
var string = function () { };
var actual = helper.formatForType(string, 'amd', 'JST', 'test');
var expected = 'JST["test"] = function () { };';
test.equal(expected, actual, 'should format string to amd with namespace');
actual = helper.formatForType(string, 'amd');
expected = "return function () { }";
test.equal(expected, actual, 'should format string to amd');
test.done();
},
commonjs: function(test) {
'use strict';
test.expect(2);
var string = function () { };
var actual = helper.formatForType(string, 'commonjs', 'JST', 'test');
var expected = 'JST["test"] = function () { };';
test.equal(expected, actual, 'should format string to commonjs with namespace');
actual = helper.formatForType(string, 'commonjs');
expected = "module.exports = function () { }";
test.equal(expected, actual, 'should format string to commonjs');
test.done();
},
js: function(test) {
'use strict';
test.expect(2);
var string = function () { };
var actual = helper.formatForType(string, 'js', 'JST', 'test');
var expected = 'JST["test"] = function () { };';
test.equal(expected, actual, 'should format string to js with namespace');
actual = helper.formatForType(string, 'js');
expected = 'function () { }';
test.equal(expected, actual, 'should format string to js');
test.done();
},
html: function(test) {
'use strict';
test.expect(2);
var string = function () { };
var actual = helper.formatForType(string, 'html', 'JST', 'test');
var expected = 'function () { }';
test.equal(expected, actual, 'should format string to html with namespace');
actual = helper.formatForType(string, 'html');
expected = 'function () { }';
test.equal(expected, actual, 'should format string to html');
test.done();
}
}
};
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