Socket
Socket
Sign inDemoInstall

nanomatch

Package Overview
Dependencies
Maintainers
1
Versions
28
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

nanomatch - npm Package Compare versions

Comparing version 0.3.0 to 0.3.1

139

index.js

@@ -26,9 +26,11 @@ 'use strict';

* ```js
* var nanomatch = require('nanomatch');
* console.log(nanomatch(['a.js', 'a.txt'], ['*.js']));
* var mm = require('nanomatch');
* mm(list, patterns[, options]);
*
* console.log(mm(['a.js', 'a.txt'], ['*.js']));
* //=> [ 'a.js' ]
* ```
* @param {Array} `list`
* @param {String|Array} `patterns` Glob patterns
* @param {Object} `options`
* @param {Array} `list` A list of strings to match
* @param {String|Array} `patterns` One or more glob patterns to use for matching.
* @param {Object} `options` Any [options](#options) to change how matches are performed
* @return {Array} Returns an array of matches

@@ -93,9 +95,11 @@ * @api public

* ```js
* var nanomatch = require('nanomatch');
* console.log(nanomatch.match(['a.a', 'a.aa', 'a.b', 'a.c'], '*.a'));
* var mm = require('nanomatch');
* mm.match(list, pattern[, options]);
*
* console.log(mm.match(['a.a', 'a.aa', 'a.b', 'a.c'], '*.a'));
* //=> ['a.a', 'a.aa']
* ```
* @param {Array} `list` Array of strings to match
* @param {String} `pattern` Glob pattern
* @param {Object} `options`
* @param {String} `pattern` Glob pattern to use for matching.
* @param {Object} `options` Any [options](#options) to change how matches are performed
* @return {Array} Returns an array of matches

@@ -154,11 +158,13 @@ * @api public

* ```js
* var nanomatch = require('nanomatch');
* console.log(nanomatch.isMatch('a.a', '*.a'));
* var mm = require('nanomatch');
* mm.isMatch(string, pattern[, options]);
*
* console.log(mm.isMatch('a.a', '*.a'));
* //=> true
* console.log(nanomatch.isMatch('a.b', '*.a'));
* console.log(mm.isMatch('a.b', '*.a'));
* //=> false
* ```
* @param {String} `string` String to match
* @param {String} `pattern` Glob pattern
* @param {String} `options`
* @param {String} `pattern` Glob pattern to use for matching.
* @param {Object} `options` Any [options](#options) to change how matches are performed
* @return {Boolean} Returns true if the string matches the glob pattern.

@@ -173,3 +179,3 @@ * @api public

if (pattern === '' || pattern === ' ' || pattern === '/' || pattern === '.') {
if (utils.isSimpleChar(pattern) || utils.isSlash(pattern)) {
return str === pattern;

@@ -182,13 +188,15 @@ }

/**
* Returns a list of strings that do _not_ match any of the given `patterns`.
* Returns a list of strings that _DO NOT MATCH_ any of the given `patterns`.
*
* ```js
* var nanomatch = require('nanomatch');
* console.log(nanomatch.not(['a.a', 'b.b', 'c.c'], '*.a'));
* var mm = require('nanomatch');
* mm.not(list, patterns[, options]);
*
* console.log(mm.not(['a.a', 'b.b', 'c.c'], '*.a'));
* //=> ['b.b', 'c.c']
* ```
* @param {Array} `list` Array of strings to match.
* @param {String} `pattern` One or more glob patterns.
* @param {Object} `options`
* @return {Array} Returns an array of strings that do not match the given patterns.
* @param {String|Array} `patterns` One or more glob pattern to use for matching.
* @param {Object} `options` Any [options](#options) to change how matches are performed
* @return {Array} Returns an array of strings that **do not match** the given patterns.
* @api public

@@ -219,11 +227,13 @@ */

* ```js
* var nanomatch = require('nanomatch');
* console.log(nanomatch.any('a.a', ['b.*', '*.a']));
* var mm = require('nanomatch');
* mm.any(string, patterns[, options]);
*
* console.log(mm.any('a.a', ['b.*', '*.a']));
* //=> true
* console.log(nanomatch.any('a.a', 'b.*'));
* console.log(mm.any('a.a', 'b.*'));
* //=> false
* ```
* @param {String} `str` The string to test.
* @param {String|Array} `patterns` Glob patterns to use.
* @param {Object} `options` Options to pass to the `matcher()` function.
* @param {String|Array} `patterns` One or more glob patterns to use for matching.
* @param {Object} `options` Any [options](#options) to change how matches are performed
* @return {Boolean} Returns true if any patterns match `str`

@@ -244,10 +254,12 @@ * @api public

/**
* Returns true if the given `string` contains the given pattern. Similar to `.isMatch` but
* the pattern can match any part of the string.
* Returns true if the given `string` contains the given pattern. Similar
* to [.isMatch](#isMatch) but the pattern can match any part of the string.
*
* ```js
* var nanomatch = require('nanomatch');
* console.log(nanomatch.contains('aa/bb/cc', '*b'));
* var mm = require('nanomatch');
* mm.contains(string, pattern[, options]);
*
* console.log(mm.contains('aa/bb/cc', '*b'));
* //=> true
* console.log(nanomatch.contains('aa/bb/cc', '*d'));
* console.log(mm.contains('aa/bb/cc', '*d'));
* //=> false

@@ -257,3 +269,3 @@ * ```

* @param {String} `pattern` Glob pattern to use for matching.
* @param {Object} `options`
* @param {Object} `options` Any [options](#options) to change how matches are performed
* @return {Boolean} Returns true if the patter matches any part of `str`.

@@ -264,11 +276,16 @@ * @api public

nanomatch.contains = function(str, pattern, options) {
if (pattern === '' || pattern === ' ' || pattern === '.') {
if (pattern === str) {
return true;
}
if (utils.isSimpleChar(pattern)) {
return str === pattern;
}
var opts = extend({}, options, {contains: true});
var opts = extend({}, options);
opts.strictClose = false;
opts.strictOpen = false;
opts.contains = true;
return nanomatch.match(str, pattern, opts).length > 0;
return nanomatch(str, pattern, opts).length > 0;
};

@@ -280,2 +297,3 @@

* @return {Boolean}
* @api private
*/

@@ -294,9 +312,12 @@

* ```js
* var nanomatch = require('nanomatch');
* var mm = require('nanomatch');
* mm.matchKeys(object, patterns[, options]);
*
* var obj = { aa: 'a', ab: 'b', ac: 'c' };
* console.log(nanomatch.matchKeys(obj, '*b'));
* console.log(mm.matchKeys(obj, '*b'));
* //=> { ab: 'b' }
* ```
* @param {Object} `object`
* @param {Array|String} `patterns` One or more glob patterns.
* @param {Object} `object` The object with keys to filter.
* @param {String|Array} `patterns` One or more glob patterns to use for matching.
* @param {Object} `options` Any [options](#options) to change how matches are performed
* @return {Object} Returns an object with only keys that match the given patterns.

@@ -315,9 +336,11 @@ * @api public

/**
* Creates a matcher function from the given glob `pattern` and `options`. The returned
* function takes a string to match as its only argument.
* Returns a memoized matcher function from the given glob `pattern` and `options`.
* The returned function takes a string to match as its only argument and returns
* true if the string is a match.
*
* ```js
* var nanomatch = require('nanomatch');
* var isMatch = nanomatch.matcher('*.!(*a)');
* var mm = require('nanomatch');
* mm.matcher(pattern[, options]);
*
* var isMatch = mm.matcher('*.!(*a)');
* console.log(isMatch('a.a'));

@@ -329,3 +352,3 @@ * //=> false

* @param {String} `pattern` Glob pattern
* @param {String} `options`
* @param {Object} `options` Any [options](#options) to change how matches are performed.
* @return {Function} Returns a matcher function.

@@ -380,8 +403,10 @@ * @api public

* ```js
* var nanomatch = require('nanomatch');
* console.log(nanomatch.makeRe('*.js'));
* var mm = require('nanomatch');
* mm.makeRe(pattern[, options]);
*
* console.log(mm.makeRe('*.js'));
* //=> /^(?:(\.[\\\/])?(?!\.)(?=.)[^\/]*?\.js)$/
* ```
* @param {String} `pattern` The pattern to convert to regex.
* @param {Object} `options`
* @param {String} `pattern` A glob pattern to convert to regex.
* @param {Object} `options` Any [options](#options) to change how matches are performed.
* @return {RegExp} Returns a regex created from the given pattern.

@@ -417,4 +442,6 @@ * @api public

* ```js
* var nanomatch = require('nanomatch');
* console.log(nanomatch.create('abc/*.js'));
* var mm = require('nanomatch');
* mm.create(pattern[, options]);
*
* console.log(mm.create('abc/*.js'));
* // { options: { source: 'string', sourcemap: true },

@@ -444,4 +471,4 @@ * // state: {},

* ```
* @param {String} `pattern` Glob pattern
* @param {Object} `options`
* @param {String} `pattern` Glob pattern to parse and compile.
* @param {Object} `options` Any [options](#options) to change how parsing and compiling is performed.
* @return {Object} Returns an object with the parsed AST, compiled string and optional source map.

@@ -465,4 +492,6 @@ * @api public

* ```js
* var nanomatch = require('nanomatch');
* var ast = nanomatch.parse('a/{b,c}/d');
* var mm = require('nanomatch');
* mm.parse(pattern[, options]);
*
* var ast = mm.parse('a/{b,c}/d');
* console.log(ast);

@@ -517,2 +546,4 @@ * // { type: 'root',

* var nanomatch = require('nanomatch');
* mm.compile(ast[, options]);
*
* var ast = nanomatch.parse('a/{b,c}/d');

@@ -519,0 +550,0 @@ * console.log(nanomatch.compile(ast));

'use strict';
var utils = module.exports;
var path = require('path');

@@ -7,13 +8,13 @@ var cache = {};

/**
* Utils
* Module dependencies
*/
exports.define = require('define-property');
exports.diff = require('arr-diff');
exports.extend = require('extend-shallow');
exports.isGlob = require('is-glob');
exports.typeOf = require('kind-of');
exports.pick = require('object.pick');
exports.union = require('arr-union');
exports.unique = require('array-unique');
utils.define = require('define-property');
utils.diff = require('arr-diff');
utils.extend = require('extend-shallow');
utils.isGlob = require('is-glob');
utils.typeOf = require('kind-of');
utils.pick = require('object.pick');
utils.union = require('arr-union');
utils.unique = require('array-unique');

@@ -26,3 +27,3 @@ /**

exports.createKey = function(pattern, options) {
utils.createKey = function(pattern, options) {
var key = pattern;

@@ -45,7 +46,5 @@ if (typeof options === 'undefined') {

exports.arrayify = function(val) {
if (!Array.isArray(val)) {
return [val];
}
return val;
utils.arrayify = function(val) {
if (typeof val === 'string') return [val];
return val ? (Array.isArray(val) ? val : [val]) : [];
};

@@ -57,3 +56,3 @@

exports.isString = function(val) {
utils.isString = function(val) {
return typeof val === 'string';

@@ -66,4 +65,4 @@ };

exports.isRegex = function(val) {
return exports.typeOf(val) === 'regexp';
utils.isRegex = function(val) {
return utils.typeOf(val) === 'regexp';
};

@@ -75,4 +74,4 @@

exports.isObject = function(val) {
return exports.typeOf(val) === 'object';
utils.isObject = function(val) {
return utils.typeOf(val) === 'object';
};

@@ -84,3 +83,3 @@

exports.escapeRegex = function(str) {
utils.escapeRegex = function(str) {
return str.replace(/[\-\[\]{}()^$|\s*+?.\\\/]/g, '\\$&');

@@ -95,3 +94,3 @@ };

exports.combineDuplicates = function(str, val) {
utils.combineDuplicates = function(str, val) {
if (typeof val === 'string') {

@@ -108,3 +107,3 @@ var re = new RegExp('(' + val + ')(?=(?:' + val + ')*\\1)', 'g');

exports.hasSpecialChars = function(str) {
utils.hasSpecialChars = function(str) {
return /(?:(^|\/)[!.]|[*?+()|\[\]{}]|[+@]\()/.test(str);

@@ -120,4 +119,4 @@ };

exports.unescape = function(str) {
return exports.normalize(str.replace(/\\(\W)/g, '$1'));
utils.unescape = function(str) {
return utils.normalize(str.replace(/\\(\W)/g, '$1'));
};

@@ -132,3 +131,3 @@

exports.normalize = function(filepath) {
utils.normalize = function(filepath) {
return filepath.replace(/[\\\/]+(?=[\w._-])(?![*?+\\!])/g, '/');

@@ -138,2 +137,17 @@ };

/**
* Returns true if `str` is a common character that doesn't need
* to be processed to be used for matching.
* @param {String} `str`
* @return {Boolean}
*/
utils.isSimpleChar = function(str) {
return str === '' || str === ' ' || str === '.';
};
utils.isSlash = function(str) {
return str === '/' || str === '\\' || str === '\\\\';
};
/**
* Returns a function that returns true if the given

@@ -146,6 +160,6 @@ * pattern matches or contains a `filepath`

exports.matchPath = function(pattern, options) {
utils.matchPath = function(pattern, options) {
return (options && options.contains)
? exports.containsPattern(pattern, options)
: exports.equalsPattern(pattern, options);
? utils.containsPattern(pattern, options)
: utils.equalsPattern(pattern, options);
};

@@ -161,4 +175,4 @@

exports.equalsPattern = function(pattern, options) {
var unixify = exports.unixify(options);
utils.equalsPattern = function(pattern, options) {
var unixify = utils.unixify(options);

@@ -181,4 +195,4 @@ return function(filepath) {

exports.containsPattern = function(pattern, options) {
var unixify = exports.unixify(options);
utils.containsPattern = function(pattern, options) {
var unixify = utils.unixify(options);
return function(filepath) {

@@ -201,3 +215,3 @@ if (options && options.nocase === true) {

exports.matchBasename = function(re) {
utils.matchBasename = function(re) {
return function(filepath) {

@@ -214,3 +228,3 @@ return re.test(filepath) || re.test(path.basename(filepath));

exports.stripPrefix = function(fp) {
utils.stripPrefix = function(fp) {
if (typeof fp !== 'string') {

@@ -232,4 +246,4 @@ return fp;

exports.unixify = function(options) {
var key = exports.createKey('unixify', options);
utils.unixify = function(options) {
var key = utils.createKey('unixify', options);

@@ -240,6 +254,6 @@ if (cache.hasOwnProperty(key) && path.sep === '/') {

var opts = exports.extend({}, options);
var opts = utils.extend({}, options);
var unixify = function(filepath) {
return exports.stripPrefix(filepath);
return utils.stripPrefix(filepath);
};

@@ -249,3 +263,3 @@

unixify = function(filepath) {
return exports.stripPrefix(exports.normalize(filepath));
return utils.stripPrefix(utils.normalize(filepath));
};

@@ -256,3 +270,3 @@ }

unixify = function(filepath) {
return exports.stripPrefix(exports.normalize(exports.unescape(filepath)));
return utils.stripPrefix(utils.normalize(utils.unescape(filepath)));
};

@@ -259,0 +273,0 @@ }

{
"name": "nanomatch",
"description": "Fast, minimal glob matcher for node.js. Similar to micromatch, minimatch and multimatch, but complete Bash 4.3 wildcard support only (no support for exglobs, posix brackets or braces)",
"version": "0.3.0",
"version": "0.3.1",
"homepage": "https://github.com/jonschlinkert/nanomatch",

@@ -6,0 +6,0 @@ "author": "Jon Schlinkert (https://github.com/jonschlinkert)",

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