github
8 of 9 branches covered (88.89%)
Branch coverage included in aggregate %.
55 of 56 new or added lines in 2 files covered. (98.21%)
55 of 56 relevant lines covered (98.21%)
4.21 hits per line
|
type Options = { |
1✔ |
|
base?: string
|
1✔ |
|
fetch?: Function |
1✔ |
|
} |
1✔ |
|
|
1✔ |
|
const createEnhancedFunction = ({
|
|
|
base = '',
|
5✔ |
|
fetch = () => {}, |
5✔ |
|
...other |
5✔ |
|
}: Options = {}) => new Proxy((o: any) => createEnhancedFunction(o), {
|
|
|
get(obj: any, prop: any) { |
|
|
return obj[prop]
|
4✔ |
|
?? ( |
4✔ |
|
(...args: any) => { |
|
|
// extract base
|
4✔ |
|
base = base + ( |
4✔ |
|
typeof args[0] == 'string' |
|
NEW
|
? args.shift() |
× |
|
: ''
|
4✔ |
|
) |
4✔ |
|
|
4✔ |
|
const payload = args.shift(),
|
4✔ |
|
options = args.shift() |
4✔ |
|
|
4✔ |
|
return fetch(base, {
|
4✔ |
|
...other, |
4✔ |
|
...options, |
4✔ |
|
}) |
4✔ |
|
} |
4✔ |
|
) |
4✔ |
|
} |
4✔ |
|
}) |
5✔ |
|
|
1✔ |
|
export const fetcher = createEnhancedFunction() |
1✔ |