-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #14 from Nikaple/feat/circular-deps
- Loading branch information
Showing
11 changed files
with
4,710 additions
and
3,032 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
strict-peer-dependencies=false |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,20 @@ | ||
import { parsePath } from './internal'; | ||
|
||
/** | ||
* deeply get value by key | ||
* Deeply get value by key. | ||
* | ||
* @example | ||
* | ||
* deepGet({ a: { b: 1 } }, "a.b") // 1 | ||
* deepGet({ a: { b: [1] } }, "a.b.0") // 1 | ||
* deepGet({ a: { '?': [1] } }, 'a["?"][0]') // 1 | ||
*/ | ||
export const deepGet = (obj: any, path: string) => { | ||
export const deepGet = (obj: Record<string, unknown>, path: string) => { | ||
const keys = parsePath(path); | ||
|
||
let result: unknown = undefined; | ||
let result: any = obj; | ||
keys.forEach(part => { | ||
result = (result || obj)[part]; | ||
result = result[part]; | ||
}); | ||
return result; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,3 @@ | ||
/** | ||
* 对象的深层 get / set 方法,规则如下 | ||
* | ||
* 1. 表达普通对象 "a.b.z" | ||
* 2. 表达数组 "b[0].z" 或 "c.0.z" | ||
* 3. 表达数字 key "c["0"].z" | ||
* 4. 表达含 "." 的 key "d["b.c"].z" | ||
*/ | ||
export * from './flatten'; | ||
export * from './deep-get'; | ||
export * from './deep-set'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export interface UniFlattenOptions { | ||
circularReference: 'string' | 'symbol' | 'null'; | ||
} |