Updating NPM dependencies
This commit is contained in:
182
node_modules/istanbul-lib-report/lib/path.js
generated
vendored
182
node_modules/istanbul-lib-report/lib/path.js
generated
vendored
@@ -6,7 +6,7 @@
|
||||
|
||||
const path = require('path');
|
||||
let parsePath = path.parse;
|
||||
let SEP = path.sep || /* istanbul ignore next */ '/';
|
||||
let SEP = path.sep;
|
||||
const origParser = parsePath;
|
||||
const origSep = SEP;
|
||||
|
||||
@@ -38,7 +38,7 @@ function makeRelativeNormalizedPath(str, sep) {
|
||||
}
|
||||
|
||||
if (dir !== '') {
|
||||
dir = dir + '/' + file;
|
||||
dir = `${dir}/${file}`;
|
||||
} else {
|
||||
dir = file;
|
||||
}
|
||||
@@ -49,96 +49,106 @@ function makeRelativeNormalizedPath(str, sep) {
|
||||
return dir;
|
||||
}
|
||||
|
||||
function Path(strOrArray) {
|
||||
if (Array.isArray(strOrArray)) {
|
||||
this.v = strOrArray;
|
||||
} else if (typeof strOrArray === 'string') {
|
||||
this.v = makeRelativeNormalizedPath(strOrArray, SEP);
|
||||
} else {
|
||||
throw new Error(
|
||||
'Invalid Path argument must be string or array:' + strOrArray
|
||||
);
|
||||
class Path {
|
||||
constructor(strOrArray) {
|
||||
if (Array.isArray(strOrArray)) {
|
||||
this.v = strOrArray;
|
||||
} else if (typeof strOrArray === 'string') {
|
||||
this.v = makeRelativeNormalizedPath(strOrArray, SEP);
|
||||
} else {
|
||||
throw new Error(
|
||||
`Invalid Path argument must be string or array:${strOrArray}`
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
toString() {
|
||||
return this.v.join('/');
|
||||
}
|
||||
|
||||
hasParent() {
|
||||
return this.v.length > 0;
|
||||
}
|
||||
|
||||
parent() {
|
||||
if (!this.hasParent()) {
|
||||
throw new Error('Unable to get parent for 0 elem path');
|
||||
}
|
||||
const p = this.v.slice();
|
||||
p.pop();
|
||||
return new Path(p);
|
||||
}
|
||||
|
||||
elements() {
|
||||
return this.v.slice();
|
||||
}
|
||||
|
||||
name() {
|
||||
return this.v.slice(-1)[0];
|
||||
}
|
||||
|
||||
contains(other) {
|
||||
let i;
|
||||
if (other.length > this.length) {
|
||||
return false;
|
||||
}
|
||||
for (i = 0; i < other.length; i += 1) {
|
||||
if (this.v[i] !== other.v[i]) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
ancestorOf(other) {
|
||||
return other.contains(this) && other.length !== this.length;
|
||||
}
|
||||
|
||||
descendantOf(other) {
|
||||
return this.contains(other) && other.length !== this.length;
|
||||
}
|
||||
|
||||
commonPrefixPath(other) {
|
||||
const len = this.length > other.length ? other.length : this.length;
|
||||
let i;
|
||||
const ret = [];
|
||||
|
||||
for (i = 0; i < len; i += 1) {
|
||||
if (this.v[i] === other.v[i]) {
|
||||
ret.push(this.v[i]);
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return new Path(ret);
|
||||
}
|
||||
|
||||
static compare(a, b) {
|
||||
const al = a.length;
|
||||
const bl = b.length;
|
||||
|
||||
if (al < bl) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (al > bl) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
const astr = a.toString();
|
||||
const bstr = b.toString();
|
||||
return astr < bstr ? -1 : astr > bstr ? 1 : 0;
|
||||
}
|
||||
}
|
||||
|
||||
Path.prototype.toString = function() {
|
||||
return this.v.join('/');
|
||||
};
|
||||
|
||||
Path.prototype.hasParent = function() {
|
||||
return this.v.length > 0;
|
||||
};
|
||||
|
||||
Path.prototype.parent = function() {
|
||||
if (!this.hasParent()) {
|
||||
throw new Error('Unable to get parent for 0 elem path');
|
||||
}
|
||||
const p = this.v.slice();
|
||||
p.pop();
|
||||
return new Path(p);
|
||||
};
|
||||
|
||||
Path.prototype.elements = function() {
|
||||
return this.v.slice();
|
||||
};
|
||||
|
||||
Path.prototype.contains = function(other) {
|
||||
let i;
|
||||
if (other.length > this.length) {
|
||||
return false;
|
||||
}
|
||||
for (i = 0; i < other.length; i += 1) {
|
||||
if (this.v[i] !== other.v[i]) {
|
||||
return false;
|
||||
['push', 'pop', 'shift', 'unshift', 'splice'].forEach(fn => {
|
||||
Object.defineProperty(Path.prototype, fn, {
|
||||
value(...args) {
|
||||
return this.v[fn](...args);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
};
|
||||
|
||||
Path.prototype.ancestorOf = function(other) {
|
||||
return other.contains(this) && other.length !== this.length;
|
||||
};
|
||||
|
||||
Path.prototype.descendantOf = function(other) {
|
||||
return this.contains(other) && other.length !== this.length;
|
||||
};
|
||||
|
||||
Path.prototype.commonPrefixPath = function(other) {
|
||||
const len = this.length > other.length ? other.length : this.length;
|
||||
let i;
|
||||
const ret = [];
|
||||
|
||||
for (i = 0; i < len; i += 1) {
|
||||
if (this.v[i] === other.v[i]) {
|
||||
ret.push(this.v[i]);
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return new Path(ret);
|
||||
};
|
||||
|
||||
['push', 'pop', 'shift', 'unshift', 'splice'].forEach(f => {
|
||||
Path.prototype[f] = function(...args) {
|
||||
const v = this.v;
|
||||
return v[f](...args);
|
||||
};
|
||||
});
|
||||
});
|
||||
|
||||
Path.compare = function(a, b) {
|
||||
const al = a.length;
|
||||
const bl = b.length;
|
||||
if (al < bl) {
|
||||
return -1;
|
||||
}
|
||||
if (al > bl) {
|
||||
return 1;
|
||||
}
|
||||
const astr = a.toString();
|
||||
const bstr = b.toString();
|
||||
return astr < bstr ? -1 : astr > bstr ? 1 : 0;
|
||||
};
|
||||
|
||||
Object.defineProperty(Path.prototype, 'length', {
|
||||
enumerable: true,
|
||||
get() {
|
||||
|
||||
Reference in New Issue
Block a user