Socket
Socket
Sign inDemoInstall

globule

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

globule - npm Package Compare versions

Comparing version 0.1.0 to 0.2.0

59

lib/globule.js

@@ -5,3 +5,3 @@ /*

*
* Copyright (c) 2013 "Cowboy" Ben Alman
* Copyright (c) 2014 "Cowboy" Ben Alman
* Licensed under the MIT license.

@@ -24,14 +24,19 @@ */

// callback, excluding and uniquing files in the result set.
function processPatterns(patterns, fn) {
return _.flatten(patterns).reduce(function(result, pattern) {
if (pattern.indexOf('!') === 0) {
// If the first character is ! all matches via this pattern should be
// removed from the result set.
pattern = pattern.slice(1);
return _.difference(result, fn(pattern));
} else {
// Otherwise, add all matching filepaths to the result set.
return _.union(result, fn(pattern));
function processPatterns(patterns, options, fn) {
var result = [];
_.each(patterns, function(pattern) {
// The first character is not ! (inclusion). Add all matching filepaths
// to the result set.
if (pattern.indexOf('!') !== 0) {
result = _.union(result, fn(pattern));
return;
}
}, []);
// The first character is ! (exclusion). Remove any filepaths from the
// result set that match this pattern, sans leading !.
var filterFn = minimatch.filter(pattern.slice(1), options);
result = _.filter(result, function(filepath) {
return !filterFn(filepath);
});
});
return result;
}

@@ -45,9 +50,9 @@

if (patterns == null || filepaths == null) { return []; }
// Normalize patterns and filepaths to arrays.
if (!_.isArray(patterns)) { patterns = [patterns]; }
if (!_.isArray(filepaths)) { filepaths = [filepaths]; }
// Normalize patterns and filepaths to flattened arrays.
patterns = _.isArray(patterns) ? _.flatten(patterns) : [patterns];
filepaths = _.isArray(filepaths) ? _.flatten(filepaths) : [filepaths];
// Return empty set if there are no patterns or filepaths.
if (patterns.length === 0 || filepaths.length === 0) { return []; }
// Return all matching filepaths.
return processPatterns(patterns, function(pattern) {
return processPatterns(patterns, options, function(pattern) {
return minimatch.match(filepaths, pattern, options || {});

@@ -68,5 +73,11 @@ });

var options = _.isPlainObject(args[args.length - 1]) ? args.pop() : {};
// Use the first argument if it's an Array, otherwise use all arguments.
var patterns = _.isArray(args[0]) ? args[0] : args;
// Return empty set if there are no patterns or filepaths.
// If options.src was specified, use it. Otherwise, use all non-options
// arguments. Flatten nested arrays.
var patterns;
if (options.src) {
patterns = _.isArray(options.src) ? _.flatten(options.src) : [options.src];
} else {
patterns = _.flatten(args);
}
// Return empty set if there are no patterns.
if (patterns.length === 0) { return []; }

@@ -80,3 +91,3 @@ var srcBase = options.srcBase || options.cwd;

// Get all matching filepaths.
var matches = processPatterns(patterns, function(pattern) {
var matches = processPatterns(patterns, options, function(pattern) {
return glob.sync(pattern, globOptions);

@@ -175,4 +186,8 @@ });

// wildcard patterns.
globule.findMapping = function(patterns, options) {
return globule.mapping(globule.find(patterns, options), options);
globule.findMapping = function() {
var args = _.toArray(arguments);
// If the last argument is an options object, remove it from args.
var options = _.isPlainObject(args[args.length - 1]) ? args.pop() : {};
// Generate mapping from found filepaths.
return globule.mapping(globule.find(args, options), options);
};
{
"name": "globule",
"description": "An easy-to-use wildcard globbing library.",
"version": "0.1.0",
"version": "0.2.0",
"homepage": "https://github.com/cowboy/node-globule",

@@ -31,6 +31,6 @@ "author": {

"devDependencies": {
"grunt-contrib-jshint": "~0.1.1",
"grunt-contrib-nodeunit": "~0.1.2",
"grunt-contrib-watch": "~0.2.0",
"grunt": "~0.4.1"
"grunt-contrib-jshint": "~0.8.0",
"grunt-contrib-nodeunit": "~0.2.2",
"grunt-contrib-watch": "~0.5.3",
"grunt": "~0.4.2"
},

@@ -49,6 +49,6 @@ "keywords": [

"dependencies": {
"lodash": "~1.0.1",
"glob": "~3.1.21",
"lodash": "~2.4.1",
"glob": "~3.2.7",
"minimatch": "~0.2.11"
}
}

@@ -16,6 +16,7 @@ # globule [![Build Status](https://secure.travis-ci.org/cowboy/node-globule.png?branch=master)](http://travis-ci.org/cowboy/node-globule)

### globule.find
Returns a unique array of all file or directory paths that match the given globbing pattern(s). This method accepts either comma separated globbing patterns or an array of globbing patterns. Paths matching patterns that begin with `!` will be excluded from the returned array. Patterns are processed in order, so inclusion and exclusion order is significant.
Returns a unique array of all file or directory paths that match the given globbing pattern(s). This method accepts either comma separated globbing patterns or an array of globbing patterns. Paths matching patterns that begin with `!` will be excluded from the returned array. Patterns are processed in order, so inclusion and exclusion order is significant. Patterns may be specified as function arguments or as a `src` property of the options object.
```js
globule.find(patterns [, options])
globule.find(patterns [, patterns [, ...]] [, options])
globule.find({src: patterns, /* other options */})
```

@@ -25,2 +26,3 @@

* `src` This property may be used instead of specifying patterns as function arguments.
* `filter` Either a valid [fs.Stats method name](http://nodejs.org/docs/latest/api/fs.html#fs_class_fs_stats) or a function that will be passed the matched `src` filepath and `options` object as arguments. This function should return a `Boolean` value.

@@ -38,3 +40,3 @@ * `nonull` Retain globbing patterns in result set even if they fail to match files.

```js
grunt.file.match(patterns, filepaths [, options])
globule.match(patterns, filepaths [, options])
```

@@ -46,10 +48,11 @@

```js
grunt.file.isMatch(patterns, filepaths [, options])
globule.isMatch(patterns, filepaths [, options])
```
### globule.mapping
Given a set of source file paths, returns an array of src-dest file mapping objects. Both src and dest paths may be renamed, depending on the options specified.
Given a set of source file paths, returns an array of src-dest file mapping objects. Both src and dest paths may be renamed, depending on the options specified. Patterns may be specified as function arguments or as a `src` property of the options object.
```js
globule.mapping(filepaths [, options])
globule.mapping(filepaths [, filepaths [, ...]] [, options])
globule.mapping({src: filepaths, /* other options */})
```

@@ -87,3 +90,3 @@

globule.find("*.js", {srcBase: "foo", prefixBase: true})
globule.find({src: "*.js", srcBase: "foo", prefixBase: true})
// ["foo/a.js", "foo/b.js"]

@@ -94,9 +97,9 @@ ```

globule.findMapping("foo/*.js")
// [{src: "foo/a.js", dest: "foo/a.js"}, {src: "foo/b.js", dest: "foo/b.js"}]
// [{src: ["foo/a.js"], dest: "foo/a.js"}, {src: ["foo/b.js"], dest: "foo/b.js"}]
globule.findMapping("foo/*.js", {destBase: "bar"})
// [{src: "foo/a.js", dest: "bar/foo/a.js"}, {src: "foo/b.js", dest: "bar/foo/b.js"}]
// [{src: ["foo/a.js"], dest: "bar/foo/a.js"}, {src: ["foo/b.js"], dest: "bar/foo/b.js"}]
globule.findMapping("*.js", {srcBase: "foo", destBase: "bar"})
// [{src: "foo/a.js", dest: "bar/a.js"}, {src: "foo/b.js", dest: "bar/b.js"}]
globule.findMapping({src: "*.js", srcBase: "foo", destBase: "bar"})
// [{src: ["foo/a.js"], dest: "bar/a.js"}, {src: ["foo/b.js"], dest: "bar/b.js"}]
```

@@ -106,9 +109,15 @@

globule.mapping(["foo/a.js", "foo/b.js"])
// [{src: "foo/a.js", dest: "foo/a.js"}, {src: "foo/b.js", dest: "foo/b.js"}]
// [{src: ["foo/a.js"], dest: "foo/a.js"}, {src: ["foo/b.js"], dest: "foo/b.js"}]
globule.mapping(["foo/a.js", "foo/b.js"], {destBase: "bar"})
// [{src: "foo/a.js", dest: "bar/foo/a.js"}, {src: "foo/b.js", dest: "bar/foo/b.js"}]
// [{src: ["foo/a.js"], dest: "bar/foo/a.js"}, {src: ["foo/b.js"], dest: "bar/foo/b.js"}]
globule.mapping("foo/a.js", "foo/b.js", {destBase: "bar"})
// [{src: ["foo/a.js"], dest: "bar/foo/a.js"}, {src: ["foo/b.js"], dest: "bar/foo/b.js"}]
globule.mapping(["a.js", "b.js"], {srcBase: "foo", destBase: "bar"})
// [{src: "foo/a.js", dest: "bar/a.js"}, {src: "foo/b.js", dest: "bar/b.js"}]
// [{src: ["foo/a.js"], dest: "bar/a.js"}, {src: ["foo/b.js"], dest: "bar/b.js"}]
globule.mapping({src: ["a.js", "b.js"], srcBase: "foo", destBase: "bar"})
// [{src: ["foo/a.js"], dest: "bar/a.js"}, {src: ["foo/b.js"], dest: "bar/b.js"}]
```

@@ -120,6 +129,7 @@

## Release History
_(Nothing yet)_
2014-01-07 - v0.2.0 - Updated dependencies. Added `src` option. Improved exclusion speed significantly.
2013-04-11 - v0.1.0 - Initial release.
## License
Copyright (c) 2013 "Cowboy" Ben Alman
Copyright (c) 2014 "Cowboy" Ben Alman
Licensed under the MIT license.

@@ -63,5 +63,5 @@ 'use strict';

test.expect(1);
test.deepEqual(globule.match([['*.js', '*.css'], ['*.*', '*.js']], ['foo.js', 'bar.css']),
test.deepEqual(globule.match([['*.js', '*.css'], ['*.*', '*.js']], [['foo.js', ['bar.css']]]),
['foo.js', 'bar.css'],
'should process nested pattern arrays correctly.');
'should process nested pattern / filepaths arrays correctly.');
test.done();

@@ -213,2 +213,14 @@ },

},
'options.src': function(test) {
test.expect(4);
test.deepEqual(globule.find({src: '**/*.js'}), ['js/bar.js', 'js/foo.js'], 'single pattern argument should match.');
test.deepEqual(globule.find({src: ['**/*.js', '**/*.css']}),
['js/bar.js', 'js/foo.js', 'css/baz.css', 'css/qux.css'],
'array of patterns should match.');
test.deepEqual(globule.find({src: [['**/*.js'], [['**/*.css', 'js/*.js']]]}),
['js/bar.js', 'js/foo.js', 'css/baz.css', 'css/qux.css'],
'array of arrays of patterns should be flattened.');
test.deepEqual(globule.find({src: '*.xyz'}), [], 'bad pattern should fail to match.');
test.done();
},
'options.mark': function(test) {

@@ -462,3 +474,3 @@ test.expect(4);

'basic matching': function(test) {
test.expect(2);
test.expect(3);

@@ -473,2 +485,5 @@ var actual = globule.findMapping(['expand/**/*.txt']);

actual = globule.findMapping({src: ['expand/**/*.txt']});
test.deepEqual(actual, expected, 'should also work when specifying src as option.');
expected = globule.mapping(globule.find(['expand/**/*.txt']));

@@ -480,3 +495,3 @@ test.deepEqual(actual, expected, 'this is what it\'s doing under the hood, anwyays.');

'options.srcBase': function(test) {
test.expect(1);
test.expect(2);
var actual = globule.findMapping(['**/*.txt'], {destBase: 'dest', srcBase: 'expand/deep'});

@@ -489,4 +504,24 @@ var expected = [

test.deepEqual(actual, expected, 'srcBase should be stripped from front of destPath, pre-destBase+destPath join');
actual = globule.findMapping({src: ['**/*.txt'], destBase: 'dest', srcBase: 'expand/deep'});
test.deepEqual(actual, expected, 'should also work with src as option.');
test.done();
},
'multiple src per dest via rename': function(test) {
test.expect(1);
var actual = globule.findMapping('**/*.{js,css,txt}', {
srcBase: 'expand',
filter: 'isFile',
rename: function(dest) {
return 'build/all.' + dest.split('.').slice(-1);
},
});
var expected = [
{dest: 'build/all.css', src: ['expand/css/baz.css', 'expand/css/qux.css']},
{dest: 'build/all.txt', src: ['expand/deep/deep.txt', 'expand/deep/deeper/deeper.txt', 'expand/deep/deeper/deepest/deepest.txt']},
{dest: 'build/all.js', src: ['expand/js/bar.js', 'expand/js/foo.js']},
];
test.deepEqual(actual, expected, 'multiple src files are grouped into a per-dest array when renamed dest is same');
test.done();
},
};

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc