Skip to content

Commit 9e56c7a

Browse files
committed
bring back the other aliases
Eases the code transition from older versions, why not.
1 parent 589df96 commit 9e56c7a

File tree

3 files changed

+55
-22
lines changed

3 files changed

+55
-22
lines changed

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ const {
2929
} = require('glob')
3030

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

158159
Synchronous form of `glob()`.
159160

161+
Alias: `glob.sync()`
162+
160163
## `globIterate(pattern: string | string[], options?: GlobOptions) => AsyncGenerator<string>`
161164

162165
Return an async iterator for walking glob pattern matches.
163166

167+
Alias: `glob.iterate()`
168+
164169
## `globIterateSync(pattern: string | string[], options?: GlobOptions) => Generator<string>`
165170

166171
Return a sync iterator for walking glob pattern matches.
167172

173+
Alias: `glob.iterate.sync()`, `glob.sync.iterate()`
174+
168175
## `globStream(pattern: string | string[], options?: GlobOptions) => Minipass<string | Path>`
169176

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

180+
Alias: `glob.stream()`
181+
173182
## `globStreamSync(pattern: string | string[], options?: GlobOptions) => Minipass<string | Path>`
174183

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

189+
Alias: `glob.stream.sync()`, `glob.sync.stream()`
190+
180191
## `hasMagic(pattern: string | string[], options?: GlobOptions) => boolean`
181192

182193
Returns `true` if the provided pattern contains any "magic" glob

changelog.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# changeglob
22

3+
## 9.3
4+
5+
- Add aliases for methods. `glob.sync`, `glob.stream`,
6+
`glob.stream.sync`, etc.
7+
38
## 9.2
49

510
- Support using a custom fs object, which is passed to PathScurry

src/index.ts

Lines changed: 39 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -121,57 +121,69 @@ export async function glob(
121121
}
122122

123123
/**
124-
* Return an async iterator for walking glob pattern matches.
124+
* Return a sync iterator for walking glob pattern matches.
125125
*/
126-
export function globIterate(
126+
export function globIterateSync(
127127
pattern: string | string[],
128128
options?: GlobOptionsWithFileTypesUnset | undefined
129-
): AsyncGenerator<string, void, void>
130-
export function globIterate(
129+
): Generator<string, void, void>
130+
export function globIterateSync(
131131
pattern: string | string[],
132132
options: GlobOptionsWithFileTypesTrue
133-
): AsyncGenerator<Path, void, void>
134-
export function globIterate(
133+
): Generator<Path, void, void>
134+
export function globIterateSync(
135135
pattern: string | string[],
136136
options: GlobOptionsWithFileTypesFalse
137-
): AsyncGenerator<string, void, void>
138-
export function globIterate(
137+
): Generator<string, void, void>
138+
export function globIterateSync(
139139
pattern: string | string[],
140140
options: GlobOptions
141-
): AsyncGenerator<Path, void, void> | AsyncGenerator<string, void, void>
142-
export function globIterate(
141+
): Generator<Path, void, void> | Generator<string, void, void>
142+
export function globIterateSync(
143143
pattern: string | string[],
144144
options: GlobOptions = {}
145145
) {
146-
return new Glob(pattern, options).iterate()
146+
return new Glob(pattern, options).iterateSync()
147147
}
148148

149149
/**
150-
* Return a sync iterator for walking glob pattern matches.
150+
* Return an async iterator for walking glob pattern matches.
151151
*/
152-
export function globIterateSync(
152+
export function globIterate(
153153
pattern: string | string[],
154154
options?: GlobOptionsWithFileTypesUnset | undefined
155-
): Generator<string, void, void>
156-
export function globIterateSync(
155+
): AsyncGenerator<string, void, void>
156+
export function globIterate(
157157
pattern: string | string[],
158158
options: GlobOptionsWithFileTypesTrue
159-
): Generator<Path, void, void>
160-
export function globIterateSync(
159+
): AsyncGenerator<Path, void, void>
160+
export function globIterate(
161161
pattern: string | string[],
162162
options: GlobOptionsWithFileTypesFalse
163-
): Generator<string, void, void>
164-
export function globIterateSync(
163+
): AsyncGenerator<string, void, void>
164+
export function globIterate(
165165
pattern: string | string[],
166166
options: GlobOptions
167-
): Generator<Path, void, void> | Generator<string, void, void>
168-
export function globIterateSync(
167+
): AsyncGenerator<Path, void, void> | AsyncGenerator<string, void, void>
168+
export function globIterate(
169169
pattern: string | string[],
170170
options: GlobOptions = {}
171171
) {
172-
return new Glob(pattern, options).iterateSync()
172+
return new Glob(pattern, options).iterate()
173173
}
174174

175+
// aliases: glob.sync.stream() glob.stream.sync() glob.sync() etc
176+
export const streamSync = globStreamSync
177+
export const stream = Object.assign(globStream, { sync: globStreamSync })
178+
export const iterateSync = globIterateSync
179+
export const iterate = Object.assign(globIterate, {
180+
sync: globIterateSync,
181+
})
182+
export const sync = Object.assign(globSync, {
183+
stream: globStreamSync,
184+
iterate: globIterateSync,
185+
})
186+
175187
/* c8 ignore start */
176188
export { escape, unescape } from 'minimatch'
177189
export { Glob } from './glob.js'
@@ -189,10 +201,15 @@ export type { MatchStream } from './walker.js'
189201
export default Object.assign(glob, {
190202
glob,
191203
globSync,
204+
sync,
192205
globStream,
206+
stream,
193207
globStreamSync,
208+
streamSync,
194209
globIterate,
210+
iterate,
195211
globIterateSync,
212+
iterateSync,
196213
Glob,
197214
hasMagic,
198215
escape,

0 commit comments

Comments
 (0)