grunt-lib-contrib
Advanced tools
Comparing version 0.6.1 to 0.7.0
@@ -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; | ||
}; |
{ | ||
"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(); | ||
} | ||
} | ||
}; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
46209
12094
2
198
51
1
+ Addedmaxmin@^0.1.0
+ Addedstrip-path@^0.1.0
+ Addedansi-styles@1.0.0(transitive)
+ Addedbuffer-from@1.1.2(transitive)
+ Addedchalk@0.4.0(transitive)
+ Addedconcat-stream@1.6.2(transitive)
+ Addedcore-util-is@1.0.3(transitive)
+ Addeddeep-equal@0.0.0(transitive)
+ Addeddefined@0.0.0(transitive)
+ Addedgzip-size@0.1.1(transitive)
+ Addedhas-color@0.1.7(transitive)
+ Addedinherits@2.0.4(transitive)
+ Addedisarray@1.0.0(transitive)
+ Addedjsonify@0.0.1(transitive)
+ Addedmaxmin@0.1.0(transitive)
+ Addedpretty-bytes@0.1.2(transitive)
+ Addedprocess-nextick-args@2.0.1(transitive)
+ Addedreadable-stream@2.3.8(transitive)
+ Addedsafe-buffer@5.1.2(transitive)
+ Addedstring_decoder@1.1.1(transitive)
+ Addedstrip-ansi@0.1.1(transitive)
+ Addedstrip-path@0.1.1(transitive)
+ Addedtape@0.2.2(transitive)
+ Addedtypedarray@0.0.6(transitive)
+ Addedutil-deprecate@1.0.2(transitive)
+ Addedzlib-browserify@0.0.3(transitive)
- Removedzlib-browserify@0.0.1
- Removedzlib-browserify@0.0.1(transitive)