Repository navigation
Expand file tree
/
Copy pathpage.tsx
More file actions
315 lines (300 loc) · 9.93 KB
/
Copy pathpage.tsx
File metadata and controls
315 lines (300 loc) · 9.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
import dedent from 'dedent';
import type { Metadata } from 'next';
import Link from 'next/link';
import type { ReactNode } from 'react';
import { convertPathToPattern, type GlobOptions, isDynamicPattern } from 'tinyglobby';
import pkg from 'tinyglobby/package.json' with { type: 'json' };
import { Code } from '#components/Code.tsx';
export const metadata: Metadata = {
title: 'documentation'
};
export default function Page() {
return (
<main>
<h1>
tinyglobby documentation <small className="sub">v{pkg.version}</small>
</h1>
<h2 id="api">API</h2>
<APIEntry name="glob">
<p>Asynchronously match files following a glob pattern.</p>
<strong>Usage:</strong>
<Code lang="ts">
{dedent`
import { glob } from 'tinyglobby';
const files = await glob('src/**', {
cwd: './projects/best-cats'
});
`}
</Code>
</APIEntry>
<hr />
<APIEntry name="globSync">
<p>Synchronously match files following a glob pattern.</p>
<strong>Usage:</strong>
<Code lang="ts">
{dedent`
import { globSync } from 'tinyglobby';
const files = globSync('src/**', {
cwd: './projects/best-cats'
});
`}
</Code>
</APIEntry>
<hr />
<APIEntry name="convertPathToPattern">
<p>
Converts a path to a pattern depending on the platform. Identical to{' '}
<Link href="#escapePath">
<code>escapePath</code>
</Link>{' '}
on POSIX systems.
</p>
<strong>Usage:</strong>
<Code lang="ts">
{dedent`
import { convertPathToPattern } from 'tinyglobby';
convertPathToPattern('[413] home stuck funny moments*.mp4');
// Returns "${convertPathToPattern('[413] home stuck funny moments*.mp4')}"
`}
</Code>
</APIEntry>
<hr />
<APIEntry name="escapePath">
<p>Escapes a path's special characters depending on the platform.</p>
<strong>Usage:</strong>
<Code lang="ts">
{dedent`
import { escapePath } from 'tinyglobby';
escapePath('i use linux and i can use \\ in filenames!!()!');
// Returns "${convertPathToPattern('i use linux and i can use \\ in filenames!!()!')}"
`}
</Code>
</APIEntry>
<hr />
<APIEntry marginBottom={'3.9em'} name="isDynamicPattern">
<p>Checks if a pattern has dynamic parts.</p>
<p>
Has a few minor differences with{' '}
<Link target="_blank" href="https://github.com/mrmlnc/fast-glob">
<code>fast-glob</code>
</Link>{' '}
for better accuracy:
</p>
<ul>
<li>
Doesn't necessarily return <code>false</code> on patterns that include "<code>\\</code>".
</li>
<li>
Returns <code>true</code> if the pattern includes parentheses, regardless of them representing one single
pattern or not.
</li>
<li>
Returns <code>true</code> for unfinished glob extensions i.e. "<code>(h</code>", "<code>+(h</code>".
</li>
<li>
Returns <code>true</code> for unfinished brace expansions as long as they include "<code>,</code>" or "
<code>..</code>".
</li>
</ul>
<strong>Usage:</strong>
<Code lang="ts">
{dedent`
import { isDynamicPattern } from 'tinyglobby';
isDynamicPattern('my-dream.txt');
// ^ ${isDynamicPattern('my-dream.txt')}
isDynamicPattern('star.*');
// ^ ${isDynamicPattern('star.*')}
`}
</Code>
</APIEntry>
<h2 id="options">Options</h2>
<Code lang="ts">{"import type { GlobOptions } from 'tinyglobby';"}</Code>
<APIOption name="absolute" default="false">
<p>Whether to return absolute paths. Disable to have relative paths.</p>
</APIOption>
<hr />
<APIOption name="braceExpansion" default="true">
<p>
Enables support for brace expansion syntax, like "<code>{'{a,b}'}</code>" or "<code>{'{1..9}'}</code>".
</p>
</APIOption>
<hr />
<APIOption name="caseSensitiveMatch" default="true">
<p>Whether to match in case-sensitive mode.</p>
</APIOption>
<hr />
<APIOption name="cwd" default="process.cwd()">
<p>
The working directory in which to search. Results will be returned relative to this directory, unless{' '}
<Link href="#absolute">
<code>absolute</code>
</Link>{' '}
is set.
</p>
<p>
It is important to avoid globbing outside this directory when possible, even with absolute paths enabled, as
doing so can harm performance due to having to recalculate relative paths.
</p>
<Code lang="ts">
{dedent`
import { glob } from 'tinyglobby';
// Avoid this - will calculate it relative to \`process.cwd()\`!
await glob(\`\${searchDir}/*.ts\`, {
absolute: true
});
// Do this instead:
await glob(\`\${searchDir}/*.ts\`, {
absolute: true,
cwd: searchDir
});
`}
</Code>
</APIOption>
<hr />
<APIOption name="debug" default="false">
<p>Logs useful debug information. Meant for development purposes. Logs can change at any time.</p>
</APIOption>
<hr />
<APIOption name="deep" default="Infinity">
<p>Maximum directory depth to crawl.</p>
</APIOption>
<hr />
<APIOption name="dot" default="false">
<p>
Whether to return entries that start with a dot, like <code>.gitignore</code> or <code>.prettierrc</code>.
</p>
</APIOption>
<hr />
<APIOption name="expandDirectories" default="true">
<p>
Whether to automatically expand directory patterns. Important to disable if migrating from{' '}
<Link target="_blank" href="https://github.com/mrmlnc/fast-glob">
<code>fast-glob</code>.
</Link>
</p>
</APIOption>
<hr />
<APIOption name="extglob" default="true">
<p>
Enables support for extglobs, like "<code>+(pattern)</code>".
</p>
</APIOption>
<hr />
<APIOption name="followSymbolicLinks" default="true">
<p>Whether to traverse and include symbolic links. Can slightly affect performance.</p>
</APIOption>
<hr />
<APIOption name="fs" default="import('node:fs')">
<p>
An object that overrides{' '}
<Link href="https://nodejs.org/api/fs.html" target="_blank">
<code>node:fs</code>
</Link>{' '}
functions.
</p>
<Code lang="ts">
{dedent`
type FileSystemAdapter = {
readdir?: typeof fs.readdir;
readdirSync?: typeof fs.readdirSync;
realpath?: typeof fs.realpath;
realpathSync?: typeof fs.realpathSync;
stat?: typeof fs.stat;
statSync?: typeof fs.statSync;
};
`}
</Code>
</APIOption>
<hr />
<APIOption name="globstar" default="true">
<p>
Enables support for matching nested directories with globstars ("<code>**</code>"). If <code>false</code>, "
<code>**</code>" behaves exactly like "<code>*</code>".
</p>
</APIOption>
<hr />
<APIOption name="ignore" default="[]">
<p>Glob patterns to exclude from the results.</p>
</APIOption>
<hr />
<APIOption name="onlyDirectories" default="false">
<p>
Enable to only return directories. If <code>true</code>, disables{' '}
<Link href="#onlyFiles">
<code>onlyFiles</code>
</Link>
.
</p>
</APIOption>
<hr />
<APIOption name="onlyFiles" default="true">
<p>Enable to only return files.</p>
</APIOption>
<hr />
<APIOption name="signal" default="undefined">
<p>
An{' '}
<Link href="https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal" target="_blank">
<code>AbortSignal</code>
</Link>{' '}
to abort crawling the file system.
</p>
<Code lang="ts">
{dedent`
import { glob } from 'tinyglobby';
// Stops crawling if taking too long
await glob('**', {
signal: AbortSignal.timeout(1000)
});
`}
</Code>
</APIOption>
</main>
);
}
interface APIEntryProps {
name: keyof typeof import('tinyglobby');
marginBottom?: string | number;
children?: ReactNode;
}
function APIEntry(props: APIEntryProps) {
return (
<section className="entry">
<h3 id={props.name} style={props.marginBottom ? { marginBottom: props.marginBottom } : undefined}>
<Code meta="twoslash no-jsdoc" lang="ts">
{dedent`
import { ${props.name} } from 'tinyglobby';
// ---cut---
${props.name}
// ^?
`}
</Code>
</h3>
{props.children}
</section>
);
}
interface APIOptionProps {
name: keyof GlobOptions;
children?: ReactNode;
default: string;
}
function APIOption(props: APIOptionProps) {
return (
<section className="entry">
<h3 id={props.name}>
<Code meta="twoslash no-jsdoc" lang="ts">
{dedent`
import type { GlobOptions } from 'tinyglobby';
declare const ${props.name}: GlobOptions['${props.name}'];
// ---cut---
${props.name}
//^?
`}
</Code>
</h3>
{props.children}
<strong>Default:</strong> <code>{props.default}</code>
</section>
);
}