2 * glob-base <https://github.com/jonschlinkert/glob-base>
4 * Copyright (c) 2015, Jon Schlinkert.
5 * Licensed under the MIT License.
10 var path = require('path');
11 var parent = require('glob-parent');
12 var isGlob = require('is-glob');
14 module.exports = function globBase(pattern) {
15 if (typeof pattern !== 'string') {
16 throw new TypeError('glob-base expects a string.');
20 res.base = parent(pattern);
21 res.isGlob = isGlob(pattern);
23 if (res.base !== '.') {
24 res.glob = pattern.substr(res.base.length);
25 if (res.glob.charAt(0) === '/') {
26 res.glob = res.glob.substr(1);
33 res.base = dirname(pattern);
34 res.glob = res.base !== '.'
35 ? pattern.substr(res.base.length)
39 if (res.glob.substr(0, 2) === './') {
40 res.glob = res.glob.substr(2);
42 if (res.glob.charAt(0) === '/') {
43 res.glob = res.glob.substr(1);
48 function dirname(glob) {
49 if (glob.slice(-1) === '/') return glob;
50 return path.dirname(glob);