glob-parent
's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.Name | Version | Size | License | Type | Vulnerabilities |
---|---|---|---|---|---|
is-glob | 3.1.0 | 3.31 kB | MIT | prod | |
path-dirname | 1.0.2 | 2.42 kB | MIT | prod |
Glob-parent is a popular npm package used to extract the non-magic parent path from a glob pattern. Its main function lies in taking a string and returning the part of the path before any glob configuration starts. This can be beneficial for developers who need to handle file paths in their JavaScript applications.
To use glob-parent in your JavaScript project, you first need to install it via npm, using the command npm install glob-parent
. After it's installed, you can require it in your JavaScript file and use the provided functions. For instance:
var globParent = require('glob-parent');
// Typical usage
globParent('path/to/*.js'); // Returns 'path/to'
// When provided a non-glob path, it returns the nearest dir
globParent('path/foo/bar.js'); // Returns 'path/foo'
Keep in mind that glob-parent also supports options, such as disabling the automatic conversion of slashes for Windows:
{
flipBackslashes: true;
}
Additionally, it also has rules for escaping special characters in glob patterns, for example:
// The [bar] needs to be escaped to be treated as a regular path character
globParent('foo/\\[bar]/'); // Returns 'foo/[bar]'
The documentation for glob-parent is located directly in the README.md file on the repository's main page located at https://github.com/gulpjs/glob-parent. In there, you can find information on how to use the package, its API, the rules for escaping special characters in glob patterns, and its limitations. The repository on GitHub also contains information on the package's license, its version history, and a link to the npm page where it is hosted.