BUPKIS
    Preparing search index...

    Function parseKeypath

    • Parses a keypath string into an array of individual keys, supporting dot and bracket notation.

      Parsing rules:

      • Dot notation: Splits keys by . (e.g., 'foo.bar'['foo', 'bar']).
      • Bracket notation: Extracts keys inside []. If the key is a quoted string (single or double quotes), the quotes are removed (e.g., 'foo["bar-baz"]'['foo', 'bar-baz']). If the key is an integer (e.g., 'foo[0]'), it is parsed as a number.
      • Mixed notation: Supports combinations (e.g., 'foo.bar[0].baz'['foo', 'bar', 0, 'baz']).
      • Quoted keys: Keys inside brackets can be quoted with single or double quotes. Quotes are stripped, and the content is used as the key.
      • Numeric keys: If a bracketed key is an integer, it is returned as a number; otherwise, as a string.
      • Whitespace inside brackets is preserved as part of the key.
      • Does not support escape sequences inside quotes.

      Limitations:

      • Does not support symbol keys.
      • Does not handle escape characters inside quoted keys.

      Type Parameters

      • S extends string = string

      Parameters

      • keypath: Keypath<S>

        The keypath string to parse, using dot and/or bracket notation.

      Returns (string | number)[]

      An array of keys, where each key is a string or number. Bracketed integer keys are returned as numbers; all others as strings.

      parseKeypath('foo.bar'); // ['foo', 'bar']
      parseKeypath('foo[0].baz'); // ['foo', 0, 'baz']
      parseKeypath('foo["bar-baz"].quux'); // ['foo', 'bar-baz', 'quux']
      parseKeypath("foo['bar-baz'].quux"); // ['foo', 'bar-baz', 'quux']
      parseKeypath("arr[10]['spam']"); // ['arr', 10, 'spam']