Skip to main content

grepString (function)

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, grepArray, String.prototype.grep, and Array.prototype.grep.

const grepString: {
(
str: string,
pattern: string | RegExp,
options: GrepOptions & {
details: true;
},
): Array<GrepMatchDetail>;
(str: string, pattern: string | RegExp, options?: GrepOptions): Array<string>;
};

grepString(...) (call signature)

(str: string, pattern: string | RegExp, options: GrepOptions & {
details: true;
}): Array<GrepMatchDetail>;

grepString(...) (call signature)

(str: string, pattern: string | RegExp, options?: GrepOptions): Array<string>;

grepArray (function)

Returns those Array items matching the specified pattern, as either an Array of items or an Array of detail objects.

  • @param targetArray — The Array of strings to search through. Non-strings will be coerced to string during matching.
  • @param pattern — The pattern to find. Can be a string or a RegExp.
  • @param options — Options which control matching behavior.

See also grepString, grepFile, String.prototype.grep, and Array.prototype.grep.

const grepArray: {
<T>(
targetArray: Array<T>,
pattern: string | RegExp,
options: GrepOptions & {
details: true;
},
): Array<GrepMatchDetail<T>>;
<T>(
targetArray: Array<T>,
pattern: string | RegExp,
options?: GrepOptions,
): Array<T>;
};

grepArray(...) (call signature)

<T>(targetArray: Array<T>, pattern: string | RegExp, options: GrepOptions & {
details: true;
}): Array<GrepMatchDetail<T>>;

grepArray(...) (call signature)

<T>(targetArray: Array<T>, pattern: string | RegExp, options?: GrepOptions): Array<T>;

grepFile (function)

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 grepArray, grepString, String.prototype.grep, and Array.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>;
};

grepFile(...) (call signature)

(path: string | Path, pattern: string | RegExp, options: GrepOptions & {
details: true;
}): Array<GrepMatchDetail>;

grepFile(...) (call signature)

(path: string | Path, pattern: string | RegExp, options?: GrepOptions): Array<string>;

String (interface)

interface String {
grep: {
(
pattern: string | RegExp,
options: GrepOptions & {
details: true;
},
): Array<GrepMatchDetail>;
(pattern: string | RegExp, options?: GrepOptions): Array<string>;
};
}

String.grep (function property)

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, grepArray, grepFile, and Array.prototype.grep.

grep: {
(pattern: string | RegExp, options: GrepOptions & {
details: true;
}): Array<GrepMatchDetail>;
(pattern: string | RegExp, options?: GrepOptions): Array<string>;
};

String.grep(...) (call signature)

(pattern: string | RegExp, options: GrepOptions & {
details: true;
}): Array<GrepMatchDetail>;

String.grep(...) (call signature)

(pattern: string | RegExp, options?: GrepOptions): Array<string>;

Array (interface)

interface Array<T> {
grep: {
(
pattern: string | RegExp,
options: GrepOptions & {
details: true;
},
): Array<GrepMatchDetail<T>>;
(pattern: string | RegExp, options?: GrepOptions): Array<T>;
};
}

Array.grep (function property)

Returns those Array items matching the specified pattern, as either an Array of items or an Array of detail objects.

  • @param pattern — The pattern to find. Can be a string or a RegExp.
  • @param options — Options which control matching behavior.

See also grepString, grepArray, grepFile, and String.prototype.grep.

grep: {
(pattern: string | RegExp, options: GrepOptions & {
details: true;
}): Array<GrepMatchDetail<T>>;
(pattern: string | RegExp, options?: GrepOptions): Array<T>;
};

Array.grep(...) (call signature)

(pattern: string | RegExp, options: GrepOptions & {
details: true;
}): Array<GrepMatchDetail<T>>;

Array.grep(...) (call signature)

(pattern: string | RegExp, options?: GrepOptions): Array<T>;

GrepOptions (interface)

declare interface GrepOptions {
inverse?: boolean;
details?: boolean;
}

GrepOptions.inverse (boolean property)

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;

GrepOptions.details (boolean property)

When details is true, the grep function returns an array of GrepMatchDetail objects instead of an array of strings. Defaults to false.

details?: boolean;

GrepMatchDetail (interface)

When grepString, grepArray, grepFile, or String.prototype.grep are called with the { details: true } option set, an Array of GrepMatchDetail objects is returned.

declare interface GrepMatchDetail<ItemType = string> {
lineNumber: number;
lineContent: ItemType;
matches: RegExpMatchArray;
index: number;
content: ItemType;
}

GrepMatchDetail.lineNumber (number property)

lineNumber: number;

GrepMatchDetail.lineContent (ItemType property)

lineContent: ItemType;

GrepMatchDetail.matches (RegExpMatchArray property)

matches: RegExpMatchArray;

GrepMatchDetail.index (number property)

Same as lineNumber - 1.

index: number;

GrepMatchDetail.content (ItemType property)

Alias for lineContent.

content: ItemType;