mono/packages/commons/dist/glob-base.js
2025-01-24 20:47:57 +01:00

47 lines
1.3 KiB
JavaScript

/*!
* glob-base <https://github.com/jonschlinkert/glob-base>
*
* Copyright (c) 2015, Jon Schlinkert.
* Licensed under the MIT License.
*/
import { dirname as pathDirname } from 'path';
import { hasMagic } from 'glob';
import { globParent } from './glob-parent.js';
function dirname(glob) {
if (glob.slice(-1) === '/')
return glob;
return pathDirname(glob);
}
export const globBase = (pattern) => {
if (typeof pattern !== 'string') {
throw new TypeError('glob-base expects a string.');
}
const res = {
base: globParent(pattern),
isGlob: hasMagic(pattern),
glob: ''
};
if (res.base !== '.') {
res.glob = pattern.substr(res.base.length);
if (res.glob.charAt(0) === '/') {
res.glob = res.glob.substr(1);
}
}
else {
res.glob = pattern;
}
if (!res.isGlob) {
res.base = dirname(pattern);
res.glob = res.base !== '.'
? pattern.substr(res.base.length)
: pattern;
}
if (res.glob.substr(0, 2) === './') {
res.glob = res.glob.substr(2);
}
if (res.glob.charAt(0) === '/') {
res.glob = res.glob.substr(1);
}
return res;
};
//# sourceMappingURL=glob-base.js.map