imgix / js-core

A JavaScript client library for generating image URLs with imgix
https://www.imgix.com
BSD 2-Clause "Simplified" License
122 stars 20 forks source link

(PoC) feat: add _buildURL static method #287

Closed luqven closed 3 years ago

luqven commented 3 years ago

This PR is a WIP This PR is a stacked PR

PR Title Merges Into diff
1 _buildURL 👈🏼 main review this
2 _buildSrcSet #287 review this
3 fix extractUrl #288 review this

This PR creates the _buildURL static method on the ImgixClient. This methods allows us to use a 1-step, or full, URL to generate imgix formatted urls.

Future work

Proxy URL tests are needed here. They're not being handled as of yet.

commit-lint[bot] commented 3 years ago

Features

Tests

Chore

Contributors

luqven

Commit-Lint commands
You can trigger Commit-Lint actions by commenting on this PR: - `@Commit-Lint merge patch` will merge dependabot PR on "patch" versions (X.X.Y - Y change) - `@Commit-Lint merge minor` will merge dependabot PR on "minor" versions (X.Y.Y - Y change) - `@Commit-Lint merge major` will merge dependabot PR on "major" versions (Y.Y.Y - Y change) - `@Commit-Lint merge disable` will desactivate merge dependabot PR - `@Commit-Lint review` will approve dependabot PR - `@Commit-Lint stop review` will stop approve dependabot PR
luqven commented 3 years ago

Initially, I felt that users should stick to using the instance methods if they want to build proxy URLs

I second this ☝🏼 . sanitize option can and IMO should be removed.

As for proxies, for one-step URLs we can treat proxies as an opts parameter. Something like

const url = "https://foo.bar.net"
const opts = { proxy: "https://bar.baz.net/img.jpg" }
const params = {fit: "crop"}
_buildOneStepURL({ url, params, opts }) {

// somewhere inside _buildOneStepURL
if (options.proxy) {
  path = client._sanitizePath(options.proxy);
}
sherwinski commented 3 years ago

@luqven Yeah that sounds like a plausible solution. Since this will probably take a few beta releases to get right, I'd say feel free to experiment with the interface until all the wrinkles get ironed out 👍

luqven commented 3 years ago

Updated this PR to rename the static method to _buildURL, rename opts to options, and rename the test suite to match.

luqven commented 3 years ago

Closing in favor of #294