imgix / js-core

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

feat: full URL support for buildUrl and buildSrcSet #294

Closed luqven closed 3 years ago

luqven commented 3 years ago

This PR adds full URL support to the client via static methods

Unit tests for these methods are included in the PR.

The PR also introduces a helper function, extractUrl that uses the ufo module to parse and isolate different URL components of a full URL. Unit tests for the helper function are also included in the PR.

The PR also introduces ufo package as a dependency.

Examples

const client = ImgixClient
const params = { w: 100 }
const opts = { useHttps: true }
const src = "sdk-test.imgix.net/amsterdam.jpg?h=100"

const url = client._buildURL(src, params, opts)
const srcSet = client._buildSrcSet(src, params, opts)

console.log(url) // => "https://sdk-test.imgix.net/amsterdam.jpg?h=100&w=100"
console.log(srcSet) /** =>
* https://sdk-test.imgix.net/amsterdam.jpg?w=800&q=100&dpr=1&s=f556bd48d069e6435d8f59940fbd2830 1x,
* https://sdk-test.imgix.net/amsterdam.jpg?w=100&h=100&dpr=2 2x,
* https://sdk-test.imgix.net/amsterdam.jpg?w=100&h=100&&dpr=3 3x,
* https://sdk-test.imgix.net/amsterdam.jpg?w=100&h=100&dpr=4 4x,
* https://sdk-test.imgix.net/amsterdam.jpg?w=100&h=100&dpr=5 5x"
*/

Future Work

Comments

This PR is not considered a breaking change since none of the existing public methods are changed.

This PR includes work and feedback from:

Please note that support for full URLs is considered experimental and will not be officially supported.

commit-lint[bot] commented 3 years ago

Features

Build System

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

Forced pushed to try out semantic release on @next.

luqven commented 3 years ago

Ran into an issue with colliding deps. Had to rebase and force push again.

imgix-git-robot commented 3 years ago

:tada: This PR is included in version 3.3.0-rc.1 :tada:

The release is available on:

Your semantic-release bot :package::rocket:

imgix-git-robot commented 3 years ago

:tada: This PR is included in version 3.3.0 :tada:

The release is available on:

Your semantic-release bot :package::rocket: