Skip to content

Commit

Permalink
bring back the other aliases
Browse files Browse the repository at this point in the history
Eases the code transition from older versions, why not.
  • Loading branch information
isaacs committed Mar 14, 2023
1 parent 589df96 commit 9e56c7a
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 22 deletions.
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ const {
} = require('glob')

// or default export is fine too, just returns the glob function
// with all the aliases attached.
import glob from 'glob'
// or using commonjs
const glob = require('glob')
Expand Down Expand Up @@ -157,26 +158,36 @@ for full options field desciptions.

Synchronous form of `glob()`.

Alias: `glob.sync()`

## `globIterate(pattern: string | string[], options?: GlobOptions) => AsyncGenerator<string>`

Return an async iterator for walking glob pattern matches.

Alias: `glob.iterate()`

## `globIterateSync(pattern: string | string[], options?: GlobOptions) => Generator<string>`

Return a sync iterator for walking glob pattern matches.

Alias: `glob.iterate.sync()`, `glob.sync.iterate()`

## `globStream(pattern: string | string[], options?: GlobOptions) => Minipass<string | Path>`

Return a stream that emits all the strings or `Path` objects and
then emits `end` when completed.

Alias: `glob.stream()`

## `globStreamSync(pattern: string | string[], options?: GlobOptions) => Minipass<string | Path>`

Syncronous form of `globStream()`. Will read all the matches as
fast as you consume them, even all in a single tick if you
consume them immediately, but will still respond to backpressure
if they're not consumed immediately.

Alias: `glob.stream.sync()`, `glob.sync.stream()`

## `hasMagic(pattern: string | string[], options?: GlobOptions) => boolean`

Returns `true` if the provided pattern contains any "magic" glob
Expand Down
5 changes: 5 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# changeglob

## 9.3

- Add aliases for methods. `glob.sync`, `glob.stream`,
`glob.stream.sync`, etc.

## 9.2

- Support using a custom fs object, which is passed to PathScurry
Expand Down
61 changes: 39 additions & 22 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,57 +121,69 @@ export async function glob(
}

/**
* Return an async iterator for walking glob pattern matches.
* Return a sync iterator for walking glob pattern matches.
*/
export function globIterate(
export function globIterateSync(
pattern: string | string[],
options?: GlobOptionsWithFileTypesUnset | undefined
): AsyncGenerator<string, void, void>
export function globIterate(
): Generator<string, void, void>
export function globIterateSync(
pattern: string | string[],
options: GlobOptionsWithFileTypesTrue
): AsyncGenerator<Path, void, void>
export function globIterate(
): Generator<Path, void, void>
export function globIterateSync(
pattern: string | string[],
options: GlobOptionsWithFileTypesFalse
): AsyncGenerator<string, void, void>
export function globIterate(
): Generator<string, void, void>
export function globIterateSync(
pattern: string | string[],
options: GlobOptions
): AsyncGenerator<Path, void, void> | AsyncGenerator<string, void, void>
export function globIterate(
): Generator<Path, void, void> | Generator<string, void, void>
export function globIterateSync(
pattern: string | string[],
options: GlobOptions = {}
) {
return new Glob(pattern, options).iterate()
return new Glob(pattern, options).iterateSync()
}

/**
* Return a sync iterator for walking glob pattern matches.
* Return an async iterator for walking glob pattern matches.
*/
export function globIterateSync(
export function globIterate(
pattern: string | string[],
options?: GlobOptionsWithFileTypesUnset | undefined
): Generator<string, void, void>
export function globIterateSync(
): AsyncGenerator<string, void, void>
export function globIterate(
pattern: string | string[],
options: GlobOptionsWithFileTypesTrue
): Generator<Path, void, void>
export function globIterateSync(
): AsyncGenerator<Path, void, void>
export function globIterate(
pattern: string | string[],
options: GlobOptionsWithFileTypesFalse
): Generator<string, void, void>
export function globIterateSync(
): AsyncGenerator<string, void, void>
export function globIterate(
pattern: string | string[],
options: GlobOptions
): Generator<Path, void, void> | Generator<string, void, void>
export function globIterateSync(
): AsyncGenerator<Path, void, void> | AsyncGenerator<string, void, void>
export function globIterate(
pattern: string | string[],
options: GlobOptions = {}
) {
return new Glob(pattern, options).iterateSync()
return new Glob(pattern, options).iterate()
}

// aliases: glob.sync.stream() glob.stream.sync() glob.sync() etc
export const streamSync = globStreamSync
export const stream = Object.assign(globStream, { sync: globStreamSync })
export const iterateSync = globIterateSync
export const iterate = Object.assign(globIterate, {
sync: globIterateSync,
})
export const sync = Object.assign(globSync, {
stream: globStreamSync,
iterate: globIterateSync,
})

/* c8 ignore start */
export { escape, unescape } from 'minimatch'
export { Glob } from './glob.js'
Expand All @@ -189,10 +201,15 @@ export type { MatchStream } from './walker.js'
export default Object.assign(glob, {
glob,
globSync,
sync,
globStream,
stream,
globStreamSync,
streamSync,
globIterate,
iterate,
globIterateSync,
iterateSync,
Glob,
hasMagic,
escape,
Expand Down

0 comments on commit 9e56c7a

Please sign in to comment.