sindresorhus / ky

🌳 Tiny & elegant JavaScript HTTP client based on the Fetch API
MIT License
13.46k stars 361 forks source link

Add support for passing a function to ky.extend() #611

Closed mfulton26 closed 1 month ago

mfulton26 commented 1 month ago

callback function receives parent's default options to allow extended instance to refer to modify parent options

Closes #586

sholladay commented 1 month ago

Thanks for working on this, looking good.

Can you add a few more permutations to the tests? In particular, I want to make sure we cover:

  1. What happens when the extend function ignores the parent options, i.e. is the prefixUrl still set if extend doesn't set it?
  2. The behavior of setting nested options, such as hooks. Does setting a hook add to or replace the parent's hooks?
mfulton26 commented 1 month ago

@sholladay I've added some more test cases. I believe I've captured what you were targeting.

sholladay commented 1 month ago

Such a simple change, yet I think this will be a popular feature and cleanly solve a lot of use cases. Thanks again!

mfulton26 commented 1 month ago

Such a simple change, yet I think this will be a popular feature and cleanly solve a lot of use cases. Thanks again!

I agree. Thank you for helping me add this change. I look forward to using it in my own projects!

joshgummersall commented 1 month ago

Will this be published soon? Doesn't look like this landed in 1.4.0.

sindresorhus commented 1 month ago

https://github.com/sindresorhus/ky/releases/tag/v1.5.0

joshgummersall commented 1 month ago

Ah wow, thanks so much for getting to this to fast! Appreciate it 😄