unitedwardrobe / imgproxy-node

A Node client library to generate urls for imgproxy services.
MIT License
36 stars 8 forks source link

feat(builder): return `this` from `setOption` and `clearOption` #22

Closed jgradim closed 1 year ago

jgradim commented 1 year ago

Currently, setOption can't be used as an alternative for missing options in the Builder class due to not returning any value. By returning this, we can use setOption in the same way as format, resize, etc, and keep the API consistent and predictable.

Before

const builder = imgproxy.builder();
builder.setOption('expires', (Date.now() / 1000 + 60).toFixed(0)); // 1 minute expiry

return builder
  .format('jpg')
  .resize('fit', 1920, 1080, false)
  .generateUrl('...');

After

return imgproxy
  .builder()
  .format('jpg')
  .resize('fit', 1920, 1080, false)
  .setOption('expires', (Date.now() / 1000 + 60).toFixed(0)), // 1 minute expiry
  .generateUrl('...');
remq commented 1 year ago

This repo isn't actively maintained anymore, but I just updated it to modernise it a bit (https://github.com/unitedwardrobe/imgproxy-node/commit/d3bbd168b763dfa7de29784c848785723a8cdbc6). I'm not a maintainer of the NPM repository, but I've asked for it to be deployed. This would include this change as well.

jgradim commented 1 year ago

@remq looks great, thank you!