-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: move sources length check to create-merger
- Loading branch information
Showing
6 changed files
with
61 additions
and
15 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
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,26 @@ | ||
/* | ||
* Copyright (c) 2023. | ||
* Author Peter Placzek (tada5hi) | ||
* For the full copyright and license information, | ||
* view the LICENSE file that was distributed with this source code. | ||
*/ | ||
|
||
import { createMerger } from './module'; | ||
import type { MergerResult } from './type'; | ||
|
||
/** | ||
* Assign source attributes to a target object. | ||
* | ||
* @param target | ||
* @param sources | ||
*/ | ||
export function assign<A extends Record<string, any>, B extends Record<string, any>[]>( | ||
target: A, | ||
...sources: B | ||
) : A & MergerResult<B> { | ||
return createMerger({ | ||
inPlace: true, | ||
priority: 'left', | ||
array: false, | ||
})(target, ...sources) as A & MergerResult<B>; | ||
} |
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 |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/* | ||
* Copyright (c) 2023. | ||
* Author Peter Placzek (tada5hi) | ||
* For the full copyright and license information, | ||
* view the LICENSE file that was distributed with this source code. | ||
*/ | ||
|
||
import {assign} from "../../src"; | ||
|
||
describe('src/presets', () => { | ||
it('should assign default properties', () => { | ||
let target = { | ||
foo: 'bar' | ||
}; | ||
|
||
assign(target, { | ||
baz: 'boz' | ||
}); | ||
|
||
expect(target).toEqual({foo: 'bar', baz: 'boz'}) | ||
}) | ||
}) |