Skip to content

Latest commit

 

History

History
207 lines (161 loc) · 5.62 KB

grep.md

File metadata and controls

207 lines (161 loc) · 5.62 KB

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 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>;
};

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>;

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 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>;
};

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 and grepFile.

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>;

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, 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;
}

GrepMatchDetail.lineNumber (number property)

lineNumber: number;

GrepMatchDetail.lineContent (string property)

lineContent: string;

GrepMatchDetail.matches (RegExpMatchArray property)

matches: RegExpMatchArray;