globby

  • Version 12.2.0
  • Published
  • 22.6 kB
  • 6 dependencies
  • MIT license

Install

npm i globby
yarn add globby
pnpm add globby

Overview

User-friendly glob matching

Index

Functions

function generateGlobTasks

generateGlobTasks: (
patterns: string | readonly string[],
options?: Options
) => GlobTask[];
  • Note that you should avoid running the same tasks multiple times as they contain a file system cache. Instead, run this method each time to ensure file system changes are taken into consideration.

    Parameter patterns

    See the supported [glob patterns](https://github.com/sindresorhus/globby#globbing-patterns).

    Parameter options

    See the [fast-glob options](https://github.com/mrmlnc/fast-glob#options-3) in addition to the ones in this package.

    Returns

    An object in the format {pattern: string, options: object}, which can be passed as arguments to [fast-glob](https://github.com/mrmlnc/fast-glob). This is useful for other globbing-related packages.

function globby

globby: {
(
patterns: string | readonly string[],
options: Options & { objectMode: true }
): Promise<GlobEntry[]>;
(patterns: string | readonly string[], options?: Options): Promise<string[]>;
};
  • Find files and directories using glob patterns.

    Note that glob patterns can only contain forward-slashes, not backward-slashes, so if you want to construct a glob pattern from path components, you need to use path.posix.join() instead of path.join().

    Parameter patterns

    See the supported [glob patterns](https://github.com/sindresorhus/globby#globbing-patterns).

    Parameter options

    See the [fast-glob options](https://github.com/mrmlnc/fast-glob#options-3) in addition to the ones in this package.

    Returns

    The matching paths.

    Example 1

    import {globby} from 'globby';
    const paths = await globby(['*', '!cake']);
    console.log(paths);
    //=> ['unicorn', 'rainbow']

function globbyStream

globbyStream: (
patterns: string | readonly string[],
options?: Options
) => NodeJS.ReadableStream;
  • Find files and directories using glob patterns.

    Note that glob patterns can only contain forward-slashes, not backward-slashes, so if you want to construct a glob pattern from path components, you need to use path.posix.join() instead of path.join().

    Parameter patterns

    See the supported [glob patterns](https://github.com/sindresorhus/globby#globbing-patterns).

    Parameter options

    See the [fast-glob options](https://github.com/mrmlnc/fast-glob#options-3) in addition to the ones in this package.

    Returns

    The stream of matching paths.

    Example 1

    import {globbyStream} from 'globby';
    for await (const path of globbyStream('*.tmp')) {
    console.log(path);
    }

function globbySync

globbySync: {
(
patterns: string | readonly string[],
options: Options & { objectMode: true }
): GlobEntry[];
(patterns: string | readonly string[], options?: Options): string[];
};
  • Find files and directories using glob patterns.

    Note that glob patterns can only contain forward-slashes, not backward-slashes, so if you want to construct a glob pattern from path components, you need to use path.posix.join() instead of path.join().

    Parameter patterns

    See the supported [glob patterns](https://github.com/sindresorhus/globby#globbing-patterns).

    Parameter options

    See the [fast-glob options](https://github.com/mrmlnc/fast-glob#options-3) in addition to the ones in this package.

    Returns

    The matching paths.

function isDynamicPattern

isDynamicPattern: (
patterns: string | readonly string[],
options?: FastGlobOptionsWithoutCwd & { readonly cwd?: URL | string }
) => boolean;
  • Note that the options affect the results.

    This function is backed by [fast-glob](https://github.com/mrmlnc/fast-glob#isdynamicpatternpattern-options).

    Parameter patterns

    See the supported [glob patterns](https://github.com/sindresorhus/globby#globbing-patterns).

    Parameter options

    See the [fast-glob options](https://github.com/mrmlnc/fast-glob#options-3).

    Returns

    Whether there are any special glob characters in the patterns.

function isGitIgnored

isGitIgnored: (options?: GitignoreOptions) => Promise<GlobbyFilterFunction>;
  • .gitignore files matched by the ignore config are not used for the resulting filter function.

    Returns

    A filter function indicating whether a given path is ignored via a .gitignore file.

    Example 1

    import {isGitIgnored} from 'globby';
    const isIgnored = await isGitIgnored();
    console.log(isIgnored('some/file'));

function isGitIgnoredSync

isGitIgnoredSync: (options?: GitignoreOptions) => GlobbyFilterFunction;
  • Returns

    A filter function indicating whether a given path is ignored via a .gitignore file.

    See Also

    • isGitIgnored

Interfaces

interface GitignoreOptions

interface GitignoreOptions {}

    property cwd

    readonly cwd?: URL | string;

      property ignore

      readonly ignore?: readonly string[];

        interface GlobTask

        interface GlobTask {}

          property options

          readonly options: Options;

            property pattern

            readonly pattern: string;

              interface Options

              interface Options extends FastGlobOptionsWithoutCwd {}

                property cwd

                readonly cwd?: URL | string;
                • The current working directory in which to search.

                  process.cwd()

                property expandDirectories

                readonly expandDirectories?: ExpandDirectoriesOption;
                • If set to true, globby will automatically glob directories for you. If you define an Array it will only glob files that matches the patterns inside the Array. You can also define an Object with files and extensions like in the example below.

                  Note that if you set this option to false, you won't get back matched directories unless you set onlyFiles: false.

                  true

                  Example 1

                  ``` import {globby} from 'globby';

                  const paths = await globby('images', { expandDirectories: { files: ['cat', 'unicorn', '*.jpg'], extensions: ['png'] } });

                  console.log(paths); //=> ['cat.png', 'unicorn.png', 'cow.jpg', 'rainbow.jpg'] ```

                property gitignore

                readonly gitignore?: boolean;
                • Respect ignore patterns in .gitignore files that apply to the globbed files.

                  false

                Type Aliases

                type ExpandDirectoriesOption

                type ExpandDirectoriesOption =
                | boolean
                | readonly string[]
                | { files?: readonly string[]; extensions?: readonly string[] };

                  type FastGlobOptionsWithoutCwd

                  type FastGlobOptionsWithoutCwd = Omit<FastGlobOptions, 'cwd'>;

                    type GlobbyFilterFunction

                    type GlobbyFilterFunction = (path: URL | string) => boolean;

                      type GlobEntry

                      type GlobEntry = Entry;

                        Package Files (1)

                        Dependencies (6)

                        Dev Dependencies (10)

                        Peer Dependencies (0)

                        No peer dependencies.

                        Badge

                        To add a badge like this onejsDocs.io badgeto your package's README, use the codes available below.

                        You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/globby.

                        • Markdown
                          [![jsDocs.io](https://img.shields.io/badge/jsDocs.io-reference-blue)](https://www.jsdocs.io/package/globby)
                        • HTML
                          <a href="https://www.jsdocs.io/package/globby"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>