imgix-url-builder
Advanced tools
Comparing version 0.0.3 to 0.0.4
@@ -40,11 +40,129 @@ const camelCaseToParamCase = (input) => { | ||
class Client { | ||
/** | ||
* Creates a new `Client` instance for an Imgix domain. | ||
* | ||
* @param options - Options to instantiate a new client. | ||
* | ||
* @returns A `Client` instance for the given Imgix domain. | ||
*/ | ||
constructor(options) { | ||
this.baseURL = options.baseURL; | ||
} | ||
/** | ||
* Builds a URL to an Imgix image with Imgix URL API parameters for the | ||
* client's base URL. | ||
* | ||
* @example | ||
* | ||
* ```ts | ||
* const client = new Client({ baseURL: "https://example.imgix.net" }); | ||
* const url = client.buildURLForPath("/image.png", { width: 400 }); | ||
* // => https://example.imgix.net/image.png?width=400 | ||
* ``` | ||
* | ||
* @example | ||
* | ||
* ```ts | ||
* const client = new Client({ | ||
* baseURL: "https://example.imgix.net/folder", | ||
* }); | ||
* const url = client.buildURLForPath("./image.png", { width: 400 }); | ||
* // => https://example.imgix.net/folder/image.png?width=400 | ||
* ``` | ||
* | ||
* @param path - Path to the image relative to the client's base URL. | ||
* @param params - An object of Imgix URL API parameters. | ||
* | ||
* @returns The full absolute URL to the image with the given Imgix URL API | ||
* parameters applied. | ||
*/ | ||
buildURLForPath(path, params = {}) { | ||
return buildURL(`${new URL(path, this.baseURL)}`, params); | ||
} | ||
/** | ||
* Builds an `<img>` `srcset` attribute value for a given set of widths for | ||
* the client's base URL. It can also optinally apply Imgix URL API parameters | ||
* to the URLs. | ||
* | ||
* The `width` URL parameter will be applied for each `srcset` entry. If a | ||
* `width` or `w` parameter is provided to the `params` parameter, it will be | ||
* ignored. | ||
* | ||
* @example | ||
* | ||
* ```ts | ||
* const client = new Client({ baseURL: "https://example.imgix.net" }); | ||
* const srcset = client.buildWidthSrcSetForPath("/image.png", { | ||
* widths: [400, 800, 1600], | ||
* }); | ||
* // => https://example.imgix.net/image.png?width=400 400w, | ||
* // https://example.imgix.net/image.png?width=800 800w, | ||
* // https://example.imgix.net/image.png?width=1600 1600w | ||
* ``` | ||
* | ||
* @example | ||
* | ||
* ```ts | ||
* const client = new Client({ | ||
* baseURL: "https://example.imgix.net", | ||
* }); | ||
* const srcset = client.buildWidthSrcSetForPath("/image.png", { | ||
* widths: [400, 800, 1600], | ||
* sat: -100, | ||
* }); | ||
* // => https://example.imgix.net/image.png?width=400&sat=-100 400w, | ||
* // https://example.imgix.net/image.png?width=800&sat=-100 800w, | ||
* // https://example.imgix.net/image.png?width=1600&sat=-100 1600w | ||
* ``` | ||
* | ||
* @param path - Path to the image relative to the client's base URL. | ||
* @param params - An object of Imgix URL API parameters. The `widths` | ||
* parameter defines the resulting `srcset` widths. | ||
* | ||
* @returns A `srcset` attribute value for `url` with the given Imgix URL API | ||
* parameters applied. | ||
*/ | ||
buildWidthSrcSetForPath(path, params) { | ||
return buildWidthSrcSet(`${new URL(path, this.baseURL)}`, params); | ||
} | ||
/** | ||
* Builds an `<img>` `srcset` attribute value for a given set of pixel | ||
* densities for the client's base URL. It can also optinally apply Imgix URL | ||
* API parameters to the URLs. | ||
* | ||
* The `dpr` URL parameter will be applied for each `srcset` entry. If a `dpr` | ||
* parameter is provided to the `params` parameter, it will be ignored. | ||
* | ||
* @example | ||
* | ||
* ```ts | ||
* const client = new Client({ baseURL: "https://example.imgix.net" }); | ||
* const srcset = client.buildPixelDensitySrcSetForPath("/image.png", { | ||
* pixelDensities: [1, 2, 3], | ||
* }); | ||
* // => https://example.imgix.net/image.png?dpr=1 1x, | ||
* // https://example.imgix.net/image.png?dpr=2 2x, | ||
* // https://example.imgix.net/image.png?dpr=3 3x | ||
* ``` | ||
* | ||
* @example | ||
* | ||
* ```ts | ||
* const client = new Client({ baseURL: "https://example.imgix.net" }); | ||
* const srcset = client.buildPixelDensitySrcSetForPath("/image.png", { | ||
* pixelDensities: [1, 2, 3], | ||
* sat: -100, | ||
* }); | ||
* // => https://example.imgix.net/image.png?dpr=1&sat=-100 1x, | ||
* // https://example.imgix.net/image.png?dpr=2&sat=-100 2x, | ||
* // https://example.imgix.net/image.png?dpr=3&sat=-100 3x | ||
* ``` | ||
* | ||
* @param path - Path to the image relative to the client's base URL. | ||
* @param params - An object of Imgix URL API parameters. The `pixelDensities` | ||
* parameter defines the resulting `srcset` widths. | ||
* | ||
* @returns A `srcset` attribute value for `url` with the given Imgix URL API | ||
* parameters applied. | ||
*/ | ||
buildPixelDensitySrcSetForPath(path, params) { | ||
@@ -51,0 +169,0 @@ return buildPixelDensitySrcSet(`${new URL(path, this.baseURL)}`, params); |
{ | ||
"name": "imgix-url-builder", | ||
"version": "0.0.3", | ||
"version": "0.0.4", | ||
"description": "JavaScript/TypeScript Imgix URL builders for browsers and Node.js", | ||
@@ -52,22 +52,22 @@ "keywords": [ | ||
"devDependencies": { | ||
"@size-limit/preset-small-lib": "^7.0.5", | ||
"@types/prettier": "^2.4.3", | ||
"@typescript-eslint/eslint-plugin": "^5.8.1", | ||
"@typescript-eslint/parser": "^5.8.1", | ||
"ava": "^4.0.1", | ||
"eslint": "^8.6.0", | ||
"eslint-config-prettier": "^8.3.0", | ||
"eslint-plugin-prettier": "^4.0.0", | ||
"eslint-plugin-tsdoc": "^0.2.14", | ||
"imgix-url-params": "^11.12.0", | ||
"@size-limit/preset-small-lib": "^8.2.4", | ||
"@types/prettier": "^2.7.2", | ||
"@typescript-eslint/eslint-plugin": "^5.59.7", | ||
"@typescript-eslint/parser": "^5.59.7", | ||
"ava": "^5.3.0", | ||
"eslint": "^8.41.0", | ||
"eslint-config-prettier": "^8.8.0", | ||
"eslint-plugin-prettier": "^4.2.1", | ||
"eslint-plugin-tsdoc": "^0.2.17", | ||
"imgix-url-params": "^11.15.0", | ||
"nyc": "^15.1.0", | ||
"prettier": "^2.5.1", | ||
"prettier-plugin-jsdoc": "^0.3.30", | ||
"prettier": "^2.8.8", | ||
"prettier-plugin-jsdoc": "^0.4.2", | ||
"siroc": "^0.16.0", | ||
"size-limit": "^7.0.5", | ||
"standard-version": "^9.3.2", | ||
"size-limit": "^8.2.4", | ||
"standard-version": "^9.5.0", | ||
"ts-eager": "^2.0.2", | ||
"ts-morph": "^13.0.2", | ||
"ts-node": "^10.4.0", | ||
"typescript": "^4.5.4" | ||
"ts-morph": "^18.0.0", | ||
"ts-node": "^10.9.1", | ||
"typescript": "^5.0.4" | ||
}, | ||
@@ -74,0 +74,0 @@ "engines": { |
@@ -29,3 +29,4 @@ import type { ImgixURLParams } from "./types.generated"; | ||
* URL parameters already applied to the image will be retained. To remove | ||
* existing parameters, set the parameter to `undefined` in the `params` argument. | ||
* existing parameters, set the parameter to `undefined` in the `params` | ||
* argument. | ||
* | ||
@@ -32,0 +33,0 @@ * @example |
@@ -25,3 +25,4 @@ import type { ImgixURLParams } from "./types.generated"; | ||
* The `width` URL parameter will be applied for each `srcset` entry. If a | ||
* `width` or `w` parameter is provided to the `params` parameter, it will be ignored. | ||
* `width` or `w` parameter is provided to the `params` parameter, it will be | ||
* ignored. | ||
* | ||
@@ -28,0 +29,0 @@ * @example |
@@ -78,3 +78,4 @@ import type { BuildPixelDensitySrcSetParams } from "./buildPixelDensitySrcSet"; | ||
* The `width` URL parameter will be applied for each `srcset` entry. If a | ||
* `width` or `w` parameter is provided to the `params` parameter, it will be ignored. | ||
* `width` or `w` parameter is provided to the `params` parameter, it will be | ||
* ignored. | ||
* | ||
@@ -81,0 +82,0 @@ * @example |
@@ -8,3 +8,4 @@ import type { BuildPixelDensitySrcSetParams } from "../buildPixelDensitySrcSet"; | ||
* The URLs are signed by appending a signature to their URL parameters. This | ||
* locks the URLs and their parameters to the signature to prevent URL tampering. | ||
* locks the URLs and their parameters to the signature to prevent URL | ||
* tampering. | ||
* | ||
@@ -48,3 +49,4 @@ * The `dpr` URL parameter will be applied for each `srcset` entry. If a `dpr` | ||
* @param url - Full absolute URL to the Imgix image. | ||
* @param secureURLToken - The secret secure URL token for the image's Imgix source. | ||
* @param secureURLToken - The secret secure URL token for the image's Imgix | ||
* source. | ||
* @param params - An object of Imgix URL API parameters. The `pixelDensities` | ||
@@ -51,0 +53,0 @@ * parameter defines the resulting `srcset` widths. |
@@ -13,3 +13,4 @@ import type { ImgixURLParams } from "../types.generated"; | ||
* URL parameters already applied to the image will be retained. To remove | ||
* existing parameters, set the parameter to `undefined` in the `params` argument. | ||
* existing parameters, set the parameter to `undefined` in the `params` | ||
* argument. | ||
* | ||
@@ -43,3 +44,4 @@ * **Important**: This function should only be used in a trusted environment and | ||
* @param url - Full absolute URL to the Imgix image. | ||
* @param secureURLToken - The secret secure URL token for the image's Imgix source. | ||
* @param secureURLToken - The secret secure URL token for the image's Imgix | ||
* source. | ||
* @param params - An object of Imgix URL API parameters. | ||
@@ -46,0 +48,0 @@ * |
@@ -11,3 +11,4 @@ import type { BuildWidthSrcSetParams } from "../buildWidthSrcSet"; | ||
* The `width` URL parameter will be applied for each `srcset` entry. If a | ||
* `width` or `w` parameter is provided to the `params` parameter, it will be ignored. | ||
* `width` or `w` parameter is provided to the `params` parameter, it will be | ||
* ignored. | ||
* | ||
@@ -48,3 +49,4 @@ * **Important**: This function should only be used in a trusted environment and | ||
* @param url - Full absolute URL to the Imgix image. | ||
* @param secureURLToken - The secret secure URL token for the image's Imgix source. | ||
* @param secureURLToken - The secret secure URL token for the image's Imgix | ||
* source. | ||
* @param params - An object of Imgix URL API parameters. The `widths` parameter | ||
@@ -51,0 +53,0 @@ * defines the resulting `srcset` widths. |
@@ -176,6 +176,8 @@ import type { BuildPixelDensitySrcSetParams } from "../buildPixelDensitySrcSet"; | ||
* | ||
* The given URL must be a full absolute URL containing the protocol and domain. | ||
* The given URL must be a full absolute URL containing the protocol and | ||
* domain. | ||
* | ||
* URL parameters already applied to the image will be retained. To remove | ||
* existing parameters, set the parameter to `undefined` in the `params` argument. | ||
* existing parameters, set the parameter to `undefined` in the `params` | ||
* argument. | ||
* | ||
@@ -216,3 +218,4 @@ * @example | ||
* Signs an Imgix image URL by appending a signature to the URL parameters. | ||
* This locks the URL and its parameters to the signature to prevent URL tampering. | ||
* This locks the URL and its parameters to the signature to prevent URL | ||
* tampering. | ||
* | ||
@@ -245,3 +248,4 @@ * @example | ||
* The `width` URL parameter will be applied for each `srcset` entry. If a | ||
* `width` or `w` parameter is provided to the `params` parameter, it will be ignored. | ||
* `width` or `w` parameter is provided to the `params` parameter, it will be | ||
* ignored. | ||
* | ||
@@ -292,3 +296,4 @@ * @example | ||
* The `width` URL parameter will be applied for each `srcset` entry. If a | ||
* `width` or `w` parameter is provided to the `params` parameter, it will be ignored. | ||
* `width` or `w` parameter is provided to the `params` parameter, it will be | ||
* ignored. | ||
* | ||
@@ -351,3 +356,4 @@ * Note: The returned URLs are not signed. See `buildSignedWidthSrcSet` if | ||
* The `width` URL parameter will be applied for each `srcset` entry. If a | ||
* `width` or `w` parameter is provided to the `params` parameter, it will be ignored. | ||
* `width` or `w` parameter is provided to the `params` parameter, it will be | ||
* ignored. | ||
* | ||
@@ -406,3 +412,4 @@ * @example | ||
* URLs. The URLs are signed by appending a signature to their URL parameters. | ||
* This locks the URLs and their parameters to the signature to prevent URL tampering. | ||
* This locks the URLs and their parameters to the signature to prevent URL | ||
* tampering. | ||
* | ||
@@ -409,0 +416,0 @@ * The `dpr` URL parameter will be applied for each `srcset` entry. If a `dpr` |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
476798
12055