-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
29 additions
and
0 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,29 @@ | ||
import { isObject } from 'lodash-unified' | ||
import symbolsOf from '../symbolsOf' | ||
|
||
/** | ||
* 合并符号属性到目标对象上 | ||
* | ||
* @example | ||
* ```ts | ||
* const obj = {} | ||
* | ||
* const obj1 = {} | ||
* obj1[Symbol('key1')] = 1 | ||
* | ||
* const obj2 = {} | ||
* obj2[Symbol('key2')] = 2 | ||
* | ||
* assignSymbols(obj, obj1, obj2) | ||
* obj // => { [Symbol('key1')]: 1, [Symbol('key2')]: 2 } | ||
* ``` | ||
*/ | ||
export default function assignSymbols<T extends object>(o: T, ...sources): T { | ||
if (isObject(o)) { | ||
for (const source of sources) { | ||
const symbols = symbolsOf(source || {}) | ||
for (const syb of symbols) o[syb] = source[syb] | ||
} | ||
} | ||
return o | ||
} |