main
Last change
on this file was 79a0317, checked in by stefan toskovski <stefantoska84@…>, 2 weeks ago |
F4 Finalna Verzija
|
-
Property mode
set to
100644
|
File size:
643 bytes
|
Line | |
---|
1 | export function call<T>(v: T | ((...args: any[]) => T), ...args: any[]): T {
|
---|
2 | if (typeof v === 'function') {
|
---|
3 | // @ts-ignore
|
---|
4 | return v(...args)
|
---|
5 | } else {
|
---|
6 | return v
|
---|
7 | }
|
---|
8 | }
|
---|
9 |
|
---|
10 | export function noop() {}
|
---|
11 |
|
---|
12 | export function chain(...fns: Function[]): Function {
|
---|
13 | if (fns.length === 0) return noop
|
---|
14 | if (fns.length === 1) return fns[0]
|
---|
15 |
|
---|
16 | return function (this: any) {
|
---|
17 | let result
|
---|
18 | for (const fn of fns) {
|
---|
19 | result = fn.apply(this, arguments) || result
|
---|
20 | }
|
---|
21 | return result
|
---|
22 | }
|
---|
23 | }
|
---|
24 |
|
---|
25 | export function assignDefault<T extends Object>(value: Partial<T> | undefined, fallback: T): T {
|
---|
26 | return Object.assign({}, fallback, value || {})
|
---|
27 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.