0.2.2 • Published 5 months ago

@rust-gear/glob v0.2.2

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
5 months ago

@rust-gear/glob

A high-performance globbing library for Node.js, powered by native Rust code.

Installation

npm install --save-dev @rust-gear/glob

Usage

import { globSync, glob } from "@rust-gear/glob";

const files = globSync("src/**/*.rs");
console.log(files);

const filesAsync = await glob("src/**/*.rs");
console.log(filesAsync);

Options

You can pass an options object as the second argument to globSync/glob.

Return path type:
If the pattern is absolute, absolute paths are returned.
If the pattern is relative, paths are returned relative to the specified cwd.

OptionTypeDescription
cwdstringCurrent working directory for searching
excludestring[]Array of glob patterns to exclude

Example

// Relative pattern, returns paths relative to cwd
const files = globSync("**/*.rs", {
  cwd: "src",
  exclude: ["**/test/**", "**/target/**"],
});

// Convert all relative paths to absolute paths
const absFiles = globSync("**/*.rs", {
  cwd: "src",
  exclude: ["**/test/**", "**/target/**"],
}).map((f) => path.resolve(cwd(), f));

// Absolute pattern, returns absolute paths
const absoluteFiles = globSync("/Users/foo/project/src/**/*.rs");

API

globSync(pattern: string | string[], options?: GlobOptions): string[]
Synchronously returns an array of file paths.

glob(pattern: string | string[], options?: GlobOptions): Promise<string[]>
Asynchronously returns an array of file paths.

License

Apache-2.0

0.2.2

5 months ago

0.2.1

5 months ago

0.2.0

5 months ago