Comparing version 1.0.0 to 2.0.0
203
gex.js
@@ -1,140 +0,121 @@ | ||
/* Copyright (c) 2011-2019 Richard Rodger, MIT License */ | ||
/* Copyright (c) 2011-2020 Richard Rodger, MIT License */ | ||
// eslint-disable-next-line | ||
;(function() { | ||
'use strict' | ||
var root = this | ||
var previous_gex = root.gex | ||
module.exports = gex | ||
function Gex(gexspec) { | ||
var self = this | ||
function gex(gexspec) { | ||
return new Gex(gexspec) | ||
} | ||
function dodgy(obj) { | ||
return null == obj || void 0 == obj || Number.isNaN(obj) | ||
} | ||
gex.Gex = Gex | ||
function clean(gexexp) { | ||
var gexstr = '' + gexexp | ||
if (dodgy(gexexp)) { | ||
gexstr = '' | ||
} | ||
return gexstr | ||
function Gex(gexspec) { | ||
var self = this | ||
function dodgy(obj) { | ||
return null == obj || Number.isNaN(obj) | ||
} | ||
function clean(gexexp) { | ||
var gexstr = '' + gexexp | ||
if (dodgy(gexexp)) { | ||
gexstr = '' | ||
} | ||
return gexstr | ||
} | ||
function match(str) { | ||
str = '' + str | ||
var hasmatch = false | ||
var gexstrs = Object.keys(gexmap) | ||
function match(str) { | ||
str = '' + str | ||
var hasmatch = false | ||
var gexstrs = Object.keys(gexmap) | ||
for (var i = 0; i < gexstrs.length && !hasmatch; i++) { | ||
hasmatch = !!gexmap[gexstrs[i]].exec(str) | ||
} | ||
return hasmatch | ||
for (var i = 0; i < gexstrs.length && !hasmatch; i++) { | ||
hasmatch = !!gexmap[gexstrs[i]].exec(str) | ||
} | ||
return hasmatch | ||
} | ||
self.noConflict = function() { | ||
root.gex = previous_gex | ||
return self | ||
self.on = function (obj) { | ||
if (null == obj) { | ||
return null | ||
} | ||
self.on = function(obj) { | ||
var typeof_obj = typeof obj | ||
if ( | ||
'string' === typeof_obj || | ||
'number' === typeof_obj || | ||
'boolean' === typeof_obj || | ||
obj instanceof Date || | ||
obj instanceof RegExp | ||
) { | ||
return match(obj) ? obj : null | ||
} else if (Array.isArray(obj)) { | ||
var out = [] | ||
for (var i = 0; i < obj.length; i++) { | ||
if (!dodgy(obj[i]) && match(obj[i])) { | ||
out.push(obj[i]) | ||
} | ||
var typeof_obj = typeof obj | ||
if ( | ||
'string' === typeof_obj || | ||
'number' === typeof_obj || | ||
'boolean' === typeof_obj || | ||
obj instanceof Date || | ||
obj instanceof RegExp | ||
) { | ||
return match(obj) ? obj : null | ||
} else if (Array.isArray(obj)) { | ||
var out = [] | ||
for (var i = 0; i < obj.length; i++) { | ||
if (!dodgy(obj[i]) && match(obj[i])) { | ||
out.push(obj[i]) | ||
} | ||
return out | ||
} else if ('object' === typeof_obj) { | ||
var outobj = {} | ||
for (var p in obj) { | ||
if (Object.prototype.hasOwnProperty.call(obj, p)) { | ||
if (match(p)) { | ||
outobj[p] = obj[p] | ||
} | ||
} | ||
return out | ||
} else { | ||
var outobj = {} | ||
for (var p in obj) { | ||
if (Object.prototype.hasOwnProperty.call(obj, p)) { | ||
if (match(p)) { | ||
outobj[p] = obj[p] | ||
} | ||
} | ||
return outobj | ||
} else { | ||
return null | ||
} | ||
return outobj | ||
} | ||
} | ||
self.esc = function(gexexp) { | ||
var gexstr = clean(gexexp) | ||
gexstr = gexstr.replace(/\*/g, '**') | ||
gexstr = gexstr.replace(/\?/g, '*?') | ||
return gexstr | ||
} | ||
self.esc = function (gexexp) { | ||
var gexstr = clean(gexexp) | ||
gexstr = gexstr.replace(/\*/g, '**') | ||
gexstr = gexstr.replace(/\?/g, '*?') | ||
return gexstr | ||
} | ||
self.re = function(gs) { | ||
if ('' === gs || gs) { | ||
gs = self.escregexp(gs) | ||
self.re = function (gs) { | ||
if ('' === gs || gs) { | ||
gs = self.escregexp(gs) | ||
// use [\s\S] instead of . to match newlines | ||
gs = gs.replace(/\\\*/g, '[\\s\\S]*') | ||
gs = gs.replace(/\\\?/g, '[\\s\\S]') | ||
// use [\s\S] instead of . to match newlines | ||
gs = gs.replace(/\\\*/g, '[\\s\\S]*') | ||
gs = gs.replace(/\\\?/g, '[\\s\\S]') | ||
// escapes ** and *? | ||
gs = gs.replace(/\[\\s\\S\]\*\[\\s\\S\]\*/g, '\\*') | ||
gs = gs.replace(/\[\\s\\S\]\*\[\\s\\S\]/g, '\\?') | ||
// escapes ** and *? | ||
gs = gs.replace(/\[\\s\\S\]\*\[\\s\\S\]\*/g, '\\*') | ||
gs = gs.replace(/\[\\s\\S\]\*\[\\s\\S\]/g, '\\?') | ||
gs = '^' + gs + '$' | ||
gs = '^' + gs + '$' | ||
return new RegExp(gs) | ||
} else { | ||
var gexstrs = Object.keys(gexmap) | ||
return 1 == gexstrs.length ? gexmap[gexstrs[0]] : { ...gexmap } | ||
} | ||
return new RegExp(gs) | ||
} else { | ||
var gexstrs = Object.keys(gexmap) | ||
return 1 == gexstrs.length ? gexmap[gexstrs[0]] : { ...gexmap } | ||
} | ||
} | ||
self.escregexp = function(restr) { | ||
return restr | ||
? ('' + restr).replace(/[-[\]{}()*+?.,\\^$|#\s]/g, '\\$&') | ||
: '' | ||
} | ||
self.escregexp = function (restr) { | ||
return restr ? ('' + restr).replace(/[-[\]{}()*+?.,\\^$|#\s]/g, '\\$&') : '' | ||
} | ||
self.toString = function() { | ||
return desc ? desc : (desc = 'gex[' + Object.keys(gexmap) + ']') | ||
} | ||
self.inspect = function() { | ||
return self.toString() | ||
} | ||
var gexstrs = Array.isArray(gexspec) ? gexspec : [gexspec] | ||
var gexmap = {} | ||
var desc | ||
gexstrs.forEach(function(str) { | ||
str = clean(str) | ||
var re = self.re(str) | ||
gexmap[str] = re | ||
}) | ||
self.toString = function () { | ||
return null != desc ? desc : (desc = 'gex[' + Object.keys(gexmap) + ']') | ||
} | ||
function gex(gexspec) { | ||
var gexobj = new Gex(gexspec) | ||
return gexobj | ||
self.inspect = function () { | ||
return self.toString() | ||
} | ||
gex.Gex = Gex | ||
if (typeof exports !== 'undefined') { | ||
if (typeof module !== 'undefined' && module.exports) { | ||
exports = module.exports = gex | ||
} | ||
exports.gex = gex | ||
} else { | ||
root.gex = gex | ||
} | ||
}.call(this)) | ||
var gexstrs = Array.isArray(gexspec) ? gexspec : [gexspec] | ||
var gexmap = {} | ||
var desc | ||
gexstrs.forEach(function (str) { | ||
str = clean(str) | ||
var re = self.re(str) | ||
gexmap[str] = re | ||
}) | ||
} |
{ | ||
"name": "gex", | ||
"version": "2.0.0", | ||
"main": "gex.js", | ||
"browser": "dist/gex.min.js", | ||
"description": "Glob expressions for JavaScript", | ||
"scripts": { | ||
"test": "lab -v -L -P test -t 85", | ||
"test": "lab -v -L -P test -t 100 -I document -r console -o stdout -r html -o test/coverage.html", | ||
"test-web": "browserify -o test-web/test-web.js -e test/gex.test.js -s Gex -im -i assert -i @hapi/lab && open test-web/index.html", | ||
"build": "browserify -o dist/gex.min.js -e gex.js -s Gex -im -i assert -p tinyify", | ||
"coveralls": "lab -s -P test -r lcov -I URL,URLSearchParams | coveralls", | ||
"prettier": "prettier --write --no-semi --single-quote gex.js lib/*.js test/*.js", | ||
"prettier": "prettier --write --no-semi --single-quote gex.js test/*.js", | ||
"clean": "rm -rf node_modules yarn.lock package-lock.json", | ||
"reset": "npm run clean && npm i && npm test", | ||
"repo-tag": "REPO_VERSION=`node -e \"console.log(require('./package').version)\"`; echo TAG: v$REPO_VERSION && git commit -a -m v$REPO_VERSION && git push && git tag v$REPO_VERSION && git push --tags;", | ||
"repo-publish": "npm run clean && npm i && npm run prettier && npm test && npm run repo-tag && npm publish --registry http://registry.npmjs.org" | ||
"repo-publish": "npm run clean && npm i && npm run prettier && npm build && npm test && npm run test-web && npm run repo-tag && npm publish --registry http://registry.npmjs.org" | ||
}, | ||
@@ -21,3 +26,2 @@ "keywords": [ | ||
], | ||
"version": "1.0.0", | ||
"homepage": "https://github.com/rjrodger/gex", | ||
@@ -30,3 +34,2 @@ "author": "Richard Rodger (http://richardrodger.com/)", | ||
"dependencies": {}, | ||
"main": "gex.js", | ||
"repository": { | ||
@@ -39,9 +42,13 @@ "type": "git", | ||
"LICENSE.txt", | ||
"gex.js" | ||
"gex.js", | ||
"dist/gex.min.js" | ||
], | ||
"devDependencies": { | ||
"@hapi/code": "^7.0.0", | ||
"@hapi/lab": "^21.0.0", | ||
"coveralls": "^3.0.7" | ||
"@hapi/code": "^8.0.2", | ||
"@hapi/lab": "^23.0.0", | ||
"browserify": "^16.5.2", | ||
"coveralls": "^3.1.0", | ||
"prettier": "^2.1.1", | ||
"tinyify": "^3.0.0" | ||
} | ||
} |
@@ -6,2 +6,4 @@ # gex | ||
[![Coverage Status][coveralls-badge]][coveralls-url] | ||
[![DeepScan grade](https://deepscan.io/api/teams/5016/projects/13588/branches/232094/badge/grade.svg)](https://deepscan.io/dashboard#view=project&tid=5016&pid=13588&bid=232094) | ||
[![Maintainability](https://api.codeclimate.com/v1/badges/5def990719578771abb3/maintainability)](https://codeclimate.com/github/rjrodger/gex/maintainability) | ||
[![Dependency Status][david-badge]][david-url] | ||
@@ -8,0 +10,0 @@ |
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
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
11097
5
97
6
100