Security News
pnpm 9.5 Introduces Catalogs: Shareable Dependency Version Specifiers
pnpm 9.5 introduces a Catalogs feature, enabling shareable dependency version specifiers, reducing merge conflicts and improving support for monorepos.
globule
Advanced tools
Package description
The globule npm package is a utility for file system operations that involve matching file paths using glob patterns. It provides a simple and flexible way to find, read, and manipulate files based on patterns.
File Matching
This feature allows you to find files that match a specific glob pattern. In this example, it finds all JavaScript files in the 'src' directory and its subdirectories.
const globule = require('globule');
const matches = globule.find('src/**/*.js');
console.log(matches);
File Copying
This feature allows you to copy files that match a specific glob pattern to a new location. In this example, it copies all JavaScript files from the 'src' directory to the 'dist' directory.
const globule = require('globule');
globule.copy('src/**/*.js', 'dist');
File Deletion
This feature allows you to delete files that match a specific glob pattern. In this example, it deletes all JavaScript files in the 'dist' directory and its subdirectories.
const globule = require('globule');
globule.del('dist/**/*.js');
File Reading
This feature allows you to read the contents of files that match a specific glob pattern. In this example, it reads and logs the contents of all JavaScript files in the 'src' directory and its subdirectories.
const globule = require('globule');
const files = globule.find('src/**/*.js');
files.forEach(file => {
const content = globule.read(file);
console.log(content);
});
The 'glob' package is a popular library for matching files using glob patterns. It is similar to 'globule' but focuses solely on file matching without additional file manipulation features. It is widely used and has a simple API for finding files.
The 'fast-glob' package is a high-performance alternative to 'glob' and 'globule'. It offers faster file matching and supports advanced features like concurrency and caching. It is suitable for large projects where performance is critical.
The 'minimatch' package is a lightweight library for matching file paths against glob patterns. It is often used as a dependency in other packages and provides a simple and efficient way to perform pattern matching.
Readme
An easy-to-use wildcard globbing library.
Install the module with: npm install globule
var globule = require('globule');
var filepaths = globule.find('**/*.js');
Returns a unique array of all file or directory paths that match the given globbing pattern(s). This method accepts either comma separated globbing patterns or an array of globbing patterns. Paths matching patterns that begin with !
will be excluded from the returned array. Patterns are processed in order, so inclusion and exclusion order is significant.
globule.find(patterns [, options])
The options
object supports all glob library options, along with a few extras. These are the most commonly used:
filter
Either a valid fs.Stats method name or a function that will be passed the matched src
filepath and options
object as arguments. This function should return a Boolean
value.nonull
Retain globbing patterns in result set even if they fail to match files.matchBase
Patterns without slashes will match just the basename part. Eg. this makes *.js
work like **/*.js
.srcBase
Patterns will be matched relative to the specified path instead of the current working directory. This is a synonym for cwd
.prefixBase
Any specified srcBase
will be prefixed to all returned filepaths.Match one or more globbing patterns against one or more file paths. Returns a uniqued array of all file paths that match any of the specified globbing patterns. Both the patterns
and filepaths
arguments can be a single string or array of strings. Paths matching patterns that begin with !
will be excluded from the returned array. Patterns are processed in order, so inclusion and exclusion order is significant.
grunt.file.match(patterns, filepaths [, options])
This method contains the same signature and logic as the globule.match
method, but returns true
if any files were matched, otherwise false
.
grunt.file.isMatch(patterns, filepaths [, options])
Given a set of source file paths, returns an array of src-dest file mapping objects. Both src and dest paths may be renamed, depending on the options specified.
globule.mapping(filepaths [, options])
In addition to the options the globule.find
method supports, the options object also supports these properties:
srcBase
The directory from which patterns are matched. Any string specified as srcBase
is effectively stripped from the beginning of all matched paths.destBase
The specified path is prefixed to all dest
filepaths.ext
Remove anything after (and including) the first .
in the destination path, then append this value.extDot
Change the behavior of ext
, "first"
and "last"
will remove anything after the first or last .
in the destination filename, respectively. Defaults to "first"
.flatten
Remove the path component from all matched src files. The src file path is still joined to the specified destBase.rename
If specified, this function will be responsible for returning the final dest
filepath. By default, it flattens paths (if specified), changes extensions (if specified) and joins the matched path to the destBase
.This method is a convenience wrapper around the globule.find
and globule.mapping
methods.
globule.findMapping(patterns [, options])
Given the files foo/a.js
and foo/b.js
:
globule.find("foo/*.js")
// ["foo/a.js", "foo/b.js"]
globule.find("*.js", {srcBase: "foo"})
// ["a.js", "b.js"]
globule.find("*.js", {srcBase: "foo", prefixBase: true})
// ["foo/a.js", "foo/b.js"]
globule.findMapping("foo/*.js")
// [{src: "foo/a.js", dest: "foo/a.js"}, {src: "foo/b.js", dest: "foo/b.js"}]
globule.findMapping("foo/*.js", {destBase: "bar"})
// [{src: "foo/a.js", dest: "bar/foo/a.js"}, {src: "foo/b.js", dest: "bar/foo/b.js"}]
globule.findMapping("*.js", {srcBase: "foo", destBase: "bar"})
// [{src: "foo/a.js", dest: "bar/a.js"}, {src: "foo/b.js", dest: "bar/b.js"}]
globule.mapping(["foo/a.js", "foo/b.js"])
// [{src: "foo/a.js", dest: "foo/a.js"}, {src: "foo/b.js", dest: "foo/b.js"}]
globule.mapping(["foo/a.js", "foo/b.js"], {destBase: "bar"})
// [{src: "foo/a.js", dest: "bar/foo/a.js"}, {src: "foo/b.js", dest: "bar/foo/b.js"}]
globule.mapping(["a.js", "b.js"], {srcBase: "foo", destBase: "bar"})
// [{src: "foo/a.js", dest: "bar/a.js"}, {src: "foo/b.js", dest: "bar/b.js"}]
In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using Grunt.
(Nothing yet)
Copyright (c) 2013 "Cowboy" Ben Alman
Licensed under the MIT license.
FAQs
Unknown package
The npm package globule receives a total of 2,202,369 weekly downloads. As such, globule popularity was classified as popular.
We found that globule demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 3 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
pnpm 9.5 introduces a Catalogs feature, enabling shareable dependency version specifiers, reducing merge conflicts and improving support for monorepos.
Security News
A threat actor on BreachForums is selling an unverified npm vulnerability for account takeover, but npm has not officially confirmed the existence of this security concern.
Security News
Cyber insurance rates are dropping as the market matures, according to a new report projecting global premiums to reach $43 billion by 2030, driven by international market uptake and growth in the SME sector.