- grepString (function)
- grepFile (function)
- String (interface)
- GrepOptions (interface)
- GrepMatchDetail (interface)
Splits the string passed into it on \n
and then returns the lines matching
the specified pattern, as an array of strings or detail objects.
@param
str — The string to search through.@param
pattern — The pattern to find. Can be a string or a RegExp.@param
options — Options which control matching behavior.
See also grepFile and String.prototype.grep.
const grepString: {
(
str: string,
pattern: string | RegExp,
options: GrepOptions & {
details: true;
}
): Array<GrepMatchDetail>;
(str: string, pattern: string | RegExp, options?: GrepOptions): Array<string>;
};
(str: string, pattern: string | RegExp, options: GrepOptions & {
details: true;
}): Array<GrepMatchDetail>;
(str: string, pattern: string | RegExp, options?: GrepOptions): Array<string>;
Reads the file content at path
, splits it on \n
, and then returns the
lines matching the specified pattern, as an array of strings or detail objects.
@param
str — The string to search through.@param
pattern — The pattern to find. Can be a string or a RegExp.@param
options — Options which control matching behavior.
See also grepString and String.prototype.grep.
const grepFile: {
(
path: string | Path,
pattern: string | RegExp,
options: GrepOptions & {
details: true;
}
): Array<GrepMatchDetail>;
(
path: string | Path,
pattern: string | RegExp,
options?: GrepOptions
): Array<string>;
};
(path: string | Path, pattern: string | RegExp, options: GrepOptions & {
details: true;
}): Array<GrepMatchDetail>;
(path: string | Path, pattern: string | RegExp, options?: GrepOptions): Array<string>;
interface String {
grep: {
(
pattern: string | RegExp,
options: GrepOptions & {
details: true;
}
): Array<GrepMatchDetail>;
(pattern: string | RegExp, options?: GrepOptions): Array<string>;
};
}
Splits the target string on \n
and then returns the lines matching the
specified pattern, as an array of strings or detail objects.
@param
str — The string to search through.@param
pattern — The pattern to find. Can be a string or a RegExp.@param
options — Options which control matching behavior.
See also grepString and grepFile.
grep: {
(pattern: string | RegExp, options: GrepOptions & {
details: true;
}): Array<GrepMatchDetail>;
(pattern: string | RegExp, options?: GrepOptions): Array<string>;
};
(pattern: string | RegExp, options: GrepOptions & {
details: true;
}): Array<GrepMatchDetail>;
(pattern: string | RegExp, options?: GrepOptions): Array<string>;
declare interface GrepOptions {
inverse?: boolean;
details?: boolean;
}
When inverse
is true, the grep function returns those lines which DON'T
match the pattern, instead of those which do. Defaults to false
.
inverse?: boolean;
When details
is true, the grep function returns an array of
GrepMatchDetail objects instead of an array of strings. Defaults to
false
.
details?: boolean;
When grepString
, grepFile
, or String.prototype.grep
are called with the
{ details: true }
option set, an Array of GrepMatchDetail
objects is
returned.
declare interface GrepMatchDetail {
lineNumber: number;
lineContent: string;
matches: RegExpMatchArray;
}
lineNumber: number;
lineContent: string;
matches: RegExpMatchArray;