search
Find objects whose key matches a glob (default), regex, substring, or exact pattern. Streams matches as an async iterable, walking every page like listAll, with a glob's literal prefix pushed down automatically.
files.search(pattern, options?)
Find objects whose key matches pattern, walking every page like listAll. It’s a streaming async iterable of StoredFile, so it stays memory-bounded on large buckets and you can break to stop early.
// Glob is the default: `*` stays within a path segment, `?` matches one char.
for await (const file of files.search("avatars/*.png")) {
console.log(file.key, file.size);
}
// Collect into an array when you want them all at once:
const pdfs = await Array.fromAsync(files.search("invoices/2024/*.pdf"));
Matching is against the caller-facing key, so a client prefix on the instance is already stripped before the pattern is tested.
Glob syntax
"glob" mode uses standard glob semantics, powered by picomatch:
*— any run of characters within a path segment (does not cross/).**— a globstar segment that spans path segments. Write it as its own segment:photos/**/*.jpgmatches at any depth, including zero subfolders.?— a single non-/character.[a-z],{a,b}— character classes and brace alternation.!pattern— negation (matches everything except).
The pattern is anchored to the whole key, and dotfiles are matched (object keys are opaque, not hidden files). A glob with no wildcards is an exact match, not a substring — files.search("report.pdf") matches the key report.pdf and nothing else. Use match: "substring" for “contains”.
// Every JPEG at any depth under photos/:
for await (const file of files.search("photos/**/*.jpg")) {
// photos/cover.jpg, photos/2024/spain/beach.jpg, ...
}
Match modes
Pass a match mode to change how a string pattern is interpreted, or pass a RegExp directly (which always matches by regex and ignores match):
// Regular expression (string form):
files.search("\\.(png|jpe?g)$", { match: "regex" });
// ...or a RegExp instance:
files.search(/\.(png|jpe?g)$/);
// Substring — key contains the text anywhere:
files.search("report", { match: "substring" });
// Exact — key equals the text:
files.search("invoices/2024/q1.pdf", { match: "exact" });
// Case-insensitive (any mode):
files.search("*.PNG", { caseInsensitive: true });
An invalid regex pattern throws a FilesError before the walk begins.
Scoping the walk with prefix
search reads every page under a prefix, following the cursor. For a glob, the literal head of the pattern is pushed down automatically as that prefix, so files.search("uploads/2024/*.pdf") scopes the walk to the uploads/2024 prefix rather than the whole bucket.
Other modes carry no inferable prefix, so for a regex, substring, or caseInsensitive search over a large bucket, pass prefix yourself to bound the walk:
// Only walk logs/ — then regex-match within it:
files.search("error|panic", { match: "regex", prefix: "logs/" });
A glob’s auto push-down is disabled when caseInsensitive is set (a provider’s prefix filter is case-sensitive), so combine caseInsensitive with an explicit prefix to scope it.
Stopping early
maxResults caps the number of matches yielded; because the walk is lazy, it also stops paging once the cap is hit. Equivalently, break out of the loop.
// First 10 matches, then stop fetching pages:
const recent = await Array.fromAsync(
files.search("**/*.log", { maxResults: 10 })
);
Provider support
search runs on every adapter, since it’s built on listAll — there’s no per-provider search capability and nothing to gate. The two listAll caveats carry over: on Netlify Blobs omit limit to walk everything, and the non-recursive Box / OneDrive / SharePoint adapters only see the immediate children of the root folder. An unbounded search with no prefix walks the whole bucket by design.
Options
prefix?string
Restrict the underlying walk to keys starting with this prefix. For a glob pattern a literal prefix is inferred automatically (`uploads/2024/*.pdf` walks only the `uploads/2024` prefix); set this explicitly to bound a `regex`, `substring`, or `caseInsensitive` search — which have no inferable prefix — to part of a large bucket. Composes with the {@link Files} instance `prefix` exactly like {@link ListOptions.prefix}.
stringlimit?number
Page size for each underlying `list()` call — the walk's batch size, not a cap on results. See {@link ListOptions.limit}.
numbermaxResults?number
Stop after yielding this many matches. Omit to yield every match (the walk still pages lazily, so memory stays bounded).
numbermatch?SearchMatch
How to interpret a string `pattern`. Defaults to `"glob"`. Ignored when `pattern` is a `RegExp`.
SearchMatchcaseInsensitive?boolean
Match case-insensitively. Adds the `i` flag for `glob` and `regex` and lowercases both sides for `substring` and `exact`. A `RegExp` that already sets its own `i` flag is honored regardless. When set, the automatic glob prefix push-down is disabled (a provider prefix filter is case-sensitive), so pass an explicit `prefix` to bound a case-insensitive search. Defaults to `false`.
booleansignal?AbortSignal
Abort the operation when this signal is aborted. When both constructor and per-call signals are provided, either one can abort the call.
AbortSignaltimeout?number
Overall timeout in milliseconds, applied to each attempt. A timeout aborts the operation and is not retried. `0` or a negative value disables timeout handling.
numberretries?RetryOptions
Retry provider failures. A number is treated as `{ max: number }`.
RetryOptionsThe match mode is one of:
toString() => string
Returns a string representation of a string.
() => stringcharAt(pos: number) => string
Returns the character at the specified index.
(pos: number) => stringcharCodeAt(index: number) => number
Returns the Unicode value of the character at the specified location.
(index: number) => numberconcat(...strings: string[]) => string
Returns a string that contains the concatenation of two or more strings.
(...strings: string[]) => stringindexOf(searchString: string, position?: number | undefined) => number
Returns the position of the first occurrence of a substring, or -1 if it is not present.
(searchString: string, position?: number | undefined) => numberlastIndexOf(searchString: string, position?: number | undefined) => number
Returns the last occurrence of a substring in the string, or -1 if it is not present.
(searchString: string, position?: number | undefined) => numberlocaleCompare{ (that: string): number; (that: string, locales?: string | string[] | undefined, options?: CollatorOptions | undefined): number; (that: string, locales?: LocalesArgument, options?: CollatorOptions | undefined): number; }
Determines whether two strings are equivalent in the current locale. Determines whether two strings are equivalent in the current or specified locale.
{ (that: string): number; (that: string, locales?: string | string[] | undefined, options?: CollatorOptions | undefined): number; (that: string, locales?: LocalesArgument, options?: CollatorOptions | undefined): number; }match{ (regexp: string | RegExp): RegExpMatchArray | null; (matcher: { [Symbol.match](string: string): RegExpMatchArray | null; }): RegExpMatchArray | null; }
Matches a string with a regular expression, and returns an array containing the results of that search. Matches a string or an object that supports being matched against, and returns an array containing the results of that search, or null if no matches are found.
{ (regexp: string | RegExp): RegExpMatchArray | null; (matcher: { [Symbol.match](string: string): RegExpMatchArray | null; }): RegExpMatchArray | null; }replace{ (searchValue: string | RegExp, replaceValue: string): string; (searchValue: string | RegExp, replacer: (substring: string, ...args: any[]) => string): string; (searchValue: { ...; }, replaceValue: string): string; (searchValue: { ...; }, replacer: (substring: string, ...args: any[]) => string): string; }
Replaces text in a string, using a regular expression or search string. Passes a string and {@linkcode replaceValue} to the `[Symbol.replace]` method on {@linkcode searchValue}. This method is expected to implement its own replacement algorithm. Replaces text in a string, using an object that supports replacement within a string.
{ (searchValue: string | RegExp, replaceValue: string): string; (searchValue: string | RegExp, replacer: (substring: string, ...args: any[]) => string): string; (searchValue: { ...; }, replaceValue: string): string; (searchValue: { ...; }, replacer: (substring: string, ...args: any[]) => string): string; }search{ (regexp: string | RegExp): number; (searcher: { [Symbol.search](string: string): number; }): number; }
Finds the first substring match in a regular expression search.
{ (regexp: string | RegExp): number; (searcher: { [Symbol.search](string: string): number; }): number; }slice(start?: number | undefined, end?: number | undefined) => string
Returns a section of a string.
(start?: number | undefined, end?: number | undefined) => stringsplit{ (separator: string | RegExp, limit?: number | undefined): string[]; (splitter: { [Symbol.split](string: string, limit?: number | undefined): string[]; }, limit?: number | undefined): string[]; }
Split a string into substrings using the specified separator and return them as an array.
{ (separator: string | RegExp, limit?: number | undefined): string[]; (splitter: { [Symbol.split](string: string, limit?: number | undefined): string[]; }, limit?: number | undefined): string[]; }substring(start: number, end?: number | undefined) => string
Returns the substring at the specified location within a String object.
(start: number, end?: number | undefined) => stringtoLowerCase() => string
Converts all the alphabetic characters in a string to lowercase.
() => stringtoLocaleLowerCase{ (locales?: string | string[] | undefined): string; (locales?: LocalesArgument): string; }
Converts all alphabetic characters to lowercase, taking into account the host environment's current locale.
{ (locales?: string | string[] | undefined): string; (locales?: LocalesArgument): string; }toUpperCase() => string
Converts all the alphabetic characters in a string to uppercase.
() => stringtoLocaleUpperCase{ (locales?: string | string[] | undefined): string; (locales?: LocalesArgument): string; }
Returns a string where all alphabetic characters have been converted to uppercase, taking into account the host environment's current locale.
{ (locales?: string | string[] | undefined): string; (locales?: LocalesArgument): string; }trim() => string
Removes the leading and trailing white space and line terminator characters from a string.
() => stringlengthpping t
Returns the length of a String object.
pping tsubstr(from: number, length?: number | undefined) => string
Gets a substring beginning at the specified location and having the specified length.
(from: number, length?: number | undefined) => stringvalueOf() => string
Returns the primitive value of the specified object.
() => stringcodePointAt(pos: number) => number | undefined
Returns a nonnegative integer Number less than 1114112 (0x110000) that is the code point value of the UTF-16 encoded code point starting at the string element at position pos in the String resulting from converting this object to a String. If there is no element at that position, the result is undefined. If a valid UTF-16 surrogate pair does not begin at pos, the result is the code unit at pos.
(pos: number) => number | undefinedincludes(searchString: string, position?: number | undefined) => boolean
Returns true if searchString appears as a substring of the result of converting this object to a String, at one or more positions that are greater than or equal to position; otherwise, returns false.
(searchString: string, position?: number | undefined) => booleanendsWith(searchString: string, endPosition?: number | undefined) => boolean
Returns true if the sequence of elements of searchString converted to a String is the same as the corresponding elements of this object (converted to a String) starting at endPosition – length(this). Otherwise returns false.
(searchString: string, endPosition?: number | undefined) => booleannormalize{ (form: "NFC" | "NFD" | "NFKC" | "NFKD"): string; (form?: string | undefined): string; }
Returns the String value result of normalizing the string into the normalization form named by form as specified in Unicode Standard Annex #15, Unicode Normalization Forms.
{ (form: "NFC" | "NFD" | "NFKC" | "NFKD"): string; (form?: string | undefined): string; }repeat(count: number) => string
Returns a String value that is made from count copies appended together. If count is 0, the empty string is returned.
(count: number) => stringstartsWith(searchString: string, position?: number | undefined) => boolean
Returns true if the sequence of elements of searchString converted to a String is the same as the corresponding elements of this object (converted to a String) starting at position. Otherwise returns false.
(searchString: string, position?: number | undefined) => booleananchor(name: string) => string
Returns an `<a>` HTML anchor element and sets the name attribute to the text value
(name: string) => stringbig() => string
Returns a `<big>` HTML element
() => stringblink() => string
Returns a `<blink>` HTML element
() => stringbold() => string
Returns a `<b>` HTML element
() => stringfixed() => string
Returns a `<tt>` HTML element
() => stringfontcolor(color: string) => string
Returns a `<font>` HTML element and sets the color attribute value
(color: string) => stringfontsize{ (size: number): string; (size: string): string; }
Returns a `<font>` HTML element and sets the size attribute value
{ (size: number): string; (size: string): string; }italics() => string
Returns an `<i>` HTML element
() => stringlink(url: string) => string
Returns an `<a>` HTML element and sets the href attribute value
(url: string) => stringsmall() => string
Returns a `<small>` HTML element
() => stringstrike() => string
Returns a `<strike>` HTML element
() => stringsub() => string
Returns a `<sub>` HTML element
() => stringsup() => string
Returns a `<sup>` HTML element
() => stringpadStart(maxLength: number, fillString?: string | undefined) => string
Pads the current string with a given string (possibly repeated) so that the resulting string reaches a given length. The padding is applied from the start (left) of the current string.
(maxLength: number, fillString?: string | undefined) => stringpadEnd(maxLength: number, fillString?: string | undefined) => string
Pads the current string with a given string (possibly repeated) so that the resulting string reaches a given length. The padding is applied from the end (right) of the current string.
(maxLength: number, fillString?: string | undefined) => stringtrimEnd() => string
Removes the trailing white space and line terminator characters from a string.
() => stringtrimStart() => string
Removes the leading white space and line terminator characters from a string.
() => stringtrimLeft() => string
Removes the leading white space and line terminator characters from a string.
() => stringtrimRight() => string
Removes the trailing white space and line terminator characters from a string.
() => stringmatchAll(regexp: RegExp) => RegExpStringIterator<RegExpExecArray>
Matches a string with a regular expression, and returns an iterable of matches containing the results of that search.
(regexp: RegExp) => RegExpStringIterator<RegExpExecArray>replaceAll{ (searchValue: string | RegExp, replaceValue: string): string; (searchValue: string | RegExp, replacer: (substring: string, ...args: any[]) => string): string; }
Replace all instances of a substring in a string, using a regular expression or search string.
{ (searchValue: string | RegExp, replaceValue: string): string; (searchValue: string | RegExp, replacer: (substring: string, ...args: any[]) => string): string; }at(index: number) => string | undefined
Returns a new String consisting of the single UTF-16 code unit located at the specified index.
(index: number) => string | undefinedisWellFormed() => boolean
Returns true if all leading surrogates and trailing surrogates appear paired and in order.
() => booleantoWellFormed() => string
Returns a string where all lone or out-of-order surrogates have been replaced by the Unicode replacement character (U+FFFD).
() => string__@iterator@1034() => StringIterator<string>
Iterator
() => StringIterator<string>