// given a glob pattern, find the base path for all files that match the glob

// Example:
// Input: 'foo/bar/baz/**/qux/*.css'
// Output: 'foo/bar/baz'

const path = require('path')

function getBaseOfGlobPattern(pattern) {
    let index = -1
    const parts = pattern.split(/[\/\\]+/)
    for (let i = 0; i < parts.length; i++) {
        if (/[*?]|\[.+\]/.test(parts[i])) {
            index = i
            break
        }
    }
    return index === - 1 ? '' : path.join(...parts.slice(0, index))
}

console.log(getBaseOfGlobPattern('foo/bar/baz/**/qx/*.css'))

Embed on website

To embed this program on your website, copy the following code and paste it into your website's HTML: