mirror of
https://github.com/toss/es-toolkit.git
synced 2024-12-01 02:33:54 +03:00
perf(has/get): improve performance (#518)
This commit is contained in:
parent
7258981909
commit
b1bb77b602
@ -1,21 +1,3 @@
|
||||
/**
|
||||
* Converts a deep key string into an array of path segments.
|
||||
*
|
||||
* This function takes a string representing a deep key (e.g., 'a.b.c' or 'a[b][c]') and breaks it down into an array of strings, each representing a segment of the path.
|
||||
*
|
||||
* @param {string} deepKey - The deep key string to convert.
|
||||
* @returns {string[]} An array of strings, each representing a segment of the path.
|
||||
*
|
||||
* Examples:
|
||||
*
|
||||
* toPath('a.b.c') // Returns ['a', 'b', 'c']
|
||||
* toPath('a[b][c]') // Returns ['a', 'b', 'c']
|
||||
* toPath('.a.b.c') // Returns ['', 'a', 'b', 'c']
|
||||
* toPath('a["b.c"].d') // Returns ['a', 'b.c', 'd']
|
||||
* toPath('') // Returns []
|
||||
* toPath('.a[b].c.d[e]["f.g"].h') // Returns ['', 'a', 'b', 'c', 'd', 'e', 'f.g', 'h']
|
||||
*/
|
||||
export function toPath(deepKey: string): string[] {
|
||||
const ESCAPE_REGEXP = /\\(\\)?/g;
|
||||
const PROPERTY_REGEXP = RegExp(
|
||||
// Match anything that isn't a dot or bracket.
|
||||
@ -34,7 +16,24 @@ export function toPath(deepKey: string): string[] {
|
||||
'(?=(?:\\.|\\[\\])(?:\\.|\\[\\]|$))',
|
||||
'g'
|
||||
);
|
||||
|
||||
/**
|
||||
* Converts a deep key string into an array of path segments.
|
||||
*
|
||||
* This function takes a string representing a deep key (e.g., 'a.b.c' or 'a[b][c]') and breaks it down into an array of strings, each representing a segment of the path.
|
||||
*
|
||||
* @param {string} deepKey - The deep key string to convert.
|
||||
* @returns {string[]} An array of strings, each representing a segment of the path.
|
||||
*
|
||||
* Examples:
|
||||
*
|
||||
* toPath('a.b.c') // Returns ['a', 'b', 'c']
|
||||
* toPath('a[b][c]') // Returns ['a', 'b', 'c']
|
||||
* toPath('.a.b.c') // Returns ['', 'a', 'b', 'c']
|
||||
* toPath('a["b.c"].d') // Returns ['a', 'b.c', 'd']
|
||||
* toPath('') // Returns []
|
||||
* toPath('.a[b].c.d[e]["f.g"].h') // Returns ['', 'a', 'b', 'c', 'd', 'e', 'f.g', 'h']
|
||||
*/
|
||||
export function toPath(deepKey: string): string[] {
|
||||
const result: string[] = [];
|
||||
|
||||
if (deepKey[0] === '.') {
|
||||
|
Loading…
Reference in New Issue
Block a user