imgix-url-builder 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +6 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +6 -3
- package/dist/index.mjs.map +1 -1
- package/dist/node/index.cjs +6 -2
- package/dist/node/index.cjs.map +1 -1
- package/dist/node/index.mjs +6 -2
- package/dist/node/index.mjs.map +1 -1
- package/package.json +2 -5
- package/src/buildURL.ts +21 -3
package/dist/index.cjs
CHANGED
|
@@ -2,12 +2,15 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
const
|
|
6
|
-
|
|
5
|
+
const camelCaseToParamCase = (input) => {
|
|
6
|
+
return input.replace(/[A-Z]/g, (match) => {
|
|
7
|
+
return `-${match.toLowerCase()}`;
|
|
8
|
+
});
|
|
9
|
+
};
|
|
7
10
|
const buildURL = (url, params) => {
|
|
8
11
|
const instance = new URL(url);
|
|
9
12
|
for (const camelCasedParamKey in params) {
|
|
10
|
-
const paramKey =
|
|
13
|
+
const paramKey = camelCaseToParamCase(camelCasedParamKey);
|
|
11
14
|
const paramValue = params[camelCasedParamKey];
|
|
12
15
|
if (paramValue === void 0) {
|
|
13
16
|
instance.searchParams.delete(paramKey);
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sources":["../src/buildURL.ts","../src/buildPixelDensitySrcSet.ts","../src/buildWidthSrcSet.ts","../src/Client.ts"],"sourcesContent":["import { paramCase } from \"param-case\";\n\nimport type { ImgixURLParams } from \"./types.generated\";\n\n/**\n * Builds a URL to an Imgix image with Imgix URL API parameters.\n *\n * The given URL must be a full absolute URL containing the protocol and domain.\n *\n * URL parameters already applied to the image will be retained. To remove\n * existing parameters, set the parameter to `undefined` in the `params` argument.\n *\n * @example\n *\n * ```ts\n * const url = buildURL(\"https://example.imgix.net/image.png\", {\n * \twidth: 400,\n * });\n * // => https://example.imgix.net/image.png?width=400\n * ```\n *\n * @example\n *\n * ```ts\n * const url = buildURL(\"https://example.imgix.net/image.png?width=400\", {\n * \theight: 300,\n * });\n * // => https://example.imgix.net/image.png?width=400&height=300\n * ```\n *\n * @param url - Full absolute URL to the Imgix image.\n * @param params - An object of Imgix URL API parameters.\n *\n * @returns `url` with the given Imgix URL API parameters applied.\n *\n * @see Imgix URL API reference: https://docs.imgix.com/apis/rendering\n */\nexport const buildURL = (url: string, params: ImgixURLParams): string => {\n\tconst instance = new URL(url);\n\n\tfor (const camelCasedParamKey in params) {\n\t\tconst paramKey = paramCase(camelCasedParamKey);\n\t\tconst paramValue = params[camelCasedParamKey as keyof typeof params];\n\n\t\tif (paramValue === undefined) {\n\t\t\tinstance.searchParams.delete(paramKey);\n\t\t} else if (Array.isArray(paramValue)) {\n\t\t\tinstance.searchParams.set(paramKey, paramValue.join(\",\"));\n\t\t} else {\n\t\t\tinstance.searchParams.set(paramKey, `${paramValue}`);\n\t\t}\n\t}\n\n\t// Ensure the `s` parameter is the last parameter, if it exists.\n\t// @see https://github.com/imgix/imgix-blueprint#securing-urls\n\tconst s = instance.searchParams.get(\"s\");\n\tif (s) {\n\t\tinstance.searchParams.delete(\"s\");\n\t\tinstance.searchParams.append(\"s\", s);\n\t}\n\n\treturn instance.toString();\n};\n","import type { ImgixURLParams } from \"./types.generated\";\nimport { buildURL } from \"./buildURL\";\n\n/**\n * Parameters for `buildPixelDensitySrcSet`.\n */\nexport type BuildPixelDensitySrcSetParams = Omit<ImgixURLParams, \"dpr\"> & {\n\t/**\n\t * The pixel densities to include in the resulting `srcset` value.\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * [1, 2, 3];\n\t * ```\n\t */\n\tpixelDensities: number[];\n};\n\n/**\n * Builds an `<img>` `srcset` attribute value for a given set of pixel\n * densities. It can also optinally apply Imgix URL API parameters to the URLs.\n *\n * The `dpr` URL parameter will be applied for each `srcset` entry. If a `dpr`\n * parameter is provided to the `params` parameter, it will be ignored.\n *\n * @example\n *\n * ```ts\n * const srcset = buildPixelDensitySrcSet(\n * \t\"https://example.imgix.net/image.png\",\n * \t{ pixelDensities: [1, 2, 3] },\n * );\n * // => https://example.imgix.net/image.png?dpr=1 1x,\n * // https://example.imgix.net/image.png?dpr=2 2x,\n * // https://example.imgix.net/image.png?dpr=3 3x\n * ```\n *\n * @example\n *\n * ```ts\n * const srcset = buildPixelDensitySrcSet(\n * \t\"https://example.imgix.net/image.png\",\n * \t{\n * \t\tpixelDensities: [1, 2, 3],\n * \t\tsat: -100,\n * \t},\n * );\n * // => https://example.imgix.net/image.png?dpr=1&sat=-100 1x,\n * // https://example.imgix.net/image.png?dpr=2&sat=-100 2x,\n * // https://example.imgix.net/image.png?dpr=3&sat=-100 3x\n * ```\n *\n * @param url - Full absolute URL to the Imgix image.\n * @param params - An object of Imgix URL API parameters. The `pixelDensities`\n * parameter defines the resulting `srcset` widths.\n *\n * @returns A `srcset` attribute value for `url` with the given Imgix URL API\n * parameters applied.\n */\nexport const buildPixelDensitySrcSet = (\n\turl: string,\n\t{ pixelDensities, ...params }: BuildPixelDensitySrcSetParams,\n): string => {\n\treturn pixelDensities\n\t\t.map((dpr) => {\n\t\t\treturn `${buildURL(url, { ...params, dpr })} ${dpr}x`;\n\t\t})\n\t\t.join(\", \");\n};\n","import type { ImgixURLParams } from \"./types.generated\";\nimport { buildURL } from \"./buildURL\";\n\n/**\n * Parameters for `buildWidthSrcSet`.\n */\nexport type BuildWidthSrcSetParams = Omit<ImgixURLParams, \"width\" | \"w\"> & {\n\t/**\n\t * The pixel widths to include in the resulting `srcset` value.\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * [400, 800, 1600];\n\t * ```\n\t */\n\twidths: number[];\n};\n\n/**\n * Builds an `<img>` `srcset` attribute value for a given set of widths. It can\n * also optinally apply Imgix URL API parameters to the URLs.\n *\n * The `width` URL parameter will be applied for each `srcset` entry. If a\n * `width` or `w` parameter is provided to the `params` parameter, it will be ignored.\n *\n * @example\n *\n * ```ts\n * const srcset = buildWidthSrcSet(\"https://example.imgix.net/image.png\", {\n * \twidths: [400, 800, 1600],\n * });\n * // => https://example.imgix.net/image.png?width=400 400w,\n * // https://example.imgix.net/image.png?width=800 800w,\n * // https://example.imgix.net/image.png?width=1600 1600w\n * ```\n *\n * @example\n *\n * ```ts\n * const srcset = buildWidthSrcSet(\"https://example.imgix.net/image.png\", {\n * \twidths: [400, 800, 1600],\n * \tsat: -100,\n * });\n * // => https://example.imgix.net/image.png?width=400&sat=-100 400w,\n * // https://example.imgix.net/image.png?width=800&sat=-100 800w,\n * // https://example.imgix.net/image.png?width=1600&sat=-100 1600w\n * ```\n *\n * @param url - Full absolute URL to the Imgix image.\n * @param params - An object of Imgix URL API parameters. The `widths` parameter\n * defines the resulting `srcset` widths.\n *\n * @returns A `srcset` attribute value for `url` with the given Imgix URL API\n * parameters applied.\n */\nexport const buildWidthSrcSet = (\n\turl: string,\n\t{ widths, ...params }: BuildWidthSrcSetParams,\n): string => {\n\treturn widths\n\t\t.map((width) => {\n\t\t\treturn `${buildURL(url, { ...params, w: undefined, width })} ${width}w`;\n\t\t})\n\t\t.join(\", \");\n};\n","import type { BuildPixelDensitySrcSetParams } from \"./buildPixelDensitySrcSet\";\nimport type { BuildWidthSrcSetParams } from \"./buildWidthSrcSet\";\nimport type { ImgixURLParams } from \"./types.generated\";\nimport { buildPixelDensitySrcSet } from \"./buildPixelDensitySrcSet\";\nimport { buildURL } from \"./buildURL\";\nimport { buildWidthSrcSet } from \"./buildWidthSrcSet\";\n\n/**\n * Options to instantiate a new client.\n */\nexport type ClientOptions = {\n\t/**\n\t * The base URL used to construct image URLs from a path. The base URL must\n\t * include the protocol, domain, and optionally a path.\n\t *\n\t * @example `https://example.imgix.net`\n\t *\n\t * @example `https://example.imgix.net/folder`\n\t */\n\tbaseURL: string;\n};\n\n/**\n * An Imgix Rendering API client. A client is paired to a single Imgix domain.\n */\nexport class Client {\n\tbaseURL: string;\n\n\t/**\n\t * Creates a new `Client` instance for an Imgix domain.\n\t *\n\t * @param options - Options to instantiate a new client.\n\t *\n\t * @returns A `Client` instance for the given Imgix domain.\n\t */\n\tconstructor(options: ClientOptions) {\n\t\tthis.baseURL = options.baseURL;\n\t}\n\n\t/**\n\t * Builds a URL to an Imgix image with Imgix URL API parameters for the\n\t * client's base URL.\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * const client = new Client({ baseURL: \"https://example.imgix.net\" });\n\t * const url = client.buildURLForPath(\"/image.png\", { width: 400 });\n\t * // => https://example.imgix.net/image.png?width=400\n\t * ```\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * const client = new Client({\n\t * \tbaseURL: \"https://example.imgix.net/folder\",\n\t * });\n\t * const url = client.buildURLForPath(\"./image.png\", { width: 400 });\n\t * // => https://example.imgix.net/folder/image.png?width=400\n\t * ```\n\t *\n\t * @param path - Path to the image relative to the client's base URL.\n\t * @param params - An object of Imgix URL API parameters.\n\t *\n\t * @returns The full absolute URL to the image with the given Imgix URL API\n\t * parameters applied.\n\t */\n\tbuildURLForPath(path: string, params: ImgixURLParams = {}) {\n\t\treturn buildURL(`${new URL(path, this.baseURL)}`, params);\n\t}\n\n\t/**\n\t * Builds an `<img>` `srcset` attribute value for a given set of widths for\n\t * the client's base URL. It can also optinally apply Imgix URL API parameters\n\t * to the URLs.\n\t *\n\t * The `width` URL parameter will be applied for each `srcset` entry. If a\n\t * `width` or `w` parameter is provided to the `params` parameter, it will be ignored.\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * const client = new Client({ baseURL: \"https://example.imgix.net\" });\n\t * const srcset = client.buildWidthSrcSetForPath(\"/image.png\", {\n\t * \twidths: [400, 800, 1600],\n\t * });\n\t * // => https://example.imgix.net/image.png?width=400 400w,\n\t * // https://example.imgix.net/image.png?width=800 800w,\n\t * // https://example.imgix.net/image.png?width=1600 1600w\n\t * ```\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * const client = new Client({\n\t * \tbaseURL: \"https://example.imgix.net\",\n\t * });\n\t * const srcset = client.buildWidthSrcSetForPath(\"/image.png\", {\n\t * \twidths: [400, 800, 1600],\n\t * \tsat: -100,\n\t * });\n\t * // => https://example.imgix.net/image.png?width=400&sat=-100 400w,\n\t * // https://example.imgix.net/image.png?width=800&sat=-100 800w,\n\t * // https://example.imgix.net/image.png?width=1600&sat=-100 1600w\n\t * ```\n\t *\n\t * @param path - Path to the image relative to the client's base URL.\n\t * @param params - An object of Imgix URL API parameters. The `widths`\n\t * parameter defines the resulting `srcset` widths.\n\t *\n\t * @returns A `srcset` attribute value for `url` with the given Imgix URL API\n\t * parameters applied.\n\t */\n\tbuildWidthSrcSetForPath(path: string, params: BuildWidthSrcSetParams) {\n\t\treturn buildWidthSrcSet(`${new URL(path, this.baseURL)}`, params);\n\t}\n\n\t/**\n\t * Builds an `<img>` `srcset` attribute value for a given set of pixel\n\t * densities for the client's base URL. It can also optinally apply Imgix URL\n\t * API parameters to the URLs.\n\t *\n\t * The `dpr` URL parameter will be applied for each `srcset` entry. If a `dpr`\n\t * parameter is provided to the `params` parameter, it will be ignored.\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * const client = new Client({ baseURL: \"https://example.imgix.net\" });\n\t * const srcset = client.buildPixelDensitySrcSetForPath(\"/image.png\", {\n\t * \tpixelDensities: [1, 2, 3],\n\t * });\n\t * // => https://example.imgix.net/image.png?dpr=1 1x,\n\t * // https://example.imgix.net/image.png?dpr=2 2x,\n\t * // https://example.imgix.net/image.png?dpr=3 3x\n\t * ```\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * const client = new Client({ baseURL: \"https://example.imgix.net\" });\n\t * const srcset = client.buildPixelDensitySrcSetForPath(\"/image.png\", {\n\t * \tpixelDensities: [1, 2, 3],\n\t * \tsat: -100,\n\t * });\n\t * // => https://example.imgix.net/image.png?dpr=1&sat=-100 1x,\n\t * // https://example.imgix.net/image.png?dpr=2&sat=-100 2x,\n\t * // https://example.imgix.net/image.png?dpr=3&sat=-100 3x\n\t * ```\n\t *\n\t * @param path - Path to the image relative to the client's base URL.\n\t * @param params - An object of Imgix URL API parameters. The `pixelDensities`\n\t * parameter defines the resulting `srcset` widths.\n\t *\n\t * @returns A `srcset` attribute value for `url` with the given Imgix URL API\n\t * parameters applied.\n\t */\n\tbuildPixelDensitySrcSetForPath(\n\t\tpath: string,\n\t\tparams: BuildPixelDensitySrcSetParams,\n\t) {\n\t\treturn buildPixelDensitySrcSet(`${new URL(path, this.baseURL)}`, params);\n\t}\n}\n"],"names":["paramCase"],"mappings":";;;;;;MAqCa,WAAW,CAAC,KAAa,WAAmC;AACxE,QAAM,WAAW,IAAI,IAAI;AAEzB,aAAW,sBAAsB,QAAQ;AACxC,UAAM,WAAWA,oBAAU;AAC3B,UAAM,aAAa,OAAO;AAE1B,QAAI,eAAe,QAAW;AAC7B,eAAS,aAAa,OAAO;AAAA,eACnB,MAAM,QAAQ,aAAa;AACrC,eAAS,aAAa,IAAI,UAAU,WAAW,KAAK;AAAA,WAC9C;AACN,eAAS,aAAa,IAAI,UAAU,GAAG;AAAA;AAAA;AAMzC,QAAM,IAAI,SAAS,aAAa,IAAI;AACpC,MAAI,GAAG;AACN,aAAS,aAAa,OAAO;AAC7B,aAAS,aAAa,OAAO,KAAK;AAAA;AAGnC,SAAO,SAAS;AAAA;;MCDJ,0BAA0B,CACtC,KACA,EAAE,mBAAmB,aACT;AACZ,SAAO,eACL,IAAI,CAAC,QAAQ;AACb,WAAO,GAAG,SAAS,KAAK,KAAK,QAAQ,UAAU;AAAA,KAE/C,KAAK;AAAA;;MCZK,mBAAmB,CAC/B,KACA,EAAE,WAAW,aACD;AACZ,SAAO,OACL,IAAI,CAAC,UAAU;AACf,WAAO,GAAG,SAAS,KAAK,KAAK,QAAQ,GAAG,QAAW,YAAY;AAAA,KAE/D,KAAK;AAAA;;aCvCY;AAAA,EAUnB,YAAY,SAAwB;AACnC,SAAK,UAAU,QAAQ;AAAA;AAAA,EA+BxB,gBAAgB,MAAc,SAAyB,IAAI;AAC1D,WAAO,SAAS,GAAG,IAAI,IAAI,MAAM,KAAK,YAAY;AAAA;AAAA,EA6CnD,wBAAwB,MAAc,QAAgC;AACrE,WAAO,iBAAiB,GAAG,IAAI,IAAI,MAAM,KAAK,YAAY;AAAA;AAAA,EA2C3D,+BACC,MACA,QACC;AACD,WAAO,wBAAwB,GAAG,IAAI,IAAI,MAAM,KAAK,YAAY;AAAA;AAAA;;;;;;;"}
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":["../src/buildURL.ts","../src/buildPixelDensitySrcSet.ts","../src/buildWidthSrcSet.ts","../src/Client.ts"],"sourcesContent":["import type { ImgixURLParams } from \"./types.generated\";\n\n/**\n * Converts a camel case string to a param case string.\n *\n * @example\n *\n * ```ts\n * camelCaseToParamCase(\"fooBar\");\n * // => 'foo-bar'\n * ```\n *\n * @param input - Camel case string to convert.\n *\n * @returns Param case version of `input`.\n */\nconst camelCaseToParamCase = (input: string): string => {\n\treturn input.replace(/[A-Z]/g, (match) => {\n\t\treturn `-${match.toLowerCase()}`;\n\t});\n};\n\n/**\n * Builds a URL to an Imgix image with Imgix URL API parameters.\n *\n * The given URL must be a full absolute URL containing the protocol and domain.\n *\n * URL parameters already applied to the image will be retained. To remove\n * existing parameters, set the parameter to `undefined` in the `params` argument.\n *\n * @example\n *\n * ```ts\n * const url = buildURL(\"https://example.imgix.net/image.png\", {\n * \twidth: 400,\n * });\n * // => https://example.imgix.net/image.png?width=400\n * ```\n *\n * @example\n *\n * ```ts\n * const url = buildURL(\"https://example.imgix.net/image.png?width=400\", {\n * \theight: 300,\n * });\n * // => https://example.imgix.net/image.png?width=400&height=300\n * ```\n *\n * @param url - Full absolute URL to the Imgix image.\n * @param params - An object of Imgix URL API parameters.\n *\n * @returns `url` with the given Imgix URL API parameters applied.\n *\n * @see Imgix URL API reference: https://docs.imgix.com/apis/rendering\n */\nexport const buildURL = (url: string, params: ImgixURLParams): string => {\n\tconst instance = new URL(url);\n\n\tfor (const camelCasedParamKey in params) {\n\t\tconst paramKey = camelCaseToParamCase(camelCasedParamKey);\n\t\tconst paramValue = params[camelCasedParamKey as keyof typeof params];\n\n\t\tif (paramValue === undefined) {\n\t\t\tinstance.searchParams.delete(paramKey);\n\t\t} else if (Array.isArray(paramValue)) {\n\t\t\tinstance.searchParams.set(paramKey, paramValue.join(\",\"));\n\t\t} else {\n\t\t\tinstance.searchParams.set(paramKey, `${paramValue}`);\n\t\t}\n\t}\n\n\t// Ensure the `s` parameter is the last parameter, if it exists.\n\t// @see https://github.com/imgix/imgix-blueprint#securing-urls\n\tconst s = instance.searchParams.get(\"s\");\n\tif (s) {\n\t\tinstance.searchParams.delete(\"s\");\n\t\tinstance.searchParams.append(\"s\", s);\n\t}\n\n\treturn instance.toString();\n};\n","import type { ImgixURLParams } from \"./types.generated\";\nimport { buildURL } from \"./buildURL\";\n\n/**\n * Parameters for `buildPixelDensitySrcSet`.\n */\nexport type BuildPixelDensitySrcSetParams = Omit<ImgixURLParams, \"dpr\"> & {\n\t/**\n\t * The pixel densities to include in the resulting `srcset` value.\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * [1, 2, 3];\n\t * ```\n\t */\n\tpixelDensities: number[];\n};\n\n/**\n * Builds an `<img>` `srcset` attribute value for a given set of pixel\n * densities. It can also optinally apply Imgix URL API parameters to the URLs.\n *\n * The `dpr` URL parameter will be applied for each `srcset` entry. If a `dpr`\n * parameter is provided to the `params` parameter, it will be ignored.\n *\n * @example\n *\n * ```ts\n * const srcset = buildPixelDensitySrcSet(\n * \t\"https://example.imgix.net/image.png\",\n * \t{ pixelDensities: [1, 2, 3] },\n * );\n * // => https://example.imgix.net/image.png?dpr=1 1x,\n * // https://example.imgix.net/image.png?dpr=2 2x,\n * // https://example.imgix.net/image.png?dpr=3 3x\n * ```\n *\n * @example\n *\n * ```ts\n * const srcset = buildPixelDensitySrcSet(\n * \t\"https://example.imgix.net/image.png\",\n * \t{\n * \t\tpixelDensities: [1, 2, 3],\n * \t\tsat: -100,\n * \t},\n * );\n * // => https://example.imgix.net/image.png?dpr=1&sat=-100 1x,\n * // https://example.imgix.net/image.png?dpr=2&sat=-100 2x,\n * // https://example.imgix.net/image.png?dpr=3&sat=-100 3x\n * ```\n *\n * @param url - Full absolute URL to the Imgix image.\n * @param params - An object of Imgix URL API parameters. The `pixelDensities`\n * parameter defines the resulting `srcset` widths.\n *\n * @returns A `srcset` attribute value for `url` with the given Imgix URL API\n * parameters applied.\n */\nexport const buildPixelDensitySrcSet = (\n\turl: string,\n\t{ pixelDensities, ...params }: BuildPixelDensitySrcSetParams,\n): string => {\n\treturn pixelDensities\n\t\t.map((dpr) => {\n\t\t\treturn `${buildURL(url, { ...params, dpr })} ${dpr}x`;\n\t\t})\n\t\t.join(\", \");\n};\n","import type { ImgixURLParams } from \"./types.generated\";\nimport { buildURL } from \"./buildURL\";\n\n/**\n * Parameters for `buildWidthSrcSet`.\n */\nexport type BuildWidthSrcSetParams = Omit<ImgixURLParams, \"width\" | \"w\"> & {\n\t/**\n\t * The pixel widths to include in the resulting `srcset` value.\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * [400, 800, 1600];\n\t * ```\n\t */\n\twidths: number[];\n};\n\n/**\n * Builds an `<img>` `srcset` attribute value for a given set of widths. It can\n * also optinally apply Imgix URL API parameters to the URLs.\n *\n * The `width` URL parameter will be applied for each `srcset` entry. If a\n * `width` or `w` parameter is provided to the `params` parameter, it will be ignored.\n *\n * @example\n *\n * ```ts\n * const srcset = buildWidthSrcSet(\"https://example.imgix.net/image.png\", {\n * \twidths: [400, 800, 1600],\n * });\n * // => https://example.imgix.net/image.png?width=400 400w,\n * // https://example.imgix.net/image.png?width=800 800w,\n * // https://example.imgix.net/image.png?width=1600 1600w\n * ```\n *\n * @example\n *\n * ```ts\n * const srcset = buildWidthSrcSet(\"https://example.imgix.net/image.png\", {\n * \twidths: [400, 800, 1600],\n * \tsat: -100,\n * });\n * // => https://example.imgix.net/image.png?width=400&sat=-100 400w,\n * // https://example.imgix.net/image.png?width=800&sat=-100 800w,\n * // https://example.imgix.net/image.png?width=1600&sat=-100 1600w\n * ```\n *\n * @param url - Full absolute URL to the Imgix image.\n * @param params - An object of Imgix URL API parameters. The `widths` parameter\n * defines the resulting `srcset` widths.\n *\n * @returns A `srcset` attribute value for `url` with the given Imgix URL API\n * parameters applied.\n */\nexport const buildWidthSrcSet = (\n\turl: string,\n\t{ widths, ...params }: BuildWidthSrcSetParams,\n): string => {\n\treturn widths\n\t\t.map((width) => {\n\t\t\treturn `${buildURL(url, { ...params, w: undefined, width })} ${width}w`;\n\t\t})\n\t\t.join(\", \");\n};\n","import type { BuildPixelDensitySrcSetParams } from \"./buildPixelDensitySrcSet\";\nimport type { BuildWidthSrcSetParams } from \"./buildWidthSrcSet\";\nimport type { ImgixURLParams } from \"./types.generated\";\nimport { buildPixelDensitySrcSet } from \"./buildPixelDensitySrcSet\";\nimport { buildURL } from \"./buildURL\";\nimport { buildWidthSrcSet } from \"./buildWidthSrcSet\";\n\n/**\n * Options to instantiate a new client.\n */\nexport type ClientOptions = {\n\t/**\n\t * The base URL used to construct image URLs from a path. The base URL must\n\t * include the protocol, domain, and optionally a path.\n\t *\n\t * @example `https://example.imgix.net`\n\t *\n\t * @example `https://example.imgix.net/folder`\n\t */\n\tbaseURL: string;\n};\n\n/**\n * An Imgix Rendering API client. A client is paired to a single Imgix domain.\n */\nexport class Client {\n\tbaseURL: string;\n\n\t/**\n\t * Creates a new `Client` instance for an Imgix domain.\n\t *\n\t * @param options - Options to instantiate a new client.\n\t *\n\t * @returns A `Client` instance for the given Imgix domain.\n\t */\n\tconstructor(options: ClientOptions) {\n\t\tthis.baseURL = options.baseURL;\n\t}\n\n\t/**\n\t * Builds a URL to an Imgix image with Imgix URL API parameters for the\n\t * client's base URL.\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * const client = new Client({ baseURL: \"https://example.imgix.net\" });\n\t * const url = client.buildURLForPath(\"/image.png\", { width: 400 });\n\t * // => https://example.imgix.net/image.png?width=400\n\t * ```\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * const client = new Client({\n\t * \tbaseURL: \"https://example.imgix.net/folder\",\n\t * });\n\t * const url = client.buildURLForPath(\"./image.png\", { width: 400 });\n\t * // => https://example.imgix.net/folder/image.png?width=400\n\t * ```\n\t *\n\t * @param path - Path to the image relative to the client's base URL.\n\t * @param params - An object of Imgix URL API parameters.\n\t *\n\t * @returns The full absolute URL to the image with the given Imgix URL API\n\t * parameters applied.\n\t */\n\tbuildURLForPath(path: string, params: ImgixURLParams = {}) {\n\t\treturn buildURL(`${new URL(path, this.baseURL)}`, params);\n\t}\n\n\t/**\n\t * Builds an `<img>` `srcset` attribute value for a given set of widths for\n\t * the client's base URL. It can also optinally apply Imgix URL API parameters\n\t * to the URLs.\n\t *\n\t * The `width` URL parameter will be applied for each `srcset` entry. If a\n\t * `width` or `w` parameter is provided to the `params` parameter, it will be ignored.\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * const client = new Client({ baseURL: \"https://example.imgix.net\" });\n\t * const srcset = client.buildWidthSrcSetForPath(\"/image.png\", {\n\t * \twidths: [400, 800, 1600],\n\t * });\n\t * // => https://example.imgix.net/image.png?width=400 400w,\n\t * // https://example.imgix.net/image.png?width=800 800w,\n\t * // https://example.imgix.net/image.png?width=1600 1600w\n\t * ```\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * const client = new Client({\n\t * \tbaseURL: \"https://example.imgix.net\",\n\t * });\n\t * const srcset = client.buildWidthSrcSetForPath(\"/image.png\", {\n\t * \twidths: [400, 800, 1600],\n\t * \tsat: -100,\n\t * });\n\t * // => https://example.imgix.net/image.png?width=400&sat=-100 400w,\n\t * // https://example.imgix.net/image.png?width=800&sat=-100 800w,\n\t * // https://example.imgix.net/image.png?width=1600&sat=-100 1600w\n\t * ```\n\t *\n\t * @param path - Path to the image relative to the client's base URL.\n\t * @param params - An object of Imgix URL API parameters. The `widths`\n\t * parameter defines the resulting `srcset` widths.\n\t *\n\t * @returns A `srcset` attribute value for `url` with the given Imgix URL API\n\t * parameters applied.\n\t */\n\tbuildWidthSrcSetForPath(path: string, params: BuildWidthSrcSetParams) {\n\t\treturn buildWidthSrcSet(`${new URL(path, this.baseURL)}`, params);\n\t}\n\n\t/**\n\t * Builds an `<img>` `srcset` attribute value for a given set of pixel\n\t * densities for the client's base URL. It can also optinally apply Imgix URL\n\t * API parameters to the URLs.\n\t *\n\t * The `dpr` URL parameter will be applied for each `srcset` entry. If a `dpr`\n\t * parameter is provided to the `params` parameter, it will be ignored.\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * const client = new Client({ baseURL: \"https://example.imgix.net\" });\n\t * const srcset = client.buildPixelDensitySrcSetForPath(\"/image.png\", {\n\t * \tpixelDensities: [1, 2, 3],\n\t * });\n\t * // => https://example.imgix.net/image.png?dpr=1 1x,\n\t * // https://example.imgix.net/image.png?dpr=2 2x,\n\t * // https://example.imgix.net/image.png?dpr=3 3x\n\t * ```\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * const client = new Client({ baseURL: \"https://example.imgix.net\" });\n\t * const srcset = client.buildPixelDensitySrcSetForPath(\"/image.png\", {\n\t * \tpixelDensities: [1, 2, 3],\n\t * \tsat: -100,\n\t * });\n\t * // => https://example.imgix.net/image.png?dpr=1&sat=-100 1x,\n\t * // https://example.imgix.net/image.png?dpr=2&sat=-100 2x,\n\t * // https://example.imgix.net/image.png?dpr=3&sat=-100 3x\n\t * ```\n\t *\n\t * @param path - Path to the image relative to the client's base URL.\n\t * @param params - An object of Imgix URL API parameters. The `pixelDensities`\n\t * parameter defines the resulting `srcset` widths.\n\t *\n\t * @returns A `srcset` attribute value for `url` with the given Imgix URL API\n\t * parameters applied.\n\t */\n\tbuildPixelDensitySrcSetForPath(\n\t\tpath: string,\n\t\tparams: BuildPixelDensitySrcSetParams,\n\t) {\n\t\treturn buildPixelDensitySrcSet(`${new URL(path, this.baseURL)}`, params);\n\t}\n}\n"],"names":[],"mappings":";;;;AAgBA,MAAM,uBAAuB,CAAC,UAA0B;AACvD,SAAO,MAAM,QAAQ,UAAU,CAAC,UAAU;AACzC,WAAO,IAAI,MAAM;AAAA;AAAA;MAqCN,WAAW,CAAC,KAAa,WAAmC;AACxE,QAAM,WAAW,IAAI,IAAI;AAEzB,aAAW,sBAAsB,QAAQ;AACxC,UAAM,WAAW,qBAAqB;AACtC,UAAM,aAAa,OAAO;AAE1B,QAAI,eAAe,QAAW;AAC7B,eAAS,aAAa,OAAO;AAAA,eACnB,MAAM,QAAQ,aAAa;AACrC,eAAS,aAAa,IAAI,UAAU,WAAW,KAAK;AAAA,WAC9C;AACN,eAAS,aAAa,IAAI,UAAU,GAAG;AAAA;AAAA;AAMzC,QAAM,IAAI,SAAS,aAAa,IAAI;AACpC,MAAI,GAAG;AACN,aAAS,aAAa,OAAO;AAC7B,aAAS,aAAa,OAAO,KAAK;AAAA;AAGnC,SAAO,SAAS;AAAA;;MCnBJ,0BAA0B,CACtC,KACA,EAAE,mBAAmB,aACT;AACZ,SAAO,eACL,IAAI,CAAC,QAAQ;AACb,WAAO,GAAG,SAAS,KAAK,KAAK,QAAQ,UAAU;AAAA,KAE/C,KAAK;AAAA;;MCZK,mBAAmB,CAC/B,KACA,EAAE,WAAW,aACD;AACZ,SAAO,OACL,IAAI,CAAC,UAAU;AACf,WAAO,GAAG,SAAS,KAAK,KAAK,QAAQ,GAAG,QAAW,YAAY;AAAA,KAE/D,KAAK;AAAA;;aCvCY;AAAA,EAUnB,YAAY,SAAwB;AACnC,SAAK,UAAU,QAAQ;AAAA;AAAA,EA+BxB,gBAAgB,MAAc,SAAyB,IAAI;AAC1D,WAAO,SAAS,GAAG,IAAI,IAAI,MAAM,KAAK,YAAY;AAAA;AAAA,EA6CnD,wBAAwB,MAAc,QAAgC;AACrE,WAAO,iBAAiB,GAAG,IAAI,IAAI,MAAM,KAAK,YAAY;AAAA;AAAA,EA2C3D,+BACC,MACA,QACC;AACD,WAAO,wBAAwB,GAAG,IAAI,IAAI,MAAM,KAAK,YAAY;AAAA;AAAA;;;;;;;"}
|
package/dist/index.mjs
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
const camelCaseToParamCase = (input) => {
|
|
2
|
+
return input.replace(/[A-Z]/g, (match) => {
|
|
3
|
+
return `-${match.toLowerCase()}`;
|
|
4
|
+
});
|
|
5
|
+
};
|
|
3
6
|
const buildURL = (url, params) => {
|
|
4
7
|
const instance = new URL(url);
|
|
5
8
|
for (const camelCasedParamKey in params) {
|
|
6
|
-
const paramKey =
|
|
9
|
+
const paramKey = camelCaseToParamCase(camelCasedParamKey);
|
|
7
10
|
const paramValue = params[camelCasedParamKey];
|
|
8
11
|
if (paramValue === void 0) {
|
|
9
12
|
instance.searchParams.delete(paramKey);
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sources":["../src/buildURL.ts","../src/buildPixelDensitySrcSet.ts","../src/buildWidthSrcSet.ts","../src/Client.ts"],"sourcesContent":["import { paramCase } from \"param-case\";\n\nimport type { ImgixURLParams } from \"./types.generated\";\n\n/**\n * Builds a URL to an Imgix image with Imgix URL API parameters.\n *\n * The given URL must be a full absolute URL containing the protocol and domain.\n *\n * URL parameters already applied to the image will be retained. To remove\n * existing parameters, set the parameter to `undefined` in the `params` argument.\n *\n * @example\n *\n * ```ts\n * const url = buildURL(\"https://example.imgix.net/image.png\", {\n * \twidth: 400,\n * });\n * // => https://example.imgix.net/image.png?width=400\n * ```\n *\n * @example\n *\n * ```ts\n * const url = buildURL(\"https://example.imgix.net/image.png?width=400\", {\n * \theight: 300,\n * });\n * // => https://example.imgix.net/image.png?width=400&height=300\n * ```\n *\n * @param url - Full absolute URL to the Imgix image.\n * @param params - An object of Imgix URL API parameters.\n *\n * @returns `url` with the given Imgix URL API parameters applied.\n *\n * @see Imgix URL API reference: https://docs.imgix.com/apis/rendering\n */\nexport const buildURL = (url: string, params: ImgixURLParams): string => {\n\tconst instance = new URL(url);\n\n\tfor (const camelCasedParamKey in params) {\n\t\tconst paramKey = paramCase(camelCasedParamKey);\n\t\tconst paramValue = params[camelCasedParamKey as keyof typeof params];\n\n\t\tif (paramValue === undefined) {\n\t\t\tinstance.searchParams.delete(paramKey);\n\t\t} else if (Array.isArray(paramValue)) {\n\t\t\tinstance.searchParams.set(paramKey, paramValue.join(\",\"));\n\t\t} else {\n\t\t\tinstance.searchParams.set(paramKey, `${paramValue}`);\n\t\t}\n\t}\n\n\t// Ensure the `s` parameter is the last parameter, if it exists.\n\t// @see https://github.com/imgix/imgix-blueprint#securing-urls\n\tconst s = instance.searchParams.get(\"s\");\n\tif (s) {\n\t\tinstance.searchParams.delete(\"s\");\n\t\tinstance.searchParams.append(\"s\", s);\n\t}\n\n\treturn instance.toString();\n};\n","import type { ImgixURLParams } from \"./types.generated\";\nimport { buildURL } from \"./buildURL\";\n\n/**\n * Parameters for `buildPixelDensitySrcSet`.\n */\nexport type BuildPixelDensitySrcSetParams = Omit<ImgixURLParams, \"dpr\"> & {\n\t/**\n\t * The pixel densities to include in the resulting `srcset` value.\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * [1, 2, 3];\n\t * ```\n\t */\n\tpixelDensities: number[];\n};\n\n/**\n * Builds an `<img>` `srcset` attribute value for a given set of pixel\n * densities. It can also optinally apply Imgix URL API parameters to the URLs.\n *\n * The `dpr` URL parameter will be applied for each `srcset` entry. If a `dpr`\n * parameter is provided to the `params` parameter, it will be ignored.\n *\n * @example\n *\n * ```ts\n * const srcset = buildPixelDensitySrcSet(\n * \t\"https://example.imgix.net/image.png\",\n * \t{ pixelDensities: [1, 2, 3] },\n * );\n * // => https://example.imgix.net/image.png?dpr=1 1x,\n * // https://example.imgix.net/image.png?dpr=2 2x,\n * // https://example.imgix.net/image.png?dpr=3 3x\n * ```\n *\n * @example\n *\n * ```ts\n * const srcset = buildPixelDensitySrcSet(\n * \t\"https://example.imgix.net/image.png\",\n * \t{\n * \t\tpixelDensities: [1, 2, 3],\n * \t\tsat: -100,\n * \t},\n * );\n * // => https://example.imgix.net/image.png?dpr=1&sat=-100 1x,\n * // https://example.imgix.net/image.png?dpr=2&sat=-100 2x,\n * // https://example.imgix.net/image.png?dpr=3&sat=-100 3x\n * ```\n *\n * @param url - Full absolute URL to the Imgix image.\n * @param params - An object of Imgix URL API parameters. The `pixelDensities`\n * parameter defines the resulting `srcset` widths.\n *\n * @returns A `srcset` attribute value for `url` with the given Imgix URL API\n * parameters applied.\n */\nexport const buildPixelDensitySrcSet = (\n\turl: string,\n\t{ pixelDensities, ...params }: BuildPixelDensitySrcSetParams,\n): string => {\n\treturn pixelDensities\n\t\t.map((dpr) => {\n\t\t\treturn `${buildURL(url, { ...params, dpr })} ${dpr}x`;\n\t\t})\n\t\t.join(\", \");\n};\n","import type { ImgixURLParams } from \"./types.generated\";\nimport { buildURL } from \"./buildURL\";\n\n/**\n * Parameters for `buildWidthSrcSet`.\n */\nexport type BuildWidthSrcSetParams = Omit<ImgixURLParams, \"width\" | \"w\"> & {\n\t/**\n\t * The pixel widths to include in the resulting `srcset` value.\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * [400, 800, 1600];\n\t * ```\n\t */\n\twidths: number[];\n};\n\n/**\n * Builds an `<img>` `srcset` attribute value for a given set of widths. It can\n * also optinally apply Imgix URL API parameters to the URLs.\n *\n * The `width` URL parameter will be applied for each `srcset` entry. If a\n * `width` or `w` parameter is provided to the `params` parameter, it will be ignored.\n *\n * @example\n *\n * ```ts\n * const srcset = buildWidthSrcSet(\"https://example.imgix.net/image.png\", {\n * \twidths: [400, 800, 1600],\n * });\n * // => https://example.imgix.net/image.png?width=400 400w,\n * // https://example.imgix.net/image.png?width=800 800w,\n * // https://example.imgix.net/image.png?width=1600 1600w\n * ```\n *\n * @example\n *\n * ```ts\n * const srcset = buildWidthSrcSet(\"https://example.imgix.net/image.png\", {\n * \twidths: [400, 800, 1600],\n * \tsat: -100,\n * });\n * // => https://example.imgix.net/image.png?width=400&sat=-100 400w,\n * // https://example.imgix.net/image.png?width=800&sat=-100 800w,\n * // https://example.imgix.net/image.png?width=1600&sat=-100 1600w\n * ```\n *\n * @param url - Full absolute URL to the Imgix image.\n * @param params - An object of Imgix URL API parameters. The `widths` parameter\n * defines the resulting `srcset` widths.\n *\n * @returns A `srcset` attribute value for `url` with the given Imgix URL API\n * parameters applied.\n */\nexport const buildWidthSrcSet = (\n\turl: string,\n\t{ widths, ...params }: BuildWidthSrcSetParams,\n): string => {\n\treturn widths\n\t\t.map((width) => {\n\t\t\treturn `${buildURL(url, { ...params, w: undefined, width })} ${width}w`;\n\t\t})\n\t\t.join(\", \");\n};\n","import type { BuildPixelDensitySrcSetParams } from \"./buildPixelDensitySrcSet\";\nimport type { BuildWidthSrcSetParams } from \"./buildWidthSrcSet\";\nimport type { ImgixURLParams } from \"./types.generated\";\nimport { buildPixelDensitySrcSet } from \"./buildPixelDensitySrcSet\";\nimport { buildURL } from \"./buildURL\";\nimport { buildWidthSrcSet } from \"./buildWidthSrcSet\";\n\n/**\n * Options to instantiate a new client.\n */\nexport type ClientOptions = {\n\t/**\n\t * The base URL used to construct image URLs from a path. The base URL must\n\t * include the protocol, domain, and optionally a path.\n\t *\n\t * @example `https://example.imgix.net`\n\t *\n\t * @example `https://example.imgix.net/folder`\n\t */\n\tbaseURL: string;\n};\n\n/**\n * An Imgix Rendering API client. A client is paired to a single Imgix domain.\n */\nexport class Client {\n\tbaseURL: string;\n\n\t/**\n\t * Creates a new `Client` instance for an Imgix domain.\n\t *\n\t * @param options - Options to instantiate a new client.\n\t *\n\t * @returns A `Client` instance for the given Imgix domain.\n\t */\n\tconstructor(options: ClientOptions) {\n\t\tthis.baseURL = options.baseURL;\n\t}\n\n\t/**\n\t * Builds a URL to an Imgix image with Imgix URL API parameters for the\n\t * client's base URL.\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * const client = new Client({ baseURL: \"https://example.imgix.net\" });\n\t * const url = client.buildURLForPath(\"/image.png\", { width: 400 });\n\t * // => https://example.imgix.net/image.png?width=400\n\t * ```\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * const client = new Client({\n\t * \tbaseURL: \"https://example.imgix.net/folder\",\n\t * });\n\t * const url = client.buildURLForPath(\"./image.png\", { width: 400 });\n\t * // => https://example.imgix.net/folder/image.png?width=400\n\t * ```\n\t *\n\t * @param path - Path to the image relative to the client's base URL.\n\t * @param params - An object of Imgix URL API parameters.\n\t *\n\t * @returns The full absolute URL to the image with the given Imgix URL API\n\t * parameters applied.\n\t */\n\tbuildURLForPath(path: string, params: ImgixURLParams = {}) {\n\t\treturn buildURL(`${new URL(path, this.baseURL)}`, params);\n\t}\n\n\t/**\n\t * Builds an `<img>` `srcset` attribute value for a given set of widths for\n\t * the client's base URL. It can also optinally apply Imgix URL API parameters\n\t * to the URLs.\n\t *\n\t * The `width` URL parameter will be applied for each `srcset` entry. If a\n\t * `width` or `w` parameter is provided to the `params` parameter, it will be ignored.\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * const client = new Client({ baseURL: \"https://example.imgix.net\" });\n\t * const srcset = client.buildWidthSrcSetForPath(\"/image.png\", {\n\t * \twidths: [400, 800, 1600],\n\t * });\n\t * // => https://example.imgix.net/image.png?width=400 400w,\n\t * // https://example.imgix.net/image.png?width=800 800w,\n\t * // https://example.imgix.net/image.png?width=1600 1600w\n\t * ```\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * const client = new Client({\n\t * \tbaseURL: \"https://example.imgix.net\",\n\t * });\n\t * const srcset = client.buildWidthSrcSetForPath(\"/image.png\", {\n\t * \twidths: [400, 800, 1600],\n\t * \tsat: -100,\n\t * });\n\t * // => https://example.imgix.net/image.png?width=400&sat=-100 400w,\n\t * // https://example.imgix.net/image.png?width=800&sat=-100 800w,\n\t * // https://example.imgix.net/image.png?width=1600&sat=-100 1600w\n\t * ```\n\t *\n\t * @param path - Path to the image relative to the client's base URL.\n\t * @param params - An object of Imgix URL API parameters. The `widths`\n\t * parameter defines the resulting `srcset` widths.\n\t *\n\t * @returns A `srcset` attribute value for `url` with the given Imgix URL API\n\t * parameters applied.\n\t */\n\tbuildWidthSrcSetForPath(path: string, params: BuildWidthSrcSetParams) {\n\t\treturn buildWidthSrcSet(`${new URL(path, this.baseURL)}`, params);\n\t}\n\n\t/**\n\t * Builds an `<img>` `srcset` attribute value for a given set of pixel\n\t * densities for the client's base URL. It can also optinally apply Imgix URL\n\t * API parameters to the URLs.\n\t *\n\t * The `dpr` URL parameter will be applied for each `srcset` entry. If a `dpr`\n\t * parameter is provided to the `params` parameter, it will be ignored.\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * const client = new Client({ baseURL: \"https://example.imgix.net\" });\n\t * const srcset = client.buildPixelDensitySrcSetForPath(\"/image.png\", {\n\t * \tpixelDensities: [1, 2, 3],\n\t * });\n\t * // => https://example.imgix.net/image.png?dpr=1 1x,\n\t * // https://example.imgix.net/image.png?dpr=2 2x,\n\t * // https://example.imgix.net/image.png?dpr=3 3x\n\t * ```\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * const client = new Client({ baseURL: \"https://example.imgix.net\" });\n\t * const srcset = client.buildPixelDensitySrcSetForPath(\"/image.png\", {\n\t * \tpixelDensities: [1, 2, 3],\n\t * \tsat: -100,\n\t * });\n\t * // => https://example.imgix.net/image.png?dpr=1&sat=-100 1x,\n\t * // https://example.imgix.net/image.png?dpr=2&sat=-100 2x,\n\t * // https://example.imgix.net/image.png?dpr=3&sat=-100 3x\n\t * ```\n\t *\n\t * @param path - Path to the image relative to the client's base URL.\n\t * @param params - An object of Imgix URL API parameters. The `pixelDensities`\n\t * parameter defines the resulting `srcset` widths.\n\t *\n\t * @returns A `srcset` attribute value for `url` with the given Imgix URL API\n\t * parameters applied.\n\t */\n\tbuildPixelDensitySrcSetForPath(\n\t\tpath: string,\n\t\tparams: BuildPixelDensitySrcSetParams,\n\t) {\n\t\treturn buildPixelDensitySrcSet(`${new URL(path, this.baseURL)}`, params);\n\t}\n}\n"],"names":[],"mappings":";;MAqCa,WAAW,CAAC,KAAa,WAAmC;AACxE,QAAM,WAAW,IAAI,IAAI;AAEzB,aAAW,sBAAsB,QAAQ;AACxC,UAAM,WAAW,UAAU;AAC3B,UAAM,aAAa,OAAO;AAE1B,QAAI,eAAe,QAAW;AAC7B,eAAS,aAAa,OAAO;AAAA,eACnB,MAAM,QAAQ,aAAa;AACrC,eAAS,aAAa,IAAI,UAAU,WAAW,KAAK;AAAA,WAC9C;AACN,eAAS,aAAa,IAAI,UAAU,GAAG;AAAA;AAAA;AAMzC,QAAM,IAAI,SAAS,aAAa,IAAI;AACpC,MAAI,GAAG;AACN,aAAS,aAAa,OAAO;AAC7B,aAAS,aAAa,OAAO,KAAK;AAAA;AAGnC,SAAO,SAAS;AAAA;;MCDJ,0BAA0B,CACtC,KACA,EAAE,mBAAmB,aACT;AACZ,SAAO,eACL,IAAI,CAAC,QAAQ;AACb,WAAO,GAAG,SAAS,KAAK,KAAK,QAAQ,UAAU;AAAA,KAE/C,KAAK;AAAA;;MCZK,mBAAmB,CAC/B,KACA,EAAE,WAAW,aACD;AACZ,SAAO,OACL,IAAI,CAAC,UAAU;AACf,WAAO,GAAG,SAAS,KAAK,KAAK,QAAQ,GAAG,QAAW,YAAY;AAAA,KAE/D,KAAK;AAAA;;aCvCY;AAAA,EAUnB,YAAY,SAAwB;AACnC,SAAK,UAAU,QAAQ;AAAA;AAAA,EA+BxB,gBAAgB,MAAc,SAAyB,IAAI;AAC1D,WAAO,SAAS,GAAG,IAAI,IAAI,MAAM,KAAK,YAAY;AAAA;AAAA,EA6CnD,wBAAwB,MAAc,QAAgC;AACrE,WAAO,iBAAiB,GAAG,IAAI,IAAI,MAAM,KAAK,YAAY;AAAA;AAAA,EA2C3D,+BACC,MACA,QACC;AACD,WAAO,wBAAwB,GAAG,IAAI,IAAI,MAAM,KAAK,YAAY;AAAA;AAAA;;;;"}
|
|
1
|
+
{"version":3,"file":"index.mjs","sources":["../src/buildURL.ts","../src/buildPixelDensitySrcSet.ts","../src/buildWidthSrcSet.ts","../src/Client.ts"],"sourcesContent":["import type { ImgixURLParams } from \"./types.generated\";\n\n/**\n * Converts a camel case string to a param case string.\n *\n * @example\n *\n * ```ts\n * camelCaseToParamCase(\"fooBar\");\n * // => 'foo-bar'\n * ```\n *\n * @param input - Camel case string to convert.\n *\n * @returns Param case version of `input`.\n */\nconst camelCaseToParamCase = (input: string): string => {\n\treturn input.replace(/[A-Z]/g, (match) => {\n\t\treturn `-${match.toLowerCase()}`;\n\t});\n};\n\n/**\n * Builds a URL to an Imgix image with Imgix URL API parameters.\n *\n * The given URL must be a full absolute URL containing the protocol and domain.\n *\n * URL parameters already applied to the image will be retained. To remove\n * existing parameters, set the parameter to `undefined` in the `params` argument.\n *\n * @example\n *\n * ```ts\n * const url = buildURL(\"https://example.imgix.net/image.png\", {\n * \twidth: 400,\n * });\n * // => https://example.imgix.net/image.png?width=400\n * ```\n *\n * @example\n *\n * ```ts\n * const url = buildURL(\"https://example.imgix.net/image.png?width=400\", {\n * \theight: 300,\n * });\n * // => https://example.imgix.net/image.png?width=400&height=300\n * ```\n *\n * @param url - Full absolute URL to the Imgix image.\n * @param params - An object of Imgix URL API parameters.\n *\n * @returns `url` with the given Imgix URL API parameters applied.\n *\n * @see Imgix URL API reference: https://docs.imgix.com/apis/rendering\n */\nexport const buildURL = (url: string, params: ImgixURLParams): string => {\n\tconst instance = new URL(url);\n\n\tfor (const camelCasedParamKey in params) {\n\t\tconst paramKey = camelCaseToParamCase(camelCasedParamKey);\n\t\tconst paramValue = params[camelCasedParamKey as keyof typeof params];\n\n\t\tif (paramValue === undefined) {\n\t\t\tinstance.searchParams.delete(paramKey);\n\t\t} else if (Array.isArray(paramValue)) {\n\t\t\tinstance.searchParams.set(paramKey, paramValue.join(\",\"));\n\t\t} else {\n\t\t\tinstance.searchParams.set(paramKey, `${paramValue}`);\n\t\t}\n\t}\n\n\t// Ensure the `s` parameter is the last parameter, if it exists.\n\t// @see https://github.com/imgix/imgix-blueprint#securing-urls\n\tconst s = instance.searchParams.get(\"s\");\n\tif (s) {\n\t\tinstance.searchParams.delete(\"s\");\n\t\tinstance.searchParams.append(\"s\", s);\n\t}\n\n\treturn instance.toString();\n};\n","import type { ImgixURLParams } from \"./types.generated\";\nimport { buildURL } from \"./buildURL\";\n\n/**\n * Parameters for `buildPixelDensitySrcSet`.\n */\nexport type BuildPixelDensitySrcSetParams = Omit<ImgixURLParams, \"dpr\"> & {\n\t/**\n\t * The pixel densities to include in the resulting `srcset` value.\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * [1, 2, 3];\n\t * ```\n\t */\n\tpixelDensities: number[];\n};\n\n/**\n * Builds an `<img>` `srcset` attribute value for a given set of pixel\n * densities. It can also optinally apply Imgix URL API parameters to the URLs.\n *\n * The `dpr` URL parameter will be applied for each `srcset` entry. If a `dpr`\n * parameter is provided to the `params` parameter, it will be ignored.\n *\n * @example\n *\n * ```ts\n * const srcset = buildPixelDensitySrcSet(\n * \t\"https://example.imgix.net/image.png\",\n * \t{ pixelDensities: [1, 2, 3] },\n * );\n * // => https://example.imgix.net/image.png?dpr=1 1x,\n * // https://example.imgix.net/image.png?dpr=2 2x,\n * // https://example.imgix.net/image.png?dpr=3 3x\n * ```\n *\n * @example\n *\n * ```ts\n * const srcset = buildPixelDensitySrcSet(\n * \t\"https://example.imgix.net/image.png\",\n * \t{\n * \t\tpixelDensities: [1, 2, 3],\n * \t\tsat: -100,\n * \t},\n * );\n * // => https://example.imgix.net/image.png?dpr=1&sat=-100 1x,\n * // https://example.imgix.net/image.png?dpr=2&sat=-100 2x,\n * // https://example.imgix.net/image.png?dpr=3&sat=-100 3x\n * ```\n *\n * @param url - Full absolute URL to the Imgix image.\n * @param params - An object of Imgix URL API parameters. The `pixelDensities`\n * parameter defines the resulting `srcset` widths.\n *\n * @returns A `srcset` attribute value for `url` with the given Imgix URL API\n * parameters applied.\n */\nexport const buildPixelDensitySrcSet = (\n\turl: string,\n\t{ pixelDensities, ...params }: BuildPixelDensitySrcSetParams,\n): string => {\n\treturn pixelDensities\n\t\t.map((dpr) => {\n\t\t\treturn `${buildURL(url, { ...params, dpr })} ${dpr}x`;\n\t\t})\n\t\t.join(\", \");\n};\n","import type { ImgixURLParams } from \"./types.generated\";\nimport { buildURL } from \"./buildURL\";\n\n/**\n * Parameters for `buildWidthSrcSet`.\n */\nexport type BuildWidthSrcSetParams = Omit<ImgixURLParams, \"width\" | \"w\"> & {\n\t/**\n\t * The pixel widths to include in the resulting `srcset` value.\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * [400, 800, 1600];\n\t * ```\n\t */\n\twidths: number[];\n};\n\n/**\n * Builds an `<img>` `srcset` attribute value for a given set of widths. It can\n * also optinally apply Imgix URL API parameters to the URLs.\n *\n * The `width` URL parameter will be applied for each `srcset` entry. If a\n * `width` or `w` parameter is provided to the `params` parameter, it will be ignored.\n *\n * @example\n *\n * ```ts\n * const srcset = buildWidthSrcSet(\"https://example.imgix.net/image.png\", {\n * \twidths: [400, 800, 1600],\n * });\n * // => https://example.imgix.net/image.png?width=400 400w,\n * // https://example.imgix.net/image.png?width=800 800w,\n * // https://example.imgix.net/image.png?width=1600 1600w\n * ```\n *\n * @example\n *\n * ```ts\n * const srcset = buildWidthSrcSet(\"https://example.imgix.net/image.png\", {\n * \twidths: [400, 800, 1600],\n * \tsat: -100,\n * });\n * // => https://example.imgix.net/image.png?width=400&sat=-100 400w,\n * // https://example.imgix.net/image.png?width=800&sat=-100 800w,\n * // https://example.imgix.net/image.png?width=1600&sat=-100 1600w\n * ```\n *\n * @param url - Full absolute URL to the Imgix image.\n * @param params - An object of Imgix URL API parameters. The `widths` parameter\n * defines the resulting `srcset` widths.\n *\n * @returns A `srcset` attribute value for `url` with the given Imgix URL API\n * parameters applied.\n */\nexport const buildWidthSrcSet = (\n\turl: string,\n\t{ widths, ...params }: BuildWidthSrcSetParams,\n): string => {\n\treturn widths\n\t\t.map((width) => {\n\t\t\treturn `${buildURL(url, { ...params, w: undefined, width })} ${width}w`;\n\t\t})\n\t\t.join(\", \");\n};\n","import type { BuildPixelDensitySrcSetParams } from \"./buildPixelDensitySrcSet\";\nimport type { BuildWidthSrcSetParams } from \"./buildWidthSrcSet\";\nimport type { ImgixURLParams } from \"./types.generated\";\nimport { buildPixelDensitySrcSet } from \"./buildPixelDensitySrcSet\";\nimport { buildURL } from \"./buildURL\";\nimport { buildWidthSrcSet } from \"./buildWidthSrcSet\";\n\n/**\n * Options to instantiate a new client.\n */\nexport type ClientOptions = {\n\t/**\n\t * The base URL used to construct image URLs from a path. The base URL must\n\t * include the protocol, domain, and optionally a path.\n\t *\n\t * @example `https://example.imgix.net`\n\t *\n\t * @example `https://example.imgix.net/folder`\n\t */\n\tbaseURL: string;\n};\n\n/**\n * An Imgix Rendering API client. A client is paired to a single Imgix domain.\n */\nexport class Client {\n\tbaseURL: string;\n\n\t/**\n\t * Creates a new `Client` instance for an Imgix domain.\n\t *\n\t * @param options - Options to instantiate a new client.\n\t *\n\t * @returns A `Client` instance for the given Imgix domain.\n\t */\n\tconstructor(options: ClientOptions) {\n\t\tthis.baseURL = options.baseURL;\n\t}\n\n\t/**\n\t * Builds a URL to an Imgix image with Imgix URL API parameters for the\n\t * client's base URL.\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * const client = new Client({ baseURL: \"https://example.imgix.net\" });\n\t * const url = client.buildURLForPath(\"/image.png\", { width: 400 });\n\t * // => https://example.imgix.net/image.png?width=400\n\t * ```\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * const client = new Client({\n\t * \tbaseURL: \"https://example.imgix.net/folder\",\n\t * });\n\t * const url = client.buildURLForPath(\"./image.png\", { width: 400 });\n\t * // => https://example.imgix.net/folder/image.png?width=400\n\t * ```\n\t *\n\t * @param path - Path to the image relative to the client's base URL.\n\t * @param params - An object of Imgix URL API parameters.\n\t *\n\t * @returns The full absolute URL to the image with the given Imgix URL API\n\t * parameters applied.\n\t */\n\tbuildURLForPath(path: string, params: ImgixURLParams = {}) {\n\t\treturn buildURL(`${new URL(path, this.baseURL)}`, params);\n\t}\n\n\t/**\n\t * Builds an `<img>` `srcset` attribute value for a given set of widths for\n\t * the client's base URL. It can also optinally apply Imgix URL API parameters\n\t * to the URLs.\n\t *\n\t * The `width` URL parameter will be applied for each `srcset` entry. If a\n\t * `width` or `w` parameter is provided to the `params` parameter, it will be ignored.\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * const client = new Client({ baseURL: \"https://example.imgix.net\" });\n\t * const srcset = client.buildWidthSrcSetForPath(\"/image.png\", {\n\t * \twidths: [400, 800, 1600],\n\t * });\n\t * // => https://example.imgix.net/image.png?width=400 400w,\n\t * // https://example.imgix.net/image.png?width=800 800w,\n\t * // https://example.imgix.net/image.png?width=1600 1600w\n\t * ```\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * const client = new Client({\n\t * \tbaseURL: \"https://example.imgix.net\",\n\t * });\n\t * const srcset = client.buildWidthSrcSetForPath(\"/image.png\", {\n\t * \twidths: [400, 800, 1600],\n\t * \tsat: -100,\n\t * });\n\t * // => https://example.imgix.net/image.png?width=400&sat=-100 400w,\n\t * // https://example.imgix.net/image.png?width=800&sat=-100 800w,\n\t * // https://example.imgix.net/image.png?width=1600&sat=-100 1600w\n\t * ```\n\t *\n\t * @param path - Path to the image relative to the client's base URL.\n\t * @param params - An object of Imgix URL API parameters. The `widths`\n\t * parameter defines the resulting `srcset` widths.\n\t *\n\t * @returns A `srcset` attribute value for `url` with the given Imgix URL API\n\t * parameters applied.\n\t */\n\tbuildWidthSrcSetForPath(path: string, params: BuildWidthSrcSetParams) {\n\t\treturn buildWidthSrcSet(`${new URL(path, this.baseURL)}`, params);\n\t}\n\n\t/**\n\t * Builds an `<img>` `srcset` attribute value for a given set of pixel\n\t * densities for the client's base URL. It can also optinally apply Imgix URL\n\t * API parameters to the URLs.\n\t *\n\t * The `dpr` URL parameter will be applied for each `srcset` entry. If a `dpr`\n\t * parameter is provided to the `params` parameter, it will be ignored.\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * const client = new Client({ baseURL: \"https://example.imgix.net\" });\n\t * const srcset = client.buildPixelDensitySrcSetForPath(\"/image.png\", {\n\t * \tpixelDensities: [1, 2, 3],\n\t * });\n\t * // => https://example.imgix.net/image.png?dpr=1 1x,\n\t * // https://example.imgix.net/image.png?dpr=2 2x,\n\t * // https://example.imgix.net/image.png?dpr=3 3x\n\t * ```\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * const client = new Client({ baseURL: \"https://example.imgix.net\" });\n\t * const srcset = client.buildPixelDensitySrcSetForPath(\"/image.png\", {\n\t * \tpixelDensities: [1, 2, 3],\n\t * \tsat: -100,\n\t * });\n\t * // => https://example.imgix.net/image.png?dpr=1&sat=-100 1x,\n\t * // https://example.imgix.net/image.png?dpr=2&sat=-100 2x,\n\t * // https://example.imgix.net/image.png?dpr=3&sat=-100 3x\n\t * ```\n\t *\n\t * @param path - Path to the image relative to the client's base URL.\n\t * @param params - An object of Imgix URL API parameters. The `pixelDensities`\n\t * parameter defines the resulting `srcset` widths.\n\t *\n\t * @returns A `srcset` attribute value for `url` with the given Imgix URL API\n\t * parameters applied.\n\t */\n\tbuildPixelDensitySrcSetForPath(\n\t\tpath: string,\n\t\tparams: BuildPixelDensitySrcSetParams,\n\t) {\n\t\treturn buildPixelDensitySrcSet(`${new URL(path, this.baseURL)}`, params);\n\t}\n}\n"],"names":[],"mappings":"AAgBA,MAAM,uBAAuB,CAAC,UAA0B;AACvD,SAAO,MAAM,QAAQ,UAAU,CAAC,UAAU;AACzC,WAAO,IAAI,MAAM;AAAA;AAAA;MAqCN,WAAW,CAAC,KAAa,WAAmC;AACxE,QAAM,WAAW,IAAI,IAAI;AAEzB,aAAW,sBAAsB,QAAQ;AACxC,UAAM,WAAW,qBAAqB;AACtC,UAAM,aAAa,OAAO;AAE1B,QAAI,eAAe,QAAW;AAC7B,eAAS,aAAa,OAAO;AAAA,eACnB,MAAM,QAAQ,aAAa;AACrC,eAAS,aAAa,IAAI,UAAU,WAAW,KAAK;AAAA,WAC9C;AACN,eAAS,aAAa,IAAI,UAAU,GAAG;AAAA;AAAA;AAMzC,QAAM,IAAI,SAAS,aAAa,IAAI;AACpC,MAAI,GAAG;AACN,aAAS,aAAa,OAAO;AAC7B,aAAS,aAAa,OAAO,KAAK;AAAA;AAGnC,SAAO,SAAS;AAAA;;MCnBJ,0BAA0B,CACtC,KACA,EAAE,mBAAmB,aACT;AACZ,SAAO,eACL,IAAI,CAAC,QAAQ;AACb,WAAO,GAAG,SAAS,KAAK,KAAK,QAAQ,UAAU;AAAA,KAE/C,KAAK;AAAA;;MCZK,mBAAmB,CAC/B,KACA,EAAE,WAAW,aACD;AACZ,SAAO,OACL,IAAI,CAAC,UAAU;AACf,WAAO,GAAG,SAAS,KAAK,KAAK,QAAQ,GAAG,QAAW,YAAY;AAAA,KAE/D,KAAK;AAAA;;aCvCY;AAAA,EAUnB,YAAY,SAAwB;AACnC,SAAK,UAAU,QAAQ;AAAA;AAAA,EA+BxB,gBAAgB,MAAc,SAAyB,IAAI;AAC1D,WAAO,SAAS,GAAG,IAAI,IAAI,MAAM,KAAK,YAAY;AAAA;AAAA,EA6CnD,wBAAwB,MAAc,QAAgC;AACrE,WAAO,iBAAiB,GAAG,IAAI,IAAI,MAAM,KAAK,YAAY;AAAA;AAAA,EA2C3D,+BACC,MACA,QACC;AACD,WAAO,wBAAwB,GAAG,IAAI,IAAI,MAAM,KAAK,YAAY;AAAA;AAAA;;;;"}
|
package/dist/node/index.cjs
CHANGED
|
@@ -2,13 +2,17 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
const paramCase = require('param-case');
|
|
6
5
|
const crypto = require('crypto');
|
|
7
6
|
|
|
7
|
+
const camelCaseToParamCase = (input) => {
|
|
8
|
+
return input.replace(/[A-Z]/g, (match) => {
|
|
9
|
+
return `-${match.toLowerCase()}`;
|
|
10
|
+
});
|
|
11
|
+
};
|
|
8
12
|
const buildURL = (url, params) => {
|
|
9
13
|
const instance = new URL(url);
|
|
10
14
|
for (const camelCasedParamKey in params) {
|
|
11
|
-
const paramKey =
|
|
15
|
+
const paramKey = camelCaseToParamCase(camelCasedParamKey);
|
|
12
16
|
const paramValue = params[camelCasedParamKey];
|
|
13
17
|
if (paramValue === void 0) {
|
|
14
18
|
instance.searchParams.delete(paramKey);
|
package/dist/node/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sources":["../../src/buildURL.ts","../../src/buildPixelDensitySrcSet.ts","../../src/node/signURL.ts","../../src/node/buildSignedURL.ts","../../src/node/buildSignedPixelDensitySrcSet.ts","../../src/node/buildSignedWidthSrcSet.ts","../../src/buildWidthSrcSet.ts","../../src/node/SecureClient.ts"],"sourcesContent":["import { paramCase } from \"param-case\";\n\nimport type { ImgixURLParams } from \"./types.generated\";\n\n/**\n * Builds a URL to an Imgix image with Imgix URL API parameters.\n *\n * The given URL must be a full absolute URL containing the protocol and domain.\n *\n * URL parameters already applied to the image will be retained. To remove\n * existing parameters, set the parameter to `undefined` in the `params` argument.\n *\n * @example\n *\n * ```ts\n * const url = buildURL(\"https://example.imgix.net/image.png\", {\n * \twidth: 400,\n * });\n * // => https://example.imgix.net/image.png?width=400\n * ```\n *\n * @example\n *\n * ```ts\n * const url = buildURL(\"https://example.imgix.net/image.png?width=400\", {\n * \theight: 300,\n * });\n * // => https://example.imgix.net/image.png?width=400&height=300\n * ```\n *\n * @param url - Full absolute URL to the Imgix image.\n * @param params - An object of Imgix URL API parameters.\n *\n * @returns `url` with the given Imgix URL API parameters applied.\n *\n * @see Imgix URL API reference: https://docs.imgix.com/apis/rendering\n */\nexport const buildURL = (url: string, params: ImgixURLParams): string => {\n\tconst instance = new URL(url);\n\n\tfor (const camelCasedParamKey in params) {\n\t\tconst paramKey = paramCase(camelCasedParamKey);\n\t\tconst paramValue = params[camelCasedParamKey as keyof typeof params];\n\n\t\tif (paramValue === undefined) {\n\t\t\tinstance.searchParams.delete(paramKey);\n\t\t} else if (Array.isArray(paramValue)) {\n\t\t\tinstance.searchParams.set(paramKey, paramValue.join(\",\"));\n\t\t} else {\n\t\t\tinstance.searchParams.set(paramKey, `${paramValue}`);\n\t\t}\n\t}\n\n\t// Ensure the `s` parameter is the last parameter, if it exists.\n\t// @see https://github.com/imgix/imgix-blueprint#securing-urls\n\tconst s = instance.searchParams.get(\"s\");\n\tif (s) {\n\t\tinstance.searchParams.delete(\"s\");\n\t\tinstance.searchParams.append(\"s\", s);\n\t}\n\n\treturn instance.toString();\n};\n","import type { ImgixURLParams } from \"./types.generated\";\nimport { buildURL } from \"./buildURL\";\n\n/**\n * Parameters for `buildPixelDensitySrcSet`.\n */\nexport type BuildPixelDensitySrcSetParams = Omit<ImgixURLParams, \"dpr\"> & {\n\t/**\n\t * The pixel densities to include in the resulting `srcset` value.\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * [1, 2, 3];\n\t * ```\n\t */\n\tpixelDensities: number[];\n};\n\n/**\n * Builds an `<img>` `srcset` attribute value for a given set of pixel\n * densities. It can also optinally apply Imgix URL API parameters to the URLs.\n *\n * The `dpr` URL parameter will be applied for each `srcset` entry. If a `dpr`\n * parameter is provided to the `params` parameter, it will be ignored.\n *\n * @example\n *\n * ```ts\n * const srcset = buildPixelDensitySrcSet(\n * \t\"https://example.imgix.net/image.png\",\n * \t{ pixelDensities: [1, 2, 3] },\n * );\n * // => https://example.imgix.net/image.png?dpr=1 1x,\n * // https://example.imgix.net/image.png?dpr=2 2x,\n * // https://example.imgix.net/image.png?dpr=3 3x\n * ```\n *\n * @example\n *\n * ```ts\n * const srcset = buildPixelDensitySrcSet(\n * \t\"https://example.imgix.net/image.png\",\n * \t{\n * \t\tpixelDensities: [1, 2, 3],\n * \t\tsat: -100,\n * \t},\n * );\n * // => https://example.imgix.net/image.png?dpr=1&sat=-100 1x,\n * // https://example.imgix.net/image.png?dpr=2&sat=-100 2x,\n * // https://example.imgix.net/image.png?dpr=3&sat=-100 3x\n * ```\n *\n * @param url - Full absolute URL to the Imgix image.\n * @param params - An object of Imgix URL API parameters. The `pixelDensities`\n * parameter defines the resulting `srcset` widths.\n *\n * @returns A `srcset` attribute value for `url` with the given Imgix URL API\n * parameters applied.\n */\nexport const buildPixelDensitySrcSet = (\n\turl: string,\n\t{ pixelDensities, ...params }: BuildPixelDensitySrcSetParams,\n): string => {\n\treturn pixelDensities\n\t\t.map((dpr) => {\n\t\t\treturn `${buildURL(url, { ...params, dpr })} ${dpr}x`;\n\t\t})\n\t\t.join(\", \");\n};\n","import { createHash } from \"crypto\";\n\n/**\n * Signs an Imgix image URL by appending a signature to the URL parameters. This\n * locks the URL and its parameters to the signature to prevent URL tampering.\n *\n * **Important**: This function should only be used in a trusted environment and\n * never in a browser. The `secureURLToken` parameter is a secret and should not\n * be exposed to the public.\n *\n * @example\n *\n * ```ts\n * const url = signURL(\n * \t\"https://example.imgix.net/image.png?width=400\",\n * \t\"example-token\",\n * );\n * // => https://example.imgix.net/image.png?width=400&s=def3e221c3f4c4debda091b8e49420ea\n * ```\n *\n * @param url - Full absolute URL to the Imgix image to sign.\n * @param secureURLToken - The secret Imgix secure URL token used to generate\n * the signature.\n *\n * @returns `url` with a signature appended via an `s` URL parameter.\n *\n * @see Details on securing Imgix images: https://docs.imgix.com/setup/securing-images\n */\nexport const signURL = (url: string, secureURLToken: string): string => {\n\tconst instance = new URL(url);\n\n\t// If an `s` param is passed explicitly, it will be overridden. It must\n\t// also not be used when generating the signature.\n\tinstance.searchParams.delete(\"s\");\n\n\t// @see https://github.com/imgix/imgix-blueprint#securing-urls\n\tconst signature = createHash(\"md5\")\n\t\t.update(secureURLToken + instance.pathname + instance.search)\n\t\t.digest(\"hex\");\n\n\tinstance.searchParams.append(\"s\", signature);\n\n\treturn instance.toString();\n};\n","import type { ImgixURLParams } from \"../types.generated\";\nimport { buildURL } from \"../buildURL\";\nimport { signURL } from \"./signURL\";\n\n/**\n * Builds a URL to an Imgix image with Imgix URL API parameters. The URL is\n * signed by appending a signature to the URL parameters. This locks the URL and\n * its parameters to the signature to prevent URL tampering.\n *\n * The given URL must be a full absolute URL containing the protocol and domain.\n *\n * URL parameters already applied to the image will be retained. To remove\n * existing parameters, set the parameter to `undefined` in the `params` argument.\n *\n * **Important**: This function should only be used in a trusted environment and\n * never in a browser. The `secureURLToken` parameter is a secret and should not\n * be exposed to the public.\n *\n * @example\n *\n * ```ts\n * const url = buildSignedURL(\n * \t\"https://example.imgix.net/image.png\",\n * \t\"example-token\",\n * \t{ width: 400 },\n * );\n * // => https://example.imgix.net/image.png?width=400&s=def3e221c3f4c4debda091b8e49420ea\n * ```\n *\n * @example\n *\n * ```ts\n * const url = buildSignedURL(\n * \t\"https://example.imgix.net/image.png?width=400\",\n * \t\"example-token\",\n * \t{ height: 300 },\n * );\n * // => https://example.imgix.net/image.png?width=400&height=300&s=f12c7c39333410c10c2930b57116a943\n * ```\n *\n * @param url - Full absolute URL to the Imgix image.\n * @param secureURLToken - The secret secure URL token for the image's Imgix source.\n * @param params - An object of Imgix URL API parameters.\n *\n * @returns `url` with the given Imgix URL API parameters applied.\n *\n * @see Imgix URL API reference: https://docs.imgix.com/apis/rendering\n * @see Details on securing Imgix images: https://docs.imgix.com/setup/securing-images\n */\nexport const buildSignedURL = (\n\turl: string,\n\tsecureURLToken: string,\n\tparams: ImgixURLParams,\n): string => {\n\treturn signURL(buildURL(url, params), secureURLToken);\n};\n","import type { BuildPixelDensitySrcSetParams } from \"../buildPixelDensitySrcSet\";\nimport { buildSignedURL } from \"./buildSignedURL\";\n\n/**\n * Builds an `<img>` `srcset` attribute value for a given set of pixel\n * densities. It can also optinally apply Imgix URL API parameters to the URLs.\n * The URLs are signed by appending a signature to their URL parameters. This\n * locks the URLs and their parameters to the signature to prevent URL tampering.\n *\n * The `dpr` URL parameter will be applied for each `srcset` entry. If a `dpr`\n * parameter is provided to the `params` parameter, it will be ignored.\n *\n * **Important**: This function should only be used in a trusted environment and\n * never in a browser. The `secureURLToken` parameter is a secret and should not\n * be exposed to the public.\n *\n * @example\n *\n * ```ts\n * const srcset = buildSignedPixelDensitySrcSet(\n * \t\"https://example.imgix.net/image.png\",\n * \t\"example-token\",\n * \t{ pixelDensities: [1, 2, 3] },\n * );\n * // => https://example.imgix.net/image.png?dpr=1&s=def3e221c3f4c4debda091b8e49420ea 1x,\n * // https://example.imgix.net/image.png?dpr=2&s=f12c7c39333410c10c2930b57116a943 2x,\n * // https://example.imgix.net/image.png?dpr=3&s=3a975b5087ab7ad2ab91fe66072fd628 3x\n * ```\n *\n * @example\n *\n * ```ts\n * const srcset = buildSignedPixelDensitySrcSet(\n * \t\"https://example.imgix.net/image.png\",\n * \t\"example-token\",\n * \t{\n * \t\tpixelDensities: [1, 2, 3],\n * \t\tsat: -100,\n * \t},\n * );\n * // => https://example.imgix.net/image.png?dpr=1&sat=-100&s=def3e221c3f4c4debda091b8e49420ea 1x,\n * // https://example.imgix.net/image.png?dpr=2&sat=-100&s=f12c7c39333410c10c2930b57116a943 2x,\n * // https://example.imgix.net/image.png?dpr=3&sat=-100&s=3a975b5087ab7ad2ab91fe66072fd628 3x\n * ```\n *\n * @param url - Full absolute URL to the Imgix image.\n * @param secureURLToken - The secret secure URL token for the image's Imgix source.\n * @param params - An object of Imgix URL API parameters. The `pixelDensities`\n * parameter defines the resulting `srcset` widths.\n *\n * @returns A `srcset` attribute value for `url` with the given Imgix URL API\n * parameters applied.\n */\nexport const buildSignedPixelDensitySrcSet = (\n\turl: string,\n\tsecureURLToken: string,\n\t{ pixelDensities, ...params }: BuildPixelDensitySrcSetParams,\n): string => {\n\treturn pixelDensities\n\t\t.map((dpr) => {\n\t\t\treturn `${buildSignedURL(url, secureURLToken, {\n\t\t\t\t...params,\n\t\t\t\tdpr,\n\t\t\t})} ${dpr}x`;\n\t\t})\n\t\t.join(\", \");\n};\n","import type { BuildWidthSrcSetParams } from \"../buildWidthSrcSet\";\nimport { buildSignedURL } from \"./buildSignedURL\";\n\n/**\n * Builds an `<img>` `srcset` attribute value for a given set of widths. It can\n * also optinally apply Imgix URL API parameters to the URLs. The URLs are\n * signed by appending a signature to their URL parameters. This locks the URLs\n * and their parameters to the signature to prevent URL tampering.\n *\n * The `width` URL parameter will be applied for each `srcset` entry. If a\n * `width` or `w` parameter is provided to the `params` parameter, it will be ignored.\n *\n * **Important**: This function should only be used in a trusted environment and\n * never in a browser. The `secureURLToken` parameter is a secret and should not\n * be exposed to the public.\n *\n * @example\n *\n * ```ts\n * const srcset = buildSignedWidthSrcSet(\n * \t\"https://example.imgix.net/image.png\",\n * \t\"example-token\",\n * \t{ widths: [400, 800, 1600] },\n * );\n * // => https://example.imgix.net/image.png?width=400&s=def3e221c3f4c4debda091b8e49420ea 400w,\n * // https://example.imgix.net/image.png?width=800&s=f12c7c39333410c10c2930b57116a943 800w,\n * // https://example.imgix.net/image.png?width=1600&s=3a975b5087ab7ad2ab91fe66072fd628 1600w\n * ```\n *\n * @example\n *\n * ```ts\n * const srcset = buildSignedWidthSrcSet(\n * \t\"https://example.imgix.net/image.png\",\n * \t\"example-token\",\n * \t{\n * \t\twidths: [400, 800, 1600],\n * \t\tsat: -100,\n * \t},\n * );\n * // => https://example.imgix.net/image.png?width=400&sat=-100&s=def3e221c3f4c4debda091b8e49420ea 400w,\n * // https://example.imgix.net/image.png?width=800&sat=-100&s=f12c7c39333410c10c2930b57116a943 800w,\n * // https://example.imgix.net/image.png?width=1600&sat=-100&s=3a975b5087ab7ad2ab91fe66072fd628 1600w\n * ```\n *\n * @param url - Full absolute URL to the Imgix image.\n * @param secureURLToken - The secret secure URL token for the image's Imgix source.\n * @param params - An object of Imgix URL API parameters. The `widths` parameter\n * defines the resulting `srcset` widths.\n *\n * @returns A `srcset` attribute value for `url` with the given Imgix URL API\n * parameters applied.\n */\nexport const buildSignedWidthSrcSet = (\n\turl: string,\n\tsecureURLToken: string,\n\t{ widths, ...params }: BuildWidthSrcSetParams,\n): string => {\n\treturn widths\n\t\t.map((width) => {\n\t\t\treturn `${buildSignedURL(url, secureURLToken, {\n\t\t\t\t...params,\n\t\t\t\tw: undefined,\n\t\t\t\twidth,\n\t\t\t})} ${width}w`;\n\t\t})\n\t\t.join(\", \");\n};\n","import type { ImgixURLParams } from \"./types.generated\";\nimport { buildURL } from \"./buildURL\";\n\n/**\n * Parameters for `buildWidthSrcSet`.\n */\nexport type BuildWidthSrcSetParams = Omit<ImgixURLParams, \"width\" | \"w\"> & {\n\t/**\n\t * The pixel widths to include in the resulting `srcset` value.\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * [400, 800, 1600];\n\t * ```\n\t */\n\twidths: number[];\n};\n\n/**\n * Builds an `<img>` `srcset` attribute value for a given set of widths. It can\n * also optinally apply Imgix URL API parameters to the URLs.\n *\n * The `width` URL parameter will be applied for each `srcset` entry. If a\n * `width` or `w` parameter is provided to the `params` parameter, it will be ignored.\n *\n * @example\n *\n * ```ts\n * const srcset = buildWidthSrcSet(\"https://example.imgix.net/image.png\", {\n * \twidths: [400, 800, 1600],\n * });\n * // => https://example.imgix.net/image.png?width=400 400w,\n * // https://example.imgix.net/image.png?width=800 800w,\n * // https://example.imgix.net/image.png?width=1600 1600w\n * ```\n *\n * @example\n *\n * ```ts\n * const srcset = buildWidthSrcSet(\"https://example.imgix.net/image.png\", {\n * \twidths: [400, 800, 1600],\n * \tsat: -100,\n * });\n * // => https://example.imgix.net/image.png?width=400&sat=-100 400w,\n * // https://example.imgix.net/image.png?width=800&sat=-100 800w,\n * // https://example.imgix.net/image.png?width=1600&sat=-100 1600w\n * ```\n *\n * @param url - Full absolute URL to the Imgix image.\n * @param params - An object of Imgix URL API parameters. The `widths` parameter\n * defines the resulting `srcset` widths.\n *\n * @returns A `srcset` attribute value for `url` with the given Imgix URL API\n * parameters applied.\n */\nexport const buildWidthSrcSet = (\n\turl: string,\n\t{ widths, ...params }: BuildWidthSrcSetParams,\n): string => {\n\treturn widths\n\t\t.map((width) => {\n\t\t\treturn `${buildURL(url, { ...params, w: undefined, width })} ${width}w`;\n\t\t})\n\t\t.join(\", \");\n};\n","import type { BuildPixelDensitySrcSetParams } from \"../buildPixelDensitySrcSet\";\nimport type { BuildWidthSrcSetParams } from \"../buildWidthSrcSet\";\nimport type { ImgixURLParams } from \"../types.generated\";\nimport { buildPixelDensitySrcSet } from \"../buildPixelDensitySrcSet\";\nimport { buildSignedPixelDensitySrcSet } from \"./buildSignedPixelDensitySrcSet\";\nimport { buildSignedURL } from \"./buildSignedURL\";\nimport { buildSignedWidthSrcSet } from \"./buildSignedWidthSrcSet\";\nimport { buildURL } from \"../buildURL\";\nimport { buildWidthSrcSet } from \"../buildWidthSrcSet\";\nimport { signURL } from \"./signURL\";\n\n/**\n * Options to instantiate a new secure client.\n */\nexport type SecureClientOptions = {\n\t/**\n\t * The base URL used to construct image URLs from a path. The base URL must\n\t * include the protocol, domain, and optionally a path.\n\t *\n\t * @example `https://example.imgix.net`\n\t *\n\t * @example `https://example.imgix.net/folder`\n\t */\n\tbaseURL: string;\n\n\t/**\n\t * The secret secure URL token for the configured Imgix domain.\n\t *\n\t * @see How to get a token: https://docs.imgix.com/setup/securing-images\n\t */\n\tsecureURLToken: string;\n};\n\n/**\n * An Imgix Rendering API client with automatic URL signing. A client is paired\n * to a single Imgix domain and secure URL token.\n *\n * **Important**: This client should only be used in a trusted environment and\n * never in a browser. The `secureURLToken` parameter is a secret and should not\n * be exposed to the public.\n */\nexport class SecureClient {\n\t/**\n\t * The base URL used to construct image URLs from a path. The base URL must\n\t * include the protocol, domain, and optionally a path.\n\t */\n\tbaseURL: string;\n\n\t/**\n\t * The secret secure URL token for the configured Imgix domain.\n\t */\n\tsecureURLToken: string;\n\n\t/**\n\t * Creates a new `SecureClient` instance for an Imgix domain.\n\t *\n\t * @param options - Options to instantiate a new client.\n\t *\n\t * @returns A `SecureClient` instance for the given Imgix domain.\n\t */\n\tconstructor(options: SecureClientOptions) {\n\t\tthis.baseURL = options.baseURL;\n\t\tthis.secureURLToken = options.secureURLToken;\n\t}\n\n\t/**\n\t * Builds a Web Proxy URL that proxies a non-Imgix URL to Imgix. The client's\n\t * Imgix domain must be configured as a Web Proxy source. All Web Proxy URLs\n\t * will be signed automatically.\n\t *\n\t * **Important**: The given URL must not be URI encoded. If it is, decode it\n\t * before passing it to `buildWebProxyURL()`.\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * const client = new SecureClient({\n\t * \tbaseURL: \"https://example.imgix.net\",\n\t * \tsecureURLToken: \"example-token\",\n\t * });\n\t * const url = client.buildWebProxyURL(\"https://www.this.com/pic.jpg\", {\n\t * \twidth: 400,\n\t * });\n\t * // => https://example.imgix.net/https%3A%2F%2Fwww.this.com%2Fpic.jpg?width=400&s=def3e221c3f4c4debda091b8e49420ea\n\t * ```\n\t *\n\t * @param url - Full absolute URL to the source image to proxy.\n\t * @param params - An object of Imgix URL API parameters.\n\t *\n\t * @returns An Imgix url proxying `url` to the client's Imgix domain.\n\t */\n\tbuildWebProxyURL(url: string, params: ImgixURLParams = {}): string {\n\t\treturn this.buildSignedURLForPath(encodeURIComponent(url), params);\n\t}\n\n\t/**\n\t * Builds a URL to an Imgix image with Imgix URL API parameters for the\n\t * client's base URL.\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * const client = new SecureClient({\n\t * \tbaseURL: \"https://example.imgix.net\",\n\t * \tsecureURLToken: \"example-token\",\n\t * });\n\t * const url = client.buildURLForPath(\"/image.png\", { width: 400 });\n\t * // => https://example.imgix.net/image.png?width=400&s=def3e221c3f4c4debda091b8e49420ea\n\t * ```\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * const client = new SecureClient({\n\t * \tbaseURL: \"https://example.imgix.net/folder\",\n\t * \tsecureURLToken: \"example-token\",\n\t * });\n\t * const url = client.buildURLForPath(\"./image.png\", { width: 400 });\n\t * // => https://example.imgix.net/folder/image.png?width=400&s=f12c7c39333410c10c2930b57116a943\n\t * ```\n\t *\n\t * @param path - Path to the image relative to the client's base URL.\n\t * @param params - An object of Imgix URL API parameters.\n\t *\n\t * @returns The full absolute URL to the image with the given Imgix URL API\n\t * parameters applied.\n\t */\n\tbuildSignedURLForPath(path: string, params: ImgixURLParams = {}): string {\n\t\treturn this.signURL(this.buildURLForPath(path, params));\n\t}\n\n\t/**\n\t * Builds a URL to an Imgix image with Imgix URL API parameters for the\n\t * client's base URL.\n\t *\n\t * Note: The returned URL is not signed. See `buildSignedURL` if a signature\n\t * is required.\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * const client = new SecureClient({\n\t * \tbaseURL: \"https://example.imgix.net\",\n\t * \tsecureURLToken: \"example-token\",\n\t * });\n\t * const url = client.buildURLForPath(\"/image.png\", { width: 400 });\n\t * // => https://example.imgix.net/image.png?width=400\n\t * ```\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * const client = new SecureClient({\n\t * \tbaseURL: \"https://example.imgix.net/folder\",\n\t * \tsecureURLToken: \"example-token\",\n\t * });\n\t * const url = client.buildURLForPath(\"./image.png\", { width: 400 });\n\t * // => https://example.imgix.net/folder/image.png?width=400\n\t * ```\n\t *\n\t * @param path - Path to the image relative to the client's base URL.\n\t * @param params - An object of Imgix URL API parameters.\n\t *\n\t * @returns The full absolute URL to the image with the given Imgix URL API\n\t * parameters applied.\n\t */\n\tbuildURLForPath(path: string, params: ImgixURLParams = {}): string {\n\t\treturn buildURL(`${new URL(path, this.baseURL)}`, params);\n\t}\n\n\t/**\n\t * Builds a URL to an Imgix image with Imgix URL API parameters. The URL is\n\t * signed by appending a signature to the URL parameters. This locks the URL\n\t * and its parameters to the signature to prevent URL tampering.\n\t *\n\t * The given URL must be a full absolute URL containing the protocol and domain.\n\t *\n\t * URL parameters already applied to the image will be retained. To remove\n\t * existing parameters, set the parameter to `undefined` in the `params` argument.\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * const url = client.buildSignedURL(\n\t * \t\"https://example.imgix.net/image.png\",\n\t * \t{ width: 400 },\n\t * );\n\t * // => https://example.imgix.net/image.png?width=400&s=def3e221c3f4c4debda091b8e49420ea\n\t * ```\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * const url = client.buildSignedURL(\n\t * \t\"https://example.imgix.net/image.png?width=400\",\n\t * \t{ height: 300 },\n\t * );\n\t * // => https://example.imgix.net/image.png?width=400&height=300&s=f12c7c39333410c10c2930b57116a943\n\t * ```\n\t *\n\t * @param url - Full absolute URL to the Imgix image.\n\t * @param params - An object of Imgix URL API parameters.\n\t *\n\t * @returns `url` with the given Imgix URL API parameters applied.\n\t *\n\t * @see Imgix URL API reference: https://docs.imgix.com/apis/rendering\n\t * @see Details on securing Imgix images: https://docs.imgix.com/setup/securing-images\n\t */\n\tbuildSignedURL(url: string, params: ImgixURLParams = {}): string {\n\t\treturn buildSignedURL(url, this.secureURLToken, params);\n\t}\n\n\t/**\n\t * Signs an Imgix image URL by appending a signature to the URL parameters.\n\t * This locks the URL and its parameters to the signature to prevent URL tampering.\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * const url = client.signURL(\n\t * \t\"https://example.imgix.net/image.png?width=400\",\n\t * );\n\t * // => https://example.imgix.net/image.png?width=400&s=def3e221c3f4c4debda091b8e49420ea\n\t * ```\n\t *\n\t * @param url - Full absolute URL to the Imgix image to sign.\n\t *\n\t * @returns `url` with a signature appended via an `s` URL parameter.\n\t *\n\t * @see Details on securing Imgix images: https://docs.imgix.com/setup/securing-images\n\t */\n\tsignURL(url: string): string {\n\t\treturn signURL(url, this.secureURLToken);\n\t}\n\n\t/**\n\t * Builds an `<img>` `srcset` attribute value for a given set of widths. It\n\t * can also optinally apply Imgix URL API parameters to the URLs. The URLs are\n\t * signed by appending a signature to their URL parameters. This locks the\n\t * URLs and their parameters to the signature to prevent URL tampering.\n\t *\n\t * The `width` URL parameter will be applied for each `srcset` entry. If a\n\t * `width` or `w` parameter is provided to the `params` parameter, it will be ignored.\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * const srcset = client.buildSignedWidthSrcSet(\n\t * \t\"https://example.imgix.net/image.png\",\n\t * \t{ widths: [400, 800, 1600] },\n\t * );\n\t * // => https://example.imgix.net/image.png?width=400&s=def3e221c3f4c4debda091b8e49420ea 400w,\n\t * // https://example.imgix.net/image.png?width=800&s=f12c7c39333410c10c2930b57116a943 800w,\n\t * // https://example.imgix.net/image.png?width=1600&s=3a975b5087ab7ad2ab91fe66072fd628 1600w\n\t * ```\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * const srcset = client.buildSignedWidthSrcSet(\n\t * \t\"https://example.imgix.net/image.png\",\n\t * \t{\n\t * \t\twidths: [400, 800, 1600],\n\t * \t\tsat: -100,\n\t * \t},\n\t * );\n\t * // => https://example.imgix.net/image.png?width=400&sat=-100&s=def3e221c3f4c4debda091b8e49420ea 400w,\n\t * // https://example.imgix.net/image.png?width=800&sat=-100&s=f12c7c39333410c10c2930b57116a943 800w,\n\t * // https://example.imgix.net/image.png?width=1600&sat=-100&s=3a975b5087ab7ad2ab91fe66072fd628 1600w\n\t * ```\n\t *\n\t * @param url - Full absolute URL to the Imgix image.\n\t * @param params - An object of Imgix URL API parameters. The `widths`\n\t * parameter defines the resulting `srcset` widths.\n\t *\n\t * @returns A `srcset` attribute value for `url` with the given Imgix URL API\n\t * parameters applied.\n\t */\n\tbuildSignedWidthSrcSet(url: string, params: BuildWidthSrcSetParams): string {\n\t\treturn buildSignedWidthSrcSet(url, this.secureURLToken, params);\n\t}\n\n\t/**\n\t * Builds an `<img>` `srcset` attribute value for a given set of widths for\n\t * the client's base URL. It can also optinally apply Imgix URL API parameters\n\t * to the URLs.\n\t *\n\t * The `width` URL parameter will be applied for each `srcset` entry. If a\n\t * `width` or `w` parameter is provided to the `params` parameter, it will be ignored.\n\t *\n\t * Note: The returned URLs are not signed. See `buildSignedWidthSrcSet` if\n\t * signatures are required.\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * const client = new SecureClient({\n\t * \tbaseURL: \"https://example.imgix.net\",\n\t * \tsecureURLToken: \"example-token\",\n\t * });\n\t * const srcset = client.buildWidthSrcSetForPath(\"/image.png\", {\n\t * \twidths: [400, 800, 1600],\n\t * });\n\t * // => https://example.imgix.net/image.png?width=400 400w,\n\t * // https://example.imgix.net/image.png?width=800 800w,\n\t * // https://example.imgix.net/image.png?width=1600 1600w\n\t * ```\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * const client = new SecureClient({\n\t * \tbaseURL: \"https://example.imgix.net\",\n\t * \tsecureURLToken: \"example-token\",\n\t * });\n\t * const srcset = client.buildWidthSrcSetForPath(\"/image.png\", {\n\t * \twidths: [400, 800, 1600],\n\t * \tsat: -100,\n\t * });\n\t * // => https://example.imgix.net/image.png?width=400&sat=-100 400w,\n\t * // https://example.imgix.net/image.png?width=800&sat=-100 800w,\n\t * // https://example.imgix.net/image.png?width=1600&sat=-100 1600w\n\t * ```\n\t *\n\t * @param path - Path to the image relative to the client's base URL.\n\t * @param params - An object of Imgix URL API parameters. The `widths`\n\t * parameter defines the resulting `srcset` widths.\n\t *\n\t * @returns A `srcset` attribute value for `url` with the given Imgix URL API\n\t * parameters applied.\n\t */\n\tbuildWidthSrcSetForPath(\n\t\tpath: string,\n\t\tparams: BuildWidthSrcSetParams,\n\t): string {\n\t\treturn buildWidthSrcSet(`${new URL(path, this.baseURL)}`, params);\n\t}\n\n\t/**\n\t * Builds an `<img>` `srcset` attribute value for a given set of widths for\n\t * the client's base URL. It can also optinally apply Imgix URL API parameters\n\t * to the URLs. The URLs are signed by appending a signature to their URL\n\t * parameters. This locks the URLs and their parameters to the signature to\n\t * prevent URL tampering.\n\t *\n\t * The `width` URL parameter will be applied for each `srcset` entry. If a\n\t * `width` or `w` parameter is provided to the `params` parameter, it will be ignored.\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * const client = new SecureClient({\n\t * \tbaseURL: \"https://example.imgix.net\",\n\t * \tsecureURLToken: \"example-token\",\n\t * });\n\t * const srcset = client.buildSignedWidthSrcSetForPath(\"/image.png\", {\n\t * \twidths: [400, 800, 1600],\n\t * });\n\t * // => https://example.imgix.net/image.png?width=400&s=def3e221c3f4c4debda091b8e49420ea 400w,\n\t * // https://example.imgix.net/image.png?width=800&s=f12c7c39333410c10c2930b57116a943 800w,\n\t * // https://example.imgix.net/image.png?width=1600&s=3a975b5087ab7ad2ab91fe66072fd628 1600w\n\t * ```\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * const client = new SecureClient({\n\t * \tbaseURL: \"https://example.imgix.net\",\n\t * \tsecureURLToken: \"example-token\",\n\t * });\n\t * const srcset = client.buildSignedWidthSrcSetForPath(\"/image.png\", {\n\t * \twidths: [400, 800, 1600],\n\t * \tsat: -100,\n\t * });\n\t * // => https://example.imgix.net/image.png?width=400&sat=-100&s=def3e221c3f4c4debda091b8e49420ea 400w,\n\t * // https://example.imgix.net/image.png?width=800&sat=-100&s=f12c7c39333410c10c2930b57116a943 800w,\n\t * // https://example.imgix.net/image.png?width=1600&sat=-100&s=3a975b5087ab7ad2ab91fe66072fd628 1600w\n\t * ```\n\t *\n\t * @param path - Path to the image relative to the client's base URL.\n\t * @param params - An object of Imgix URL API parameters. The `widths`\n\t * parameter defines the resulting `srcset` widths.\n\t *\n\t * @returns A `srcset` attribute value for `url` with the given Imgix URL API\n\t * parameters applied.\n\t */\n\tbuildSignedWidthSrcSetForPath(\n\t\tpath: string,\n\t\tparams: BuildWidthSrcSetParams,\n\t): string {\n\t\treturn this.buildSignedWidthSrcSet(\n\t\t\t`${new URL(path, this.baseURL)}`,\n\t\t\tparams,\n\t\t);\n\t}\n\n\t/**\n\t * Builds an `<img>` `srcset` attribute value for a given set of pixel\n\t * densities. It can also optinally apply Imgix URL API parameters to the\n\t * URLs. The URLs are signed by appending a signature to their URL parameters.\n\t * This locks the URLs and their parameters to the signature to prevent URL tampering.\n\t *\n\t * The `dpr` URL parameter will be applied for each `srcset` entry. If a `dpr`\n\t * parameter is provided to the `params` parameter, it will be ignored.\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * const srcset = client.buildSignedPixelDensitySrcSet(\n\t * \t\"https://example.imgix.net/image.png\",\n\t * \t{ pixelDensities: [1, 2, 3] },\n\t * );\n\t * // => https://example.imgix.net/image.png?dpr=1&s=def3e221c3f4c4debda091b8e49420ea 1x,\n\t * // https://example.imgix.net/image.png?dpr=2&s=f12c7c39333410c10c2930b57116a943 2x,\n\t * // https://example.imgix.net/image.png?dpr=3&s=3a975b5087ab7ad2ab91fe66072fd628 3x\n\t * ```\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * const srcset = client.buildSignedPixelDensitySrcSet(\n\t * \t\"https://example.imgix.net/image.png\",\n\t * \t{\n\t * \t\tpixelDensities: [1, 2, 3],\n\t * \t\tsat: -100,\n\t * \t},\n\t * );\n\t * // => https://example.imgix.net/image.png?dpr=1&sat=-100&s=def3e221c3f4c4debda091b8e49420ea 1x,\n\t * // https://example.imgix.net/image.png?dpr=2&sat=-100&s=f12c7c39333410c10c2930b57116a943 2x,\n\t * // https://example.imgix.net/image.png?dpr=3&sat=-100&s=3a975b5087ab7ad2ab91fe66072fd628 3x\n\t * ```\n\t *\n\t * @param url - Full absolute URL to the Imgix image.\n\t * @param params - An object of Imgix URL API parameters. The `pixelDensities`\n\t * parameter defines the resulting `srcset` widths.\n\t *\n\t * @returns A `srcset` attribute value for `url` with the given Imgix URL API\n\t * parameters applied.\n\t */\n\tbuildSignedPixelDensitySrcSet(\n\t\turl: string,\n\t\tparams: BuildPixelDensitySrcSetParams,\n\t): string {\n\t\treturn buildSignedPixelDensitySrcSet(url, this.secureURLToken, params);\n\t}\n\n\t/**\n\t * Builds an `<img>` `srcset` attribute value for a given set of pixel\n\t * densities for the client's base URL. It can also optinally apply Imgix URL\n\t * API parameters to the URLs.\n\t *\n\t * The `dpr` URL parameter will be applied for each `srcset` entry. If a `dpr`\n\t * parameter is provided to the `params` parameter, it will be ignored.\n\t *\n\t * Note: The returned URLs are not signed. See `buildSignedPixelDensitySrcSet`\n\t * if signatures are required.\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * const client = new SecureClient({\n\t * \tbaseURL: \"https://example.imgix.net\",\n\t * \tsecureURLToken: \"example-token\",\n\t * });\n\t * const srcset = client.buildPixelDensitySrcSetForPath(\"/image.png\", {\n\t * \tpixelDensities: [1, 2, 3],\n\t * });\n\t * // => https://example.imgix.net/image.png?dpr=1 1x,\n\t * // https://example.imgix.net/image.png?dpr=2 2x,\n\t * // https://example.imgix.net/image.png?dpr=3 3x\n\t * ```\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * const client = new SecureClient({\n\t * \tbaseURL: \"https://example.imgix.net\",\n\t * \tsecureURLToken: \"example-token\",\n\t * });\n\t * const srcset = client.buildPixelDensitySrcSetForPath(\"/image.png\", {\n\t * \tpixelDensities: [1, 2, 3],\n\t * \tsat: -100,\n\t * });\n\t * // => https://example.imgix.net/image.png?dpr=1&sat=-100 1x,\n\t * // https://example.imgix.net/image.png?dpr=2&sat=-100 2x,\n\t * // https://example.imgix.net/image.png?dpr=3&sat=-100 3x\n\t * ```\n\t *\n\t * @param path - Path to the image relative to the client's base URL.\n\t * @param params - An object of Imgix URL API parameters. The `pixelDensities`\n\t * parameter defines the resulting `srcset` widths.\n\t *\n\t * @returns A `srcset` attribute value for `url` with the given Imgix URL API\n\t * parameters applied.\n\t */\n\tbuildPixelDensitySrcSetForPath(\n\t\tpath: string,\n\t\tparams: BuildPixelDensitySrcSetParams,\n\t): string {\n\t\treturn buildPixelDensitySrcSet(`${new URL(path, this.baseURL)}`, params);\n\t}\n\n\t/**\n\t * Builds an `<img>` `srcset` attribute value for a given set of pixel\n\t * densities for the client's base URL. It can also optinally apply Imgix URL\n\t * API parameters to the URLs. The URLs are signed by appending a signature to\n\t * their URL parameters. This locks the URLs and their parameters to the\n\t * signature to prevent URL tampering.\n\t *\n\t * The `dpr` URL parameter will be applied for each `srcset` entry. If a `dpr`\n\t * parameter is provided to the `params` parameter, it will be ignored.\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * const client = new SecureClient({\n\t * \tbaseURL: \"https://example.imgix.net\",\n\t * \tsecureURLToken: \"example-token\",\n\t * });\n\t * const srcset = client.buildSignedPixelDensitySrcSetForPath(\n\t * \t\"/image.png\",\n\t * \t{ pixelDensities: [1, 2, 3] },\n\t * );\n\t * // => https://example.imgix.net/image.png?dpr=1&s=def3e221c3f4c4debda091b8e49420ea 1x,\n\t * // https://example.imgix.net/image.png?dpr=2&s=f12c7c39333410c10c2930b57116a943 2x,\n\t * // https://example.imgix.net/image.png?dpr=3&s=3a975b5087ab7ad2ab91fe66072fd628 3x\n\t * ```\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * const client = new SecureClient({\n\t * \tbaseURL: \"https://example.imgix.net\",\n\t * \tsecureURLToken: \"example-token\",\n\t * });\n\t * const srcset = client.buildSignedPixelDensitySrcSetForPath(\n\t * \t\"/image.png\",\n\t * \t{\n\t * \t\tpixelDensities: [1, 2, 3],\n\t * \t\tsat: -100,\n\t * \t},\n\t * );\n\t * // => https://example.imgix.net/image.png?dpr=1&sat=-100&s=def3e221c3f4c4debda091b8e49420ea 1x,\n\t * // https://example.imgix.net/image.png?dpr=2&sat=-100&s=f12c7c39333410c10c2930b57116a943 2x,\n\t * // https://example.imgix.net/image.png?dpr=3&sat=-100&s=3a975b5087ab7ad2ab91fe66072fd628 3x\n\t * ```\n\t *\n\t * @param path - Path to the image relative to the client's base URL.\n\t * @param params - An object of Imgix URL API parameters. The `pixelDensities`\n\t * parameter defines the resulting `srcset` widths.\n\t *\n\t * @returns A `srcset` attribute value for `url` with the given Imgix URL API\n\t * parameters applied.\n\t */\n\tbuildSignedPixelDensitySrcSetForPath(\n\t\tpath: string,\n\t\tparams: BuildPixelDensitySrcSetParams,\n\t): string {\n\t\treturn buildSignedPixelDensitySrcSet(\n\t\t\t`${new URL(path, this.baseURL)}`,\n\t\t\tthis.secureURLToken,\n\t\t\tparams,\n\t\t);\n\t}\n}\n"],"names":["paramCase","createHash"],"mappings":"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"}
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":["../../src/buildURL.ts","../../src/buildPixelDensitySrcSet.ts","../../src/node/signURL.ts","../../src/node/buildSignedURL.ts","../../src/node/buildSignedPixelDensitySrcSet.ts","../../src/node/buildSignedWidthSrcSet.ts","../../src/buildWidthSrcSet.ts","../../src/node/SecureClient.ts"],"sourcesContent":["import type { ImgixURLParams } from \"./types.generated\";\n\n/**\n * Converts a camel case string to a param case string.\n *\n * @example\n *\n * ```ts\n * camelCaseToParamCase(\"fooBar\");\n * // => 'foo-bar'\n * ```\n *\n * @param input - Camel case string to convert.\n *\n * @returns Param case version of `input`.\n */\nconst camelCaseToParamCase = (input: string): string => {\n\treturn input.replace(/[A-Z]/g, (match) => {\n\t\treturn `-${match.toLowerCase()}`;\n\t});\n};\n\n/**\n * Builds a URL to an Imgix image with Imgix URL API parameters.\n *\n * The given URL must be a full absolute URL containing the protocol and domain.\n *\n * URL parameters already applied to the image will be retained. To remove\n * existing parameters, set the parameter to `undefined` in the `params` argument.\n *\n * @example\n *\n * ```ts\n * const url = buildURL(\"https://example.imgix.net/image.png\", {\n * \twidth: 400,\n * });\n * // => https://example.imgix.net/image.png?width=400\n * ```\n *\n * @example\n *\n * ```ts\n * const url = buildURL(\"https://example.imgix.net/image.png?width=400\", {\n * \theight: 300,\n * });\n * // => https://example.imgix.net/image.png?width=400&height=300\n * ```\n *\n * @param url - Full absolute URL to the Imgix image.\n * @param params - An object of Imgix URL API parameters.\n *\n * @returns `url` with the given Imgix URL API parameters applied.\n *\n * @see Imgix URL API reference: https://docs.imgix.com/apis/rendering\n */\nexport const buildURL = (url: string, params: ImgixURLParams): string => {\n\tconst instance = new URL(url);\n\n\tfor (const camelCasedParamKey in params) {\n\t\tconst paramKey = camelCaseToParamCase(camelCasedParamKey);\n\t\tconst paramValue = params[camelCasedParamKey as keyof typeof params];\n\n\t\tif (paramValue === undefined) {\n\t\t\tinstance.searchParams.delete(paramKey);\n\t\t} else if (Array.isArray(paramValue)) {\n\t\t\tinstance.searchParams.set(paramKey, paramValue.join(\",\"));\n\t\t} else {\n\t\t\tinstance.searchParams.set(paramKey, `${paramValue}`);\n\t\t}\n\t}\n\n\t// Ensure the `s` parameter is the last parameter, if it exists.\n\t// @see https://github.com/imgix/imgix-blueprint#securing-urls\n\tconst s = instance.searchParams.get(\"s\");\n\tif (s) {\n\t\tinstance.searchParams.delete(\"s\");\n\t\tinstance.searchParams.append(\"s\", s);\n\t}\n\n\treturn instance.toString();\n};\n","import type { ImgixURLParams } from \"./types.generated\";\nimport { buildURL } from \"./buildURL\";\n\n/**\n * Parameters for `buildPixelDensitySrcSet`.\n */\nexport type BuildPixelDensitySrcSetParams = Omit<ImgixURLParams, \"dpr\"> & {\n\t/**\n\t * The pixel densities to include in the resulting `srcset` value.\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * [1, 2, 3];\n\t * ```\n\t */\n\tpixelDensities: number[];\n};\n\n/**\n * Builds an `<img>` `srcset` attribute value for a given set of pixel\n * densities. It can also optinally apply Imgix URL API parameters to the URLs.\n *\n * The `dpr` URL parameter will be applied for each `srcset` entry. If a `dpr`\n * parameter is provided to the `params` parameter, it will be ignored.\n *\n * @example\n *\n * ```ts\n * const srcset = buildPixelDensitySrcSet(\n * \t\"https://example.imgix.net/image.png\",\n * \t{ pixelDensities: [1, 2, 3] },\n * );\n * // => https://example.imgix.net/image.png?dpr=1 1x,\n * // https://example.imgix.net/image.png?dpr=2 2x,\n * // https://example.imgix.net/image.png?dpr=3 3x\n * ```\n *\n * @example\n *\n * ```ts\n * const srcset = buildPixelDensitySrcSet(\n * \t\"https://example.imgix.net/image.png\",\n * \t{\n * \t\tpixelDensities: [1, 2, 3],\n * \t\tsat: -100,\n * \t},\n * );\n * // => https://example.imgix.net/image.png?dpr=1&sat=-100 1x,\n * // https://example.imgix.net/image.png?dpr=2&sat=-100 2x,\n * // https://example.imgix.net/image.png?dpr=3&sat=-100 3x\n * ```\n *\n * @param url - Full absolute URL to the Imgix image.\n * @param params - An object of Imgix URL API parameters. The `pixelDensities`\n * parameter defines the resulting `srcset` widths.\n *\n * @returns A `srcset` attribute value for `url` with the given Imgix URL API\n * parameters applied.\n */\nexport const buildPixelDensitySrcSet = (\n\turl: string,\n\t{ pixelDensities, ...params }: BuildPixelDensitySrcSetParams,\n): string => {\n\treturn pixelDensities\n\t\t.map((dpr) => {\n\t\t\treturn `${buildURL(url, { ...params, dpr })} ${dpr}x`;\n\t\t})\n\t\t.join(\", \");\n};\n","import { createHash } from \"crypto\";\n\n/**\n * Signs an Imgix image URL by appending a signature to the URL parameters. This\n * locks the URL and its parameters to the signature to prevent URL tampering.\n *\n * **Important**: This function should only be used in a trusted environment and\n * never in a browser. The `secureURLToken` parameter is a secret and should not\n * be exposed to the public.\n *\n * @example\n *\n * ```ts\n * const url = signURL(\n * \t\"https://example.imgix.net/image.png?width=400\",\n * \t\"example-token\",\n * );\n * // => https://example.imgix.net/image.png?width=400&s=def3e221c3f4c4debda091b8e49420ea\n * ```\n *\n * @param url - Full absolute URL to the Imgix image to sign.\n * @param secureURLToken - The secret Imgix secure URL token used to generate\n * the signature.\n *\n * @returns `url` with a signature appended via an `s` URL parameter.\n *\n * @see Details on securing Imgix images: https://docs.imgix.com/setup/securing-images\n */\nexport const signURL = (url: string, secureURLToken: string): string => {\n\tconst instance = new URL(url);\n\n\t// If an `s` param is passed explicitly, it will be overridden. It must\n\t// also not be used when generating the signature.\n\tinstance.searchParams.delete(\"s\");\n\n\t// @see https://github.com/imgix/imgix-blueprint#securing-urls\n\tconst signature = createHash(\"md5\")\n\t\t.update(secureURLToken + instance.pathname + instance.search)\n\t\t.digest(\"hex\");\n\n\tinstance.searchParams.append(\"s\", signature);\n\n\treturn instance.toString();\n};\n","import type { ImgixURLParams } from \"../types.generated\";\nimport { buildURL } from \"../buildURL\";\nimport { signURL } from \"./signURL\";\n\n/**\n * Builds a URL to an Imgix image with Imgix URL API parameters. The URL is\n * signed by appending a signature to the URL parameters. This locks the URL and\n * its parameters to the signature to prevent URL tampering.\n *\n * The given URL must be a full absolute URL containing the protocol and domain.\n *\n * URL parameters already applied to the image will be retained. To remove\n * existing parameters, set the parameter to `undefined` in the `params` argument.\n *\n * **Important**: This function should only be used in a trusted environment and\n * never in a browser. The `secureURLToken` parameter is a secret and should not\n * be exposed to the public.\n *\n * @example\n *\n * ```ts\n * const url = buildSignedURL(\n * \t\"https://example.imgix.net/image.png\",\n * \t\"example-token\",\n * \t{ width: 400 },\n * );\n * // => https://example.imgix.net/image.png?width=400&s=def3e221c3f4c4debda091b8e49420ea\n * ```\n *\n * @example\n *\n * ```ts\n * const url = buildSignedURL(\n * \t\"https://example.imgix.net/image.png?width=400\",\n * \t\"example-token\",\n * \t{ height: 300 },\n * );\n * // => https://example.imgix.net/image.png?width=400&height=300&s=f12c7c39333410c10c2930b57116a943\n * ```\n *\n * @param url - Full absolute URL to the Imgix image.\n * @param secureURLToken - The secret secure URL token for the image's Imgix source.\n * @param params - An object of Imgix URL API parameters.\n *\n * @returns `url` with the given Imgix URL API parameters applied.\n *\n * @see Imgix URL API reference: https://docs.imgix.com/apis/rendering\n * @see Details on securing Imgix images: https://docs.imgix.com/setup/securing-images\n */\nexport const buildSignedURL = (\n\turl: string,\n\tsecureURLToken: string,\n\tparams: ImgixURLParams,\n): string => {\n\treturn signURL(buildURL(url, params), secureURLToken);\n};\n","import type { BuildPixelDensitySrcSetParams } from \"../buildPixelDensitySrcSet\";\nimport { buildSignedURL } from \"./buildSignedURL\";\n\n/**\n * Builds an `<img>` `srcset` attribute value for a given set of pixel\n * densities. It can also optinally apply Imgix URL API parameters to the URLs.\n * The URLs are signed by appending a signature to their URL parameters. This\n * locks the URLs and their parameters to the signature to prevent URL tampering.\n *\n * The `dpr` URL parameter will be applied for each `srcset` entry. If a `dpr`\n * parameter is provided to the `params` parameter, it will be ignored.\n *\n * **Important**: This function should only be used in a trusted environment and\n * never in a browser. The `secureURLToken` parameter is a secret and should not\n * be exposed to the public.\n *\n * @example\n *\n * ```ts\n * const srcset = buildSignedPixelDensitySrcSet(\n * \t\"https://example.imgix.net/image.png\",\n * \t\"example-token\",\n * \t{ pixelDensities: [1, 2, 3] },\n * );\n * // => https://example.imgix.net/image.png?dpr=1&s=def3e221c3f4c4debda091b8e49420ea 1x,\n * // https://example.imgix.net/image.png?dpr=2&s=f12c7c39333410c10c2930b57116a943 2x,\n * // https://example.imgix.net/image.png?dpr=3&s=3a975b5087ab7ad2ab91fe66072fd628 3x\n * ```\n *\n * @example\n *\n * ```ts\n * const srcset = buildSignedPixelDensitySrcSet(\n * \t\"https://example.imgix.net/image.png\",\n * \t\"example-token\",\n * \t{\n * \t\tpixelDensities: [1, 2, 3],\n * \t\tsat: -100,\n * \t},\n * );\n * // => https://example.imgix.net/image.png?dpr=1&sat=-100&s=def3e221c3f4c4debda091b8e49420ea 1x,\n * // https://example.imgix.net/image.png?dpr=2&sat=-100&s=f12c7c39333410c10c2930b57116a943 2x,\n * // https://example.imgix.net/image.png?dpr=3&sat=-100&s=3a975b5087ab7ad2ab91fe66072fd628 3x\n * ```\n *\n * @param url - Full absolute URL to the Imgix image.\n * @param secureURLToken - The secret secure URL token for the image's Imgix source.\n * @param params - An object of Imgix URL API parameters. The `pixelDensities`\n * parameter defines the resulting `srcset` widths.\n *\n * @returns A `srcset` attribute value for `url` with the given Imgix URL API\n * parameters applied.\n */\nexport const buildSignedPixelDensitySrcSet = (\n\turl: string,\n\tsecureURLToken: string,\n\t{ pixelDensities, ...params }: BuildPixelDensitySrcSetParams,\n): string => {\n\treturn pixelDensities\n\t\t.map((dpr) => {\n\t\t\treturn `${buildSignedURL(url, secureURLToken, {\n\t\t\t\t...params,\n\t\t\t\tdpr,\n\t\t\t})} ${dpr}x`;\n\t\t})\n\t\t.join(\", \");\n};\n","import type { BuildWidthSrcSetParams } from \"../buildWidthSrcSet\";\nimport { buildSignedURL } from \"./buildSignedURL\";\n\n/**\n * Builds an `<img>` `srcset` attribute value for a given set of widths. It can\n * also optinally apply Imgix URL API parameters to the URLs. The URLs are\n * signed by appending a signature to their URL parameters. This locks the URLs\n * and their parameters to the signature to prevent URL tampering.\n *\n * The `width` URL parameter will be applied for each `srcset` entry. If a\n * `width` or `w` parameter is provided to the `params` parameter, it will be ignored.\n *\n * **Important**: This function should only be used in a trusted environment and\n * never in a browser. The `secureURLToken` parameter is a secret and should not\n * be exposed to the public.\n *\n * @example\n *\n * ```ts\n * const srcset = buildSignedWidthSrcSet(\n * \t\"https://example.imgix.net/image.png\",\n * \t\"example-token\",\n * \t{ widths: [400, 800, 1600] },\n * );\n * // => https://example.imgix.net/image.png?width=400&s=def3e221c3f4c4debda091b8e49420ea 400w,\n * // https://example.imgix.net/image.png?width=800&s=f12c7c39333410c10c2930b57116a943 800w,\n * // https://example.imgix.net/image.png?width=1600&s=3a975b5087ab7ad2ab91fe66072fd628 1600w\n * ```\n *\n * @example\n *\n * ```ts\n * const srcset = buildSignedWidthSrcSet(\n * \t\"https://example.imgix.net/image.png\",\n * \t\"example-token\",\n * \t{\n * \t\twidths: [400, 800, 1600],\n * \t\tsat: -100,\n * \t},\n * );\n * // => https://example.imgix.net/image.png?width=400&sat=-100&s=def3e221c3f4c4debda091b8e49420ea 400w,\n * // https://example.imgix.net/image.png?width=800&sat=-100&s=f12c7c39333410c10c2930b57116a943 800w,\n * // https://example.imgix.net/image.png?width=1600&sat=-100&s=3a975b5087ab7ad2ab91fe66072fd628 1600w\n * ```\n *\n * @param url - Full absolute URL to the Imgix image.\n * @param secureURLToken - The secret secure URL token for the image's Imgix source.\n * @param params - An object of Imgix URL API parameters. The `widths` parameter\n * defines the resulting `srcset` widths.\n *\n * @returns A `srcset` attribute value for `url` with the given Imgix URL API\n * parameters applied.\n */\nexport const buildSignedWidthSrcSet = (\n\turl: string,\n\tsecureURLToken: string,\n\t{ widths, ...params }: BuildWidthSrcSetParams,\n): string => {\n\treturn widths\n\t\t.map((width) => {\n\t\t\treturn `${buildSignedURL(url, secureURLToken, {\n\t\t\t\t...params,\n\t\t\t\tw: undefined,\n\t\t\t\twidth,\n\t\t\t})} ${width}w`;\n\t\t})\n\t\t.join(\", \");\n};\n","import type { ImgixURLParams } from \"./types.generated\";\nimport { buildURL } from \"./buildURL\";\n\n/**\n * Parameters for `buildWidthSrcSet`.\n */\nexport type BuildWidthSrcSetParams = Omit<ImgixURLParams, \"width\" | \"w\"> & {\n\t/**\n\t * The pixel widths to include in the resulting `srcset` value.\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * [400, 800, 1600];\n\t * ```\n\t */\n\twidths: number[];\n};\n\n/**\n * Builds an `<img>` `srcset` attribute value for a given set of widths. It can\n * also optinally apply Imgix URL API parameters to the URLs.\n *\n * The `width` URL parameter will be applied for each `srcset` entry. If a\n * `width` or `w` parameter is provided to the `params` parameter, it will be ignored.\n *\n * @example\n *\n * ```ts\n * const srcset = buildWidthSrcSet(\"https://example.imgix.net/image.png\", {\n * \twidths: [400, 800, 1600],\n * });\n * // => https://example.imgix.net/image.png?width=400 400w,\n * // https://example.imgix.net/image.png?width=800 800w,\n * // https://example.imgix.net/image.png?width=1600 1600w\n * ```\n *\n * @example\n *\n * ```ts\n * const srcset = buildWidthSrcSet(\"https://example.imgix.net/image.png\", {\n * \twidths: [400, 800, 1600],\n * \tsat: -100,\n * });\n * // => https://example.imgix.net/image.png?width=400&sat=-100 400w,\n * // https://example.imgix.net/image.png?width=800&sat=-100 800w,\n * // https://example.imgix.net/image.png?width=1600&sat=-100 1600w\n * ```\n *\n * @param url - Full absolute URL to the Imgix image.\n * @param params - An object of Imgix URL API parameters. The `widths` parameter\n * defines the resulting `srcset` widths.\n *\n * @returns A `srcset` attribute value for `url` with the given Imgix URL API\n * parameters applied.\n */\nexport const buildWidthSrcSet = (\n\turl: string,\n\t{ widths, ...params }: BuildWidthSrcSetParams,\n): string => {\n\treturn widths\n\t\t.map((width) => {\n\t\t\treturn `${buildURL(url, { ...params, w: undefined, width })} ${width}w`;\n\t\t})\n\t\t.join(\", \");\n};\n","import type { BuildPixelDensitySrcSetParams } from \"../buildPixelDensitySrcSet\";\nimport type { BuildWidthSrcSetParams } from \"../buildWidthSrcSet\";\nimport type { ImgixURLParams } from \"../types.generated\";\nimport { buildPixelDensitySrcSet } from \"../buildPixelDensitySrcSet\";\nimport { buildSignedPixelDensitySrcSet } from \"./buildSignedPixelDensitySrcSet\";\nimport { buildSignedURL } from \"./buildSignedURL\";\nimport { buildSignedWidthSrcSet } from \"./buildSignedWidthSrcSet\";\nimport { buildURL } from \"../buildURL\";\nimport { buildWidthSrcSet } from \"../buildWidthSrcSet\";\nimport { signURL } from \"./signURL\";\n\n/**\n * Options to instantiate a new secure client.\n */\nexport type SecureClientOptions = {\n\t/**\n\t * The base URL used to construct image URLs from a path. The base URL must\n\t * include the protocol, domain, and optionally a path.\n\t *\n\t * @example `https://example.imgix.net`\n\t *\n\t * @example `https://example.imgix.net/folder`\n\t */\n\tbaseURL: string;\n\n\t/**\n\t * The secret secure URL token for the configured Imgix domain.\n\t *\n\t * @see How to get a token: https://docs.imgix.com/setup/securing-images\n\t */\n\tsecureURLToken: string;\n};\n\n/**\n * An Imgix Rendering API client with automatic URL signing. A client is paired\n * to a single Imgix domain and secure URL token.\n *\n * **Important**: This client should only be used in a trusted environment and\n * never in a browser. The `secureURLToken` parameter is a secret and should not\n * be exposed to the public.\n */\nexport class SecureClient {\n\t/**\n\t * The base URL used to construct image URLs from a path. The base URL must\n\t * include the protocol, domain, and optionally a path.\n\t */\n\tbaseURL: string;\n\n\t/**\n\t * The secret secure URL token for the configured Imgix domain.\n\t */\n\tsecureURLToken: string;\n\n\t/**\n\t * Creates a new `SecureClient` instance for an Imgix domain.\n\t *\n\t * @param options - Options to instantiate a new client.\n\t *\n\t * @returns A `SecureClient` instance for the given Imgix domain.\n\t */\n\tconstructor(options: SecureClientOptions) {\n\t\tthis.baseURL = options.baseURL;\n\t\tthis.secureURLToken = options.secureURLToken;\n\t}\n\n\t/**\n\t * Builds a Web Proxy URL that proxies a non-Imgix URL to Imgix. The client's\n\t * Imgix domain must be configured as a Web Proxy source. All Web Proxy URLs\n\t * will be signed automatically.\n\t *\n\t * **Important**: The given URL must not be URI encoded. If it is, decode it\n\t * before passing it to `buildWebProxyURL()`.\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * const client = new SecureClient({\n\t * \tbaseURL: \"https://example.imgix.net\",\n\t * \tsecureURLToken: \"example-token\",\n\t * });\n\t * const url = client.buildWebProxyURL(\"https://www.this.com/pic.jpg\", {\n\t * \twidth: 400,\n\t * });\n\t * // => https://example.imgix.net/https%3A%2F%2Fwww.this.com%2Fpic.jpg?width=400&s=def3e221c3f4c4debda091b8e49420ea\n\t * ```\n\t *\n\t * @param url - Full absolute URL to the source image to proxy.\n\t * @param params - An object of Imgix URL API parameters.\n\t *\n\t * @returns An Imgix url proxying `url` to the client's Imgix domain.\n\t */\n\tbuildWebProxyURL(url: string, params: ImgixURLParams = {}): string {\n\t\treturn this.buildSignedURLForPath(encodeURIComponent(url), params);\n\t}\n\n\t/**\n\t * Builds a URL to an Imgix image with Imgix URL API parameters for the\n\t * client's base URL.\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * const client = new SecureClient({\n\t * \tbaseURL: \"https://example.imgix.net\",\n\t * \tsecureURLToken: \"example-token\",\n\t * });\n\t * const url = client.buildURLForPath(\"/image.png\", { width: 400 });\n\t * // => https://example.imgix.net/image.png?width=400&s=def3e221c3f4c4debda091b8e49420ea\n\t * ```\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * const client = new SecureClient({\n\t * \tbaseURL: \"https://example.imgix.net/folder\",\n\t * \tsecureURLToken: \"example-token\",\n\t * });\n\t * const url = client.buildURLForPath(\"./image.png\", { width: 400 });\n\t * // => https://example.imgix.net/folder/image.png?width=400&s=f12c7c39333410c10c2930b57116a943\n\t * ```\n\t *\n\t * @param path - Path to the image relative to the client's base URL.\n\t * @param params - An object of Imgix URL API parameters.\n\t *\n\t * @returns The full absolute URL to the image with the given Imgix URL API\n\t * parameters applied.\n\t */\n\tbuildSignedURLForPath(path: string, params: ImgixURLParams = {}): string {\n\t\treturn this.signURL(this.buildURLForPath(path, params));\n\t}\n\n\t/**\n\t * Builds a URL to an Imgix image with Imgix URL API parameters for the\n\t * client's base URL.\n\t *\n\t * Note: The returned URL is not signed. See `buildSignedURL` if a signature\n\t * is required.\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * const client = new SecureClient({\n\t * \tbaseURL: \"https://example.imgix.net\",\n\t * \tsecureURLToken: \"example-token\",\n\t * });\n\t * const url = client.buildURLForPath(\"/image.png\", { width: 400 });\n\t * // => https://example.imgix.net/image.png?width=400\n\t * ```\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * const client = new SecureClient({\n\t * \tbaseURL: \"https://example.imgix.net/folder\",\n\t * \tsecureURLToken: \"example-token\",\n\t * });\n\t * const url = client.buildURLForPath(\"./image.png\", { width: 400 });\n\t * // => https://example.imgix.net/folder/image.png?width=400\n\t * ```\n\t *\n\t * @param path - Path to the image relative to the client's base URL.\n\t * @param params - An object of Imgix URL API parameters.\n\t *\n\t * @returns The full absolute URL to the image with the given Imgix URL API\n\t * parameters applied.\n\t */\n\tbuildURLForPath(path: string, params: ImgixURLParams = {}): string {\n\t\treturn buildURL(`${new URL(path, this.baseURL)}`, params);\n\t}\n\n\t/**\n\t * Builds a URL to an Imgix image with Imgix URL API parameters. The URL is\n\t * signed by appending a signature to the URL parameters. This locks the URL\n\t * and its parameters to the signature to prevent URL tampering.\n\t *\n\t * The given URL must be a full absolute URL containing the protocol and domain.\n\t *\n\t * URL parameters already applied to the image will be retained. To remove\n\t * existing parameters, set the parameter to `undefined` in the `params` argument.\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * const url = client.buildSignedURL(\n\t * \t\"https://example.imgix.net/image.png\",\n\t * \t{ width: 400 },\n\t * );\n\t * // => https://example.imgix.net/image.png?width=400&s=def3e221c3f4c4debda091b8e49420ea\n\t * ```\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * const url = client.buildSignedURL(\n\t * \t\"https://example.imgix.net/image.png?width=400\",\n\t * \t{ height: 300 },\n\t * );\n\t * // => https://example.imgix.net/image.png?width=400&height=300&s=f12c7c39333410c10c2930b57116a943\n\t * ```\n\t *\n\t * @param url - Full absolute URL to the Imgix image.\n\t * @param params - An object of Imgix URL API parameters.\n\t *\n\t * @returns `url` with the given Imgix URL API parameters applied.\n\t *\n\t * @see Imgix URL API reference: https://docs.imgix.com/apis/rendering\n\t * @see Details on securing Imgix images: https://docs.imgix.com/setup/securing-images\n\t */\n\tbuildSignedURL(url: string, params: ImgixURLParams = {}): string {\n\t\treturn buildSignedURL(url, this.secureURLToken, params);\n\t}\n\n\t/**\n\t * Signs an Imgix image URL by appending a signature to the URL parameters.\n\t * This locks the URL and its parameters to the signature to prevent URL tampering.\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * const url = client.signURL(\n\t * \t\"https://example.imgix.net/image.png?width=400\",\n\t * );\n\t * // => https://example.imgix.net/image.png?width=400&s=def3e221c3f4c4debda091b8e49420ea\n\t * ```\n\t *\n\t * @param url - Full absolute URL to the Imgix image to sign.\n\t *\n\t * @returns `url` with a signature appended via an `s` URL parameter.\n\t *\n\t * @see Details on securing Imgix images: https://docs.imgix.com/setup/securing-images\n\t */\n\tsignURL(url: string): string {\n\t\treturn signURL(url, this.secureURLToken);\n\t}\n\n\t/**\n\t * Builds an `<img>` `srcset` attribute value for a given set of widths. It\n\t * can also optinally apply Imgix URL API parameters to the URLs. The URLs are\n\t * signed by appending a signature to their URL parameters. This locks the\n\t * URLs and their parameters to the signature to prevent URL tampering.\n\t *\n\t * The `width` URL parameter will be applied for each `srcset` entry. If a\n\t * `width` or `w` parameter is provided to the `params` parameter, it will be ignored.\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * const srcset = client.buildSignedWidthSrcSet(\n\t * \t\"https://example.imgix.net/image.png\",\n\t * \t{ widths: [400, 800, 1600] },\n\t * );\n\t * // => https://example.imgix.net/image.png?width=400&s=def3e221c3f4c4debda091b8e49420ea 400w,\n\t * // https://example.imgix.net/image.png?width=800&s=f12c7c39333410c10c2930b57116a943 800w,\n\t * // https://example.imgix.net/image.png?width=1600&s=3a975b5087ab7ad2ab91fe66072fd628 1600w\n\t * ```\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * const srcset = client.buildSignedWidthSrcSet(\n\t * \t\"https://example.imgix.net/image.png\",\n\t * \t{\n\t * \t\twidths: [400, 800, 1600],\n\t * \t\tsat: -100,\n\t * \t},\n\t * );\n\t * // => https://example.imgix.net/image.png?width=400&sat=-100&s=def3e221c3f4c4debda091b8e49420ea 400w,\n\t * // https://example.imgix.net/image.png?width=800&sat=-100&s=f12c7c39333410c10c2930b57116a943 800w,\n\t * // https://example.imgix.net/image.png?width=1600&sat=-100&s=3a975b5087ab7ad2ab91fe66072fd628 1600w\n\t * ```\n\t *\n\t * @param url - Full absolute URL to the Imgix image.\n\t * @param params - An object of Imgix URL API parameters. The `widths`\n\t * parameter defines the resulting `srcset` widths.\n\t *\n\t * @returns A `srcset` attribute value for `url` with the given Imgix URL API\n\t * parameters applied.\n\t */\n\tbuildSignedWidthSrcSet(url: string, params: BuildWidthSrcSetParams): string {\n\t\treturn buildSignedWidthSrcSet(url, this.secureURLToken, params);\n\t}\n\n\t/**\n\t * Builds an `<img>` `srcset` attribute value for a given set of widths for\n\t * the client's base URL. It can also optinally apply Imgix URL API parameters\n\t * to the URLs.\n\t *\n\t * The `width` URL parameter will be applied for each `srcset` entry. If a\n\t * `width` or `w` parameter is provided to the `params` parameter, it will be ignored.\n\t *\n\t * Note: The returned URLs are not signed. See `buildSignedWidthSrcSet` if\n\t * signatures are required.\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * const client = new SecureClient({\n\t * \tbaseURL: \"https://example.imgix.net\",\n\t * \tsecureURLToken: \"example-token\",\n\t * });\n\t * const srcset = client.buildWidthSrcSetForPath(\"/image.png\", {\n\t * \twidths: [400, 800, 1600],\n\t * });\n\t * // => https://example.imgix.net/image.png?width=400 400w,\n\t * // https://example.imgix.net/image.png?width=800 800w,\n\t * // https://example.imgix.net/image.png?width=1600 1600w\n\t * ```\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * const client = new SecureClient({\n\t * \tbaseURL: \"https://example.imgix.net\",\n\t * \tsecureURLToken: \"example-token\",\n\t * });\n\t * const srcset = client.buildWidthSrcSetForPath(\"/image.png\", {\n\t * \twidths: [400, 800, 1600],\n\t * \tsat: -100,\n\t * });\n\t * // => https://example.imgix.net/image.png?width=400&sat=-100 400w,\n\t * // https://example.imgix.net/image.png?width=800&sat=-100 800w,\n\t * // https://example.imgix.net/image.png?width=1600&sat=-100 1600w\n\t * ```\n\t *\n\t * @param path - Path to the image relative to the client's base URL.\n\t * @param params - An object of Imgix URL API parameters. The `widths`\n\t * parameter defines the resulting `srcset` widths.\n\t *\n\t * @returns A `srcset` attribute value for `url` with the given Imgix URL API\n\t * parameters applied.\n\t */\n\tbuildWidthSrcSetForPath(\n\t\tpath: string,\n\t\tparams: BuildWidthSrcSetParams,\n\t): string {\n\t\treturn buildWidthSrcSet(`${new URL(path, this.baseURL)}`, params);\n\t}\n\n\t/**\n\t * Builds an `<img>` `srcset` attribute value for a given set of widths for\n\t * the client's base URL. It can also optinally apply Imgix URL API parameters\n\t * to the URLs. The URLs are signed by appending a signature to their URL\n\t * parameters. This locks the URLs and their parameters to the signature to\n\t * prevent URL tampering.\n\t *\n\t * The `width` URL parameter will be applied for each `srcset` entry. If a\n\t * `width` or `w` parameter is provided to the `params` parameter, it will be ignored.\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * const client = new SecureClient({\n\t * \tbaseURL: \"https://example.imgix.net\",\n\t * \tsecureURLToken: \"example-token\",\n\t * });\n\t * const srcset = client.buildSignedWidthSrcSetForPath(\"/image.png\", {\n\t * \twidths: [400, 800, 1600],\n\t * });\n\t * // => https://example.imgix.net/image.png?width=400&s=def3e221c3f4c4debda091b8e49420ea 400w,\n\t * // https://example.imgix.net/image.png?width=800&s=f12c7c39333410c10c2930b57116a943 800w,\n\t * // https://example.imgix.net/image.png?width=1600&s=3a975b5087ab7ad2ab91fe66072fd628 1600w\n\t * ```\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * const client = new SecureClient({\n\t * \tbaseURL: \"https://example.imgix.net\",\n\t * \tsecureURLToken: \"example-token\",\n\t * });\n\t * const srcset = client.buildSignedWidthSrcSetForPath(\"/image.png\", {\n\t * \twidths: [400, 800, 1600],\n\t * \tsat: -100,\n\t * });\n\t * // => https://example.imgix.net/image.png?width=400&sat=-100&s=def3e221c3f4c4debda091b8e49420ea 400w,\n\t * // https://example.imgix.net/image.png?width=800&sat=-100&s=f12c7c39333410c10c2930b57116a943 800w,\n\t * // https://example.imgix.net/image.png?width=1600&sat=-100&s=3a975b5087ab7ad2ab91fe66072fd628 1600w\n\t * ```\n\t *\n\t * @param path - Path to the image relative to the client's base URL.\n\t * @param params - An object of Imgix URL API parameters. The `widths`\n\t * parameter defines the resulting `srcset` widths.\n\t *\n\t * @returns A `srcset` attribute value for `url` with the given Imgix URL API\n\t * parameters applied.\n\t */\n\tbuildSignedWidthSrcSetForPath(\n\t\tpath: string,\n\t\tparams: BuildWidthSrcSetParams,\n\t): string {\n\t\treturn this.buildSignedWidthSrcSet(\n\t\t\t`${new URL(path, this.baseURL)}`,\n\t\t\tparams,\n\t\t);\n\t}\n\n\t/**\n\t * Builds an `<img>` `srcset` attribute value for a given set of pixel\n\t * densities. It can also optinally apply Imgix URL API parameters to the\n\t * URLs. The URLs are signed by appending a signature to their URL parameters.\n\t * This locks the URLs and their parameters to the signature to prevent URL tampering.\n\t *\n\t * The `dpr` URL parameter will be applied for each `srcset` entry. If a `dpr`\n\t * parameter is provided to the `params` parameter, it will be ignored.\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * const srcset = client.buildSignedPixelDensitySrcSet(\n\t * \t\"https://example.imgix.net/image.png\",\n\t * \t{ pixelDensities: [1, 2, 3] },\n\t * );\n\t * // => https://example.imgix.net/image.png?dpr=1&s=def3e221c3f4c4debda091b8e49420ea 1x,\n\t * // https://example.imgix.net/image.png?dpr=2&s=f12c7c39333410c10c2930b57116a943 2x,\n\t * // https://example.imgix.net/image.png?dpr=3&s=3a975b5087ab7ad2ab91fe66072fd628 3x\n\t * ```\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * const srcset = client.buildSignedPixelDensitySrcSet(\n\t * \t\"https://example.imgix.net/image.png\",\n\t * \t{\n\t * \t\tpixelDensities: [1, 2, 3],\n\t * \t\tsat: -100,\n\t * \t},\n\t * );\n\t * // => https://example.imgix.net/image.png?dpr=1&sat=-100&s=def3e221c3f4c4debda091b8e49420ea 1x,\n\t * // https://example.imgix.net/image.png?dpr=2&sat=-100&s=f12c7c39333410c10c2930b57116a943 2x,\n\t * // https://example.imgix.net/image.png?dpr=3&sat=-100&s=3a975b5087ab7ad2ab91fe66072fd628 3x\n\t * ```\n\t *\n\t * @param url - Full absolute URL to the Imgix image.\n\t * @param params - An object of Imgix URL API parameters. The `pixelDensities`\n\t * parameter defines the resulting `srcset` widths.\n\t *\n\t * @returns A `srcset` attribute value for `url` with the given Imgix URL API\n\t * parameters applied.\n\t */\n\tbuildSignedPixelDensitySrcSet(\n\t\turl: string,\n\t\tparams: BuildPixelDensitySrcSetParams,\n\t): string {\n\t\treturn buildSignedPixelDensitySrcSet(url, this.secureURLToken, params);\n\t}\n\n\t/**\n\t * Builds an `<img>` `srcset` attribute value for a given set of pixel\n\t * densities for the client's base URL. It can also optinally apply Imgix URL\n\t * API parameters to the URLs.\n\t *\n\t * The `dpr` URL parameter will be applied for each `srcset` entry. If a `dpr`\n\t * parameter is provided to the `params` parameter, it will be ignored.\n\t *\n\t * Note: The returned URLs are not signed. See `buildSignedPixelDensitySrcSet`\n\t * if signatures are required.\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * const client = new SecureClient({\n\t * \tbaseURL: \"https://example.imgix.net\",\n\t * \tsecureURLToken: \"example-token\",\n\t * });\n\t * const srcset = client.buildPixelDensitySrcSetForPath(\"/image.png\", {\n\t * \tpixelDensities: [1, 2, 3],\n\t * });\n\t * // => https://example.imgix.net/image.png?dpr=1 1x,\n\t * // https://example.imgix.net/image.png?dpr=2 2x,\n\t * // https://example.imgix.net/image.png?dpr=3 3x\n\t * ```\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * const client = new SecureClient({\n\t * \tbaseURL: \"https://example.imgix.net\",\n\t * \tsecureURLToken: \"example-token\",\n\t * });\n\t * const srcset = client.buildPixelDensitySrcSetForPath(\"/image.png\", {\n\t * \tpixelDensities: [1, 2, 3],\n\t * \tsat: -100,\n\t * });\n\t * // => https://example.imgix.net/image.png?dpr=1&sat=-100 1x,\n\t * // https://example.imgix.net/image.png?dpr=2&sat=-100 2x,\n\t * // https://example.imgix.net/image.png?dpr=3&sat=-100 3x\n\t * ```\n\t *\n\t * @param path - Path to the image relative to the client's base URL.\n\t * @param params - An object of Imgix URL API parameters. The `pixelDensities`\n\t * parameter defines the resulting `srcset` widths.\n\t *\n\t * @returns A `srcset` attribute value for `url` with the given Imgix URL API\n\t * parameters applied.\n\t */\n\tbuildPixelDensitySrcSetForPath(\n\t\tpath: string,\n\t\tparams: BuildPixelDensitySrcSetParams,\n\t): string {\n\t\treturn buildPixelDensitySrcSet(`${new URL(path, this.baseURL)}`, params);\n\t}\n\n\t/**\n\t * Builds an `<img>` `srcset` attribute value for a given set of pixel\n\t * densities for the client's base URL. It can also optinally apply Imgix URL\n\t * API parameters to the URLs. The URLs are signed by appending a signature to\n\t * their URL parameters. This locks the URLs and their parameters to the\n\t * signature to prevent URL tampering.\n\t *\n\t * The `dpr` URL parameter will be applied for each `srcset` entry. If a `dpr`\n\t * parameter is provided to the `params` parameter, it will be ignored.\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * const client = new SecureClient({\n\t * \tbaseURL: \"https://example.imgix.net\",\n\t * \tsecureURLToken: \"example-token\",\n\t * });\n\t * const srcset = client.buildSignedPixelDensitySrcSetForPath(\n\t * \t\"/image.png\",\n\t * \t{ pixelDensities: [1, 2, 3] },\n\t * );\n\t * // => https://example.imgix.net/image.png?dpr=1&s=def3e221c3f4c4debda091b8e49420ea 1x,\n\t * // https://example.imgix.net/image.png?dpr=2&s=f12c7c39333410c10c2930b57116a943 2x,\n\t * // https://example.imgix.net/image.png?dpr=3&s=3a975b5087ab7ad2ab91fe66072fd628 3x\n\t * ```\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * const client = new SecureClient({\n\t * \tbaseURL: \"https://example.imgix.net\",\n\t * \tsecureURLToken: \"example-token\",\n\t * });\n\t * const srcset = client.buildSignedPixelDensitySrcSetForPath(\n\t * \t\"/image.png\",\n\t * \t{\n\t * \t\tpixelDensities: [1, 2, 3],\n\t * \t\tsat: -100,\n\t * \t},\n\t * );\n\t * // => https://example.imgix.net/image.png?dpr=1&sat=-100&s=def3e221c3f4c4debda091b8e49420ea 1x,\n\t * // https://example.imgix.net/image.png?dpr=2&sat=-100&s=f12c7c39333410c10c2930b57116a943 2x,\n\t * // https://example.imgix.net/image.png?dpr=3&sat=-100&s=3a975b5087ab7ad2ab91fe66072fd628 3x\n\t * ```\n\t *\n\t * @param path - Path to the image relative to the client's base URL.\n\t * @param params - An object of Imgix URL API parameters. The `pixelDensities`\n\t * parameter defines the resulting `srcset` widths.\n\t *\n\t * @returns A `srcset` attribute value for `url` with the given Imgix URL API\n\t * parameters applied.\n\t */\n\tbuildSignedPixelDensitySrcSetForPath(\n\t\tpath: string,\n\t\tparams: BuildPixelDensitySrcSetParams,\n\t): string {\n\t\treturn buildSignedPixelDensitySrcSet(\n\t\t\t`${new URL(path, this.baseURL)}`,\n\t\t\tthis.secureURLToken,\n\t\t\tparams,\n\t\t);\n\t}\n}\n"],"names":["createHash"],"mappings":"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"}
|
package/dist/node/index.mjs
CHANGED
|
@@ -1,10 +1,14 @@
|
|
|
1
|
-
import { paramCase } from 'param-case';
|
|
2
1
|
import { createHash } from 'crypto';
|
|
3
2
|
|
|
3
|
+
const camelCaseToParamCase = (input) => {
|
|
4
|
+
return input.replace(/[A-Z]/g, (match) => {
|
|
5
|
+
return `-${match.toLowerCase()}`;
|
|
6
|
+
});
|
|
7
|
+
};
|
|
4
8
|
const buildURL = (url, params) => {
|
|
5
9
|
const instance = new URL(url);
|
|
6
10
|
for (const camelCasedParamKey in params) {
|
|
7
|
-
const paramKey =
|
|
11
|
+
const paramKey = camelCaseToParamCase(camelCasedParamKey);
|
|
8
12
|
const paramValue = params[camelCasedParamKey];
|
|
9
13
|
if (paramValue === void 0) {
|
|
10
14
|
instance.searchParams.delete(paramKey);
|
package/dist/node/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sources":["../../src/buildURL.ts","../../src/buildPixelDensitySrcSet.ts","../../src/node/signURL.ts","../../src/node/buildSignedURL.ts","../../src/node/buildSignedPixelDensitySrcSet.ts","../../src/node/buildSignedWidthSrcSet.ts","../../src/buildWidthSrcSet.ts","../../src/node/SecureClient.ts"],"sourcesContent":["import { paramCase } from \"param-case\";\n\nimport type { ImgixURLParams } from \"./types.generated\";\n\n/**\n * Builds a URL to an Imgix image with Imgix URL API parameters.\n *\n * The given URL must be a full absolute URL containing the protocol and domain.\n *\n * URL parameters already applied to the image will be retained. To remove\n * existing parameters, set the parameter to `undefined` in the `params` argument.\n *\n * @example\n *\n * ```ts\n * const url = buildURL(\"https://example.imgix.net/image.png\", {\n * \twidth: 400,\n * });\n * // => https://example.imgix.net/image.png?width=400\n * ```\n *\n * @example\n *\n * ```ts\n * const url = buildURL(\"https://example.imgix.net/image.png?width=400\", {\n * \theight: 300,\n * });\n * // => https://example.imgix.net/image.png?width=400&height=300\n * ```\n *\n * @param url - Full absolute URL to the Imgix image.\n * @param params - An object of Imgix URL API parameters.\n *\n * @returns `url` with the given Imgix URL API parameters applied.\n *\n * @see Imgix URL API reference: https://docs.imgix.com/apis/rendering\n */\nexport const buildURL = (url: string, params: ImgixURLParams): string => {\n\tconst instance = new URL(url);\n\n\tfor (const camelCasedParamKey in params) {\n\t\tconst paramKey = paramCase(camelCasedParamKey);\n\t\tconst paramValue = params[camelCasedParamKey as keyof typeof params];\n\n\t\tif (paramValue === undefined) {\n\t\t\tinstance.searchParams.delete(paramKey);\n\t\t} else if (Array.isArray(paramValue)) {\n\t\t\tinstance.searchParams.set(paramKey, paramValue.join(\",\"));\n\t\t} else {\n\t\t\tinstance.searchParams.set(paramKey, `${paramValue}`);\n\t\t}\n\t}\n\n\t// Ensure the `s` parameter is the last parameter, if it exists.\n\t// @see https://github.com/imgix/imgix-blueprint#securing-urls\n\tconst s = instance.searchParams.get(\"s\");\n\tif (s) {\n\t\tinstance.searchParams.delete(\"s\");\n\t\tinstance.searchParams.append(\"s\", s);\n\t}\n\n\treturn instance.toString();\n};\n","import type { ImgixURLParams } from \"./types.generated\";\nimport { buildURL } from \"./buildURL\";\n\n/**\n * Parameters for `buildPixelDensitySrcSet`.\n */\nexport type BuildPixelDensitySrcSetParams = Omit<ImgixURLParams, \"dpr\"> & {\n\t/**\n\t * The pixel densities to include in the resulting `srcset` value.\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * [1, 2, 3];\n\t * ```\n\t */\n\tpixelDensities: number[];\n};\n\n/**\n * Builds an `<img>` `srcset` attribute value for a given set of pixel\n * densities. It can also optinally apply Imgix URL API parameters to the URLs.\n *\n * The `dpr` URL parameter will be applied for each `srcset` entry. If a `dpr`\n * parameter is provided to the `params` parameter, it will be ignored.\n *\n * @example\n *\n * ```ts\n * const srcset = buildPixelDensitySrcSet(\n * \t\"https://example.imgix.net/image.png\",\n * \t{ pixelDensities: [1, 2, 3] },\n * );\n * // => https://example.imgix.net/image.png?dpr=1 1x,\n * // https://example.imgix.net/image.png?dpr=2 2x,\n * // https://example.imgix.net/image.png?dpr=3 3x\n * ```\n *\n * @example\n *\n * ```ts\n * const srcset = buildPixelDensitySrcSet(\n * \t\"https://example.imgix.net/image.png\",\n * \t{\n * \t\tpixelDensities: [1, 2, 3],\n * \t\tsat: -100,\n * \t},\n * );\n * // => https://example.imgix.net/image.png?dpr=1&sat=-100 1x,\n * // https://example.imgix.net/image.png?dpr=2&sat=-100 2x,\n * // https://example.imgix.net/image.png?dpr=3&sat=-100 3x\n * ```\n *\n * @param url - Full absolute URL to the Imgix image.\n * @param params - An object of Imgix URL API parameters. The `pixelDensities`\n * parameter defines the resulting `srcset` widths.\n *\n * @returns A `srcset` attribute value for `url` with the given Imgix URL API\n * parameters applied.\n */\nexport const buildPixelDensitySrcSet = (\n\turl: string,\n\t{ pixelDensities, ...params }: BuildPixelDensitySrcSetParams,\n): string => {\n\treturn pixelDensities\n\t\t.map((dpr) => {\n\t\t\treturn `${buildURL(url, { ...params, dpr })} ${dpr}x`;\n\t\t})\n\t\t.join(\", \");\n};\n","import { createHash } from \"crypto\";\n\n/**\n * Signs an Imgix image URL by appending a signature to the URL parameters. This\n * locks the URL and its parameters to the signature to prevent URL tampering.\n *\n * **Important**: This function should only be used in a trusted environment and\n * never in a browser. The `secureURLToken` parameter is a secret and should not\n * be exposed to the public.\n *\n * @example\n *\n * ```ts\n * const url = signURL(\n * \t\"https://example.imgix.net/image.png?width=400\",\n * \t\"example-token\",\n * );\n * // => https://example.imgix.net/image.png?width=400&s=def3e221c3f4c4debda091b8e49420ea\n * ```\n *\n * @param url - Full absolute URL to the Imgix image to sign.\n * @param secureURLToken - The secret Imgix secure URL token used to generate\n * the signature.\n *\n * @returns `url` with a signature appended via an `s` URL parameter.\n *\n * @see Details on securing Imgix images: https://docs.imgix.com/setup/securing-images\n */\nexport const signURL = (url: string, secureURLToken: string): string => {\n\tconst instance = new URL(url);\n\n\t// If an `s` param is passed explicitly, it will be overridden. It must\n\t// also not be used when generating the signature.\n\tinstance.searchParams.delete(\"s\");\n\n\t// @see https://github.com/imgix/imgix-blueprint#securing-urls\n\tconst signature = createHash(\"md5\")\n\t\t.update(secureURLToken + instance.pathname + instance.search)\n\t\t.digest(\"hex\");\n\n\tinstance.searchParams.append(\"s\", signature);\n\n\treturn instance.toString();\n};\n","import type { ImgixURLParams } from \"../types.generated\";\nimport { buildURL } from \"../buildURL\";\nimport { signURL } from \"./signURL\";\n\n/**\n * Builds a URL to an Imgix image with Imgix URL API parameters. The URL is\n * signed by appending a signature to the URL parameters. This locks the URL and\n * its parameters to the signature to prevent URL tampering.\n *\n * The given URL must be a full absolute URL containing the protocol and domain.\n *\n * URL parameters already applied to the image will be retained. To remove\n * existing parameters, set the parameter to `undefined` in the `params` argument.\n *\n * **Important**: This function should only be used in a trusted environment and\n * never in a browser. The `secureURLToken` parameter is a secret and should not\n * be exposed to the public.\n *\n * @example\n *\n * ```ts\n * const url = buildSignedURL(\n * \t\"https://example.imgix.net/image.png\",\n * \t\"example-token\",\n * \t{ width: 400 },\n * );\n * // => https://example.imgix.net/image.png?width=400&s=def3e221c3f4c4debda091b8e49420ea\n * ```\n *\n * @example\n *\n * ```ts\n * const url = buildSignedURL(\n * \t\"https://example.imgix.net/image.png?width=400\",\n * \t\"example-token\",\n * \t{ height: 300 },\n * );\n * // => https://example.imgix.net/image.png?width=400&height=300&s=f12c7c39333410c10c2930b57116a943\n * ```\n *\n * @param url - Full absolute URL to the Imgix image.\n * @param secureURLToken - The secret secure URL token for the image's Imgix source.\n * @param params - An object of Imgix URL API parameters.\n *\n * @returns `url` with the given Imgix URL API parameters applied.\n *\n * @see Imgix URL API reference: https://docs.imgix.com/apis/rendering\n * @see Details on securing Imgix images: https://docs.imgix.com/setup/securing-images\n */\nexport const buildSignedURL = (\n\turl: string,\n\tsecureURLToken: string,\n\tparams: ImgixURLParams,\n): string => {\n\treturn signURL(buildURL(url, params), secureURLToken);\n};\n","import type { BuildPixelDensitySrcSetParams } from \"../buildPixelDensitySrcSet\";\nimport { buildSignedURL } from \"./buildSignedURL\";\n\n/**\n * Builds an `<img>` `srcset` attribute value for a given set of pixel\n * densities. It can also optinally apply Imgix URL API parameters to the URLs.\n * The URLs are signed by appending a signature to their URL parameters. This\n * locks the URLs and their parameters to the signature to prevent URL tampering.\n *\n * The `dpr` URL parameter will be applied for each `srcset` entry. If a `dpr`\n * parameter is provided to the `params` parameter, it will be ignored.\n *\n * **Important**: This function should only be used in a trusted environment and\n * never in a browser. The `secureURLToken` parameter is a secret and should not\n * be exposed to the public.\n *\n * @example\n *\n * ```ts\n * const srcset = buildSignedPixelDensitySrcSet(\n * \t\"https://example.imgix.net/image.png\",\n * \t\"example-token\",\n * \t{ pixelDensities: [1, 2, 3] },\n * );\n * // => https://example.imgix.net/image.png?dpr=1&s=def3e221c3f4c4debda091b8e49420ea 1x,\n * // https://example.imgix.net/image.png?dpr=2&s=f12c7c39333410c10c2930b57116a943 2x,\n * // https://example.imgix.net/image.png?dpr=3&s=3a975b5087ab7ad2ab91fe66072fd628 3x\n * ```\n *\n * @example\n *\n * ```ts\n * const srcset = buildSignedPixelDensitySrcSet(\n * \t\"https://example.imgix.net/image.png\",\n * \t\"example-token\",\n * \t{\n * \t\tpixelDensities: [1, 2, 3],\n * \t\tsat: -100,\n * \t},\n * );\n * // => https://example.imgix.net/image.png?dpr=1&sat=-100&s=def3e221c3f4c4debda091b8e49420ea 1x,\n * // https://example.imgix.net/image.png?dpr=2&sat=-100&s=f12c7c39333410c10c2930b57116a943 2x,\n * // https://example.imgix.net/image.png?dpr=3&sat=-100&s=3a975b5087ab7ad2ab91fe66072fd628 3x\n * ```\n *\n * @param url - Full absolute URL to the Imgix image.\n * @param secureURLToken - The secret secure URL token for the image's Imgix source.\n * @param params - An object of Imgix URL API parameters. The `pixelDensities`\n * parameter defines the resulting `srcset` widths.\n *\n * @returns A `srcset` attribute value for `url` with the given Imgix URL API\n * parameters applied.\n */\nexport const buildSignedPixelDensitySrcSet = (\n\turl: string,\n\tsecureURLToken: string,\n\t{ pixelDensities, ...params }: BuildPixelDensitySrcSetParams,\n): string => {\n\treturn pixelDensities\n\t\t.map((dpr) => {\n\t\t\treturn `${buildSignedURL(url, secureURLToken, {\n\t\t\t\t...params,\n\t\t\t\tdpr,\n\t\t\t})} ${dpr}x`;\n\t\t})\n\t\t.join(\", \");\n};\n","import type { BuildWidthSrcSetParams } from \"../buildWidthSrcSet\";\nimport { buildSignedURL } from \"./buildSignedURL\";\n\n/**\n * Builds an `<img>` `srcset` attribute value for a given set of widths. It can\n * also optinally apply Imgix URL API parameters to the URLs. The URLs are\n * signed by appending a signature to their URL parameters. This locks the URLs\n * and their parameters to the signature to prevent URL tampering.\n *\n * The `width` URL parameter will be applied for each `srcset` entry. If a\n * `width` or `w` parameter is provided to the `params` parameter, it will be ignored.\n *\n * **Important**: This function should only be used in a trusted environment and\n * never in a browser. The `secureURLToken` parameter is a secret and should not\n * be exposed to the public.\n *\n * @example\n *\n * ```ts\n * const srcset = buildSignedWidthSrcSet(\n * \t\"https://example.imgix.net/image.png\",\n * \t\"example-token\",\n * \t{ widths: [400, 800, 1600] },\n * );\n * // => https://example.imgix.net/image.png?width=400&s=def3e221c3f4c4debda091b8e49420ea 400w,\n * // https://example.imgix.net/image.png?width=800&s=f12c7c39333410c10c2930b57116a943 800w,\n * // https://example.imgix.net/image.png?width=1600&s=3a975b5087ab7ad2ab91fe66072fd628 1600w\n * ```\n *\n * @example\n *\n * ```ts\n * const srcset = buildSignedWidthSrcSet(\n * \t\"https://example.imgix.net/image.png\",\n * \t\"example-token\",\n * \t{\n * \t\twidths: [400, 800, 1600],\n * \t\tsat: -100,\n * \t},\n * );\n * // => https://example.imgix.net/image.png?width=400&sat=-100&s=def3e221c3f4c4debda091b8e49420ea 400w,\n * // https://example.imgix.net/image.png?width=800&sat=-100&s=f12c7c39333410c10c2930b57116a943 800w,\n * // https://example.imgix.net/image.png?width=1600&sat=-100&s=3a975b5087ab7ad2ab91fe66072fd628 1600w\n * ```\n *\n * @param url - Full absolute URL to the Imgix image.\n * @param secureURLToken - The secret secure URL token for the image's Imgix source.\n * @param params - An object of Imgix URL API parameters. The `widths` parameter\n * defines the resulting `srcset` widths.\n *\n * @returns A `srcset` attribute value for `url` with the given Imgix URL API\n * parameters applied.\n */\nexport const buildSignedWidthSrcSet = (\n\turl: string,\n\tsecureURLToken: string,\n\t{ widths, ...params }: BuildWidthSrcSetParams,\n): string => {\n\treturn widths\n\t\t.map((width) => {\n\t\t\treturn `${buildSignedURL(url, secureURLToken, {\n\t\t\t\t...params,\n\t\t\t\tw: undefined,\n\t\t\t\twidth,\n\t\t\t})} ${width}w`;\n\t\t})\n\t\t.join(\", \");\n};\n","import type { ImgixURLParams } from \"./types.generated\";\nimport { buildURL } from \"./buildURL\";\n\n/**\n * Parameters for `buildWidthSrcSet`.\n */\nexport type BuildWidthSrcSetParams = Omit<ImgixURLParams, \"width\" | \"w\"> & {\n\t/**\n\t * The pixel widths to include in the resulting `srcset` value.\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * [400, 800, 1600];\n\t * ```\n\t */\n\twidths: number[];\n};\n\n/**\n * Builds an `<img>` `srcset` attribute value for a given set of widths. It can\n * also optinally apply Imgix URL API parameters to the URLs.\n *\n * The `width` URL parameter will be applied for each `srcset` entry. If a\n * `width` or `w` parameter is provided to the `params` parameter, it will be ignored.\n *\n * @example\n *\n * ```ts\n * const srcset = buildWidthSrcSet(\"https://example.imgix.net/image.png\", {\n * \twidths: [400, 800, 1600],\n * });\n * // => https://example.imgix.net/image.png?width=400 400w,\n * // https://example.imgix.net/image.png?width=800 800w,\n * // https://example.imgix.net/image.png?width=1600 1600w\n * ```\n *\n * @example\n *\n * ```ts\n * const srcset = buildWidthSrcSet(\"https://example.imgix.net/image.png\", {\n * \twidths: [400, 800, 1600],\n * \tsat: -100,\n * });\n * // => https://example.imgix.net/image.png?width=400&sat=-100 400w,\n * // https://example.imgix.net/image.png?width=800&sat=-100 800w,\n * // https://example.imgix.net/image.png?width=1600&sat=-100 1600w\n * ```\n *\n * @param url - Full absolute URL to the Imgix image.\n * @param params - An object of Imgix URL API parameters. The `widths` parameter\n * defines the resulting `srcset` widths.\n *\n * @returns A `srcset` attribute value for `url` with the given Imgix URL API\n * parameters applied.\n */\nexport const buildWidthSrcSet = (\n\turl: string,\n\t{ widths, ...params }: BuildWidthSrcSetParams,\n): string => {\n\treturn widths\n\t\t.map((width) => {\n\t\t\treturn `${buildURL(url, { ...params, w: undefined, width })} ${width}w`;\n\t\t})\n\t\t.join(\", \");\n};\n","import type { BuildPixelDensitySrcSetParams } from \"../buildPixelDensitySrcSet\";\nimport type { BuildWidthSrcSetParams } from \"../buildWidthSrcSet\";\nimport type { ImgixURLParams } from \"../types.generated\";\nimport { buildPixelDensitySrcSet } from \"../buildPixelDensitySrcSet\";\nimport { buildSignedPixelDensitySrcSet } from \"./buildSignedPixelDensitySrcSet\";\nimport { buildSignedURL } from \"./buildSignedURL\";\nimport { buildSignedWidthSrcSet } from \"./buildSignedWidthSrcSet\";\nimport { buildURL } from \"../buildURL\";\nimport { buildWidthSrcSet } from \"../buildWidthSrcSet\";\nimport { signURL } from \"./signURL\";\n\n/**\n * Options to instantiate a new secure client.\n */\nexport type SecureClientOptions = {\n\t/**\n\t * The base URL used to construct image URLs from a path. The base URL must\n\t * include the protocol, domain, and optionally a path.\n\t *\n\t * @example `https://example.imgix.net`\n\t *\n\t * @example `https://example.imgix.net/folder`\n\t */\n\tbaseURL: string;\n\n\t/**\n\t * The secret secure URL token for the configured Imgix domain.\n\t *\n\t * @see How to get a token: https://docs.imgix.com/setup/securing-images\n\t */\n\tsecureURLToken: string;\n};\n\n/**\n * An Imgix Rendering API client with automatic URL signing. A client is paired\n * to a single Imgix domain and secure URL token.\n *\n * **Important**: This client should only be used in a trusted environment and\n * never in a browser. The `secureURLToken` parameter is a secret and should not\n * be exposed to the public.\n */\nexport class SecureClient {\n\t/**\n\t * The base URL used to construct image URLs from a path. The base URL must\n\t * include the protocol, domain, and optionally a path.\n\t */\n\tbaseURL: string;\n\n\t/**\n\t * The secret secure URL token for the configured Imgix domain.\n\t */\n\tsecureURLToken: string;\n\n\t/**\n\t * Creates a new `SecureClient` instance for an Imgix domain.\n\t *\n\t * @param options - Options to instantiate a new client.\n\t *\n\t * @returns A `SecureClient` instance for the given Imgix domain.\n\t */\n\tconstructor(options: SecureClientOptions) {\n\t\tthis.baseURL = options.baseURL;\n\t\tthis.secureURLToken = options.secureURLToken;\n\t}\n\n\t/**\n\t * Builds a Web Proxy URL that proxies a non-Imgix URL to Imgix. The client's\n\t * Imgix domain must be configured as a Web Proxy source. All Web Proxy URLs\n\t * will be signed automatically.\n\t *\n\t * **Important**: The given URL must not be URI encoded. If it is, decode it\n\t * before passing it to `buildWebProxyURL()`.\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * const client = new SecureClient({\n\t * \tbaseURL: \"https://example.imgix.net\",\n\t * \tsecureURLToken: \"example-token\",\n\t * });\n\t * const url = client.buildWebProxyURL(\"https://www.this.com/pic.jpg\", {\n\t * \twidth: 400,\n\t * });\n\t * // => https://example.imgix.net/https%3A%2F%2Fwww.this.com%2Fpic.jpg?width=400&s=def3e221c3f4c4debda091b8e49420ea\n\t * ```\n\t *\n\t * @param url - Full absolute URL to the source image to proxy.\n\t * @param params - An object of Imgix URL API parameters.\n\t *\n\t * @returns An Imgix url proxying `url` to the client's Imgix domain.\n\t */\n\tbuildWebProxyURL(url: string, params: ImgixURLParams = {}): string {\n\t\treturn this.buildSignedURLForPath(encodeURIComponent(url), params);\n\t}\n\n\t/**\n\t * Builds a URL to an Imgix image with Imgix URL API parameters for the\n\t * client's base URL.\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * const client = new SecureClient({\n\t * \tbaseURL: \"https://example.imgix.net\",\n\t * \tsecureURLToken: \"example-token\",\n\t * });\n\t * const url = client.buildURLForPath(\"/image.png\", { width: 400 });\n\t * // => https://example.imgix.net/image.png?width=400&s=def3e221c3f4c4debda091b8e49420ea\n\t * ```\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * const client = new SecureClient({\n\t * \tbaseURL: \"https://example.imgix.net/folder\",\n\t * \tsecureURLToken: \"example-token\",\n\t * });\n\t * const url = client.buildURLForPath(\"./image.png\", { width: 400 });\n\t * // => https://example.imgix.net/folder/image.png?width=400&s=f12c7c39333410c10c2930b57116a943\n\t * ```\n\t *\n\t * @param path - Path to the image relative to the client's base URL.\n\t * @param params - An object of Imgix URL API parameters.\n\t *\n\t * @returns The full absolute URL to the image with the given Imgix URL API\n\t * parameters applied.\n\t */\n\tbuildSignedURLForPath(path: string, params: ImgixURLParams = {}): string {\n\t\treturn this.signURL(this.buildURLForPath(path, params));\n\t}\n\n\t/**\n\t * Builds a URL to an Imgix image with Imgix URL API parameters for the\n\t * client's base URL.\n\t *\n\t * Note: The returned URL is not signed. See `buildSignedURL` if a signature\n\t * is required.\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * const client = new SecureClient({\n\t * \tbaseURL: \"https://example.imgix.net\",\n\t * \tsecureURLToken: \"example-token\",\n\t * });\n\t * const url = client.buildURLForPath(\"/image.png\", { width: 400 });\n\t * // => https://example.imgix.net/image.png?width=400\n\t * ```\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * const client = new SecureClient({\n\t * \tbaseURL: \"https://example.imgix.net/folder\",\n\t * \tsecureURLToken: \"example-token\",\n\t * });\n\t * const url = client.buildURLForPath(\"./image.png\", { width: 400 });\n\t * // => https://example.imgix.net/folder/image.png?width=400\n\t * ```\n\t *\n\t * @param path - Path to the image relative to the client's base URL.\n\t * @param params - An object of Imgix URL API parameters.\n\t *\n\t * @returns The full absolute URL to the image with the given Imgix URL API\n\t * parameters applied.\n\t */\n\tbuildURLForPath(path: string, params: ImgixURLParams = {}): string {\n\t\treturn buildURL(`${new URL(path, this.baseURL)}`, params);\n\t}\n\n\t/**\n\t * Builds a URL to an Imgix image with Imgix URL API parameters. The URL is\n\t * signed by appending a signature to the URL parameters. This locks the URL\n\t * and its parameters to the signature to prevent URL tampering.\n\t *\n\t * The given URL must be a full absolute URL containing the protocol and domain.\n\t *\n\t * URL parameters already applied to the image will be retained. To remove\n\t * existing parameters, set the parameter to `undefined` in the `params` argument.\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * const url = client.buildSignedURL(\n\t * \t\"https://example.imgix.net/image.png\",\n\t * \t{ width: 400 },\n\t * );\n\t * // => https://example.imgix.net/image.png?width=400&s=def3e221c3f4c4debda091b8e49420ea\n\t * ```\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * const url = client.buildSignedURL(\n\t * \t\"https://example.imgix.net/image.png?width=400\",\n\t * \t{ height: 300 },\n\t * );\n\t * // => https://example.imgix.net/image.png?width=400&height=300&s=f12c7c39333410c10c2930b57116a943\n\t * ```\n\t *\n\t * @param url - Full absolute URL to the Imgix image.\n\t * @param params - An object of Imgix URL API parameters.\n\t *\n\t * @returns `url` with the given Imgix URL API parameters applied.\n\t *\n\t * @see Imgix URL API reference: https://docs.imgix.com/apis/rendering\n\t * @see Details on securing Imgix images: https://docs.imgix.com/setup/securing-images\n\t */\n\tbuildSignedURL(url: string, params: ImgixURLParams = {}): string {\n\t\treturn buildSignedURL(url, this.secureURLToken, params);\n\t}\n\n\t/**\n\t * Signs an Imgix image URL by appending a signature to the URL parameters.\n\t * This locks the URL and its parameters to the signature to prevent URL tampering.\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * const url = client.signURL(\n\t * \t\"https://example.imgix.net/image.png?width=400\",\n\t * );\n\t * // => https://example.imgix.net/image.png?width=400&s=def3e221c3f4c4debda091b8e49420ea\n\t * ```\n\t *\n\t * @param url - Full absolute URL to the Imgix image to sign.\n\t *\n\t * @returns `url` with a signature appended via an `s` URL parameter.\n\t *\n\t * @see Details on securing Imgix images: https://docs.imgix.com/setup/securing-images\n\t */\n\tsignURL(url: string): string {\n\t\treturn signURL(url, this.secureURLToken);\n\t}\n\n\t/**\n\t * Builds an `<img>` `srcset` attribute value for a given set of widths. It\n\t * can also optinally apply Imgix URL API parameters to the URLs. The URLs are\n\t * signed by appending a signature to their URL parameters. This locks the\n\t * URLs and their parameters to the signature to prevent URL tampering.\n\t *\n\t * The `width` URL parameter will be applied for each `srcset` entry. If a\n\t * `width` or `w` parameter is provided to the `params` parameter, it will be ignored.\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * const srcset = client.buildSignedWidthSrcSet(\n\t * \t\"https://example.imgix.net/image.png\",\n\t * \t{ widths: [400, 800, 1600] },\n\t * );\n\t * // => https://example.imgix.net/image.png?width=400&s=def3e221c3f4c4debda091b8e49420ea 400w,\n\t * // https://example.imgix.net/image.png?width=800&s=f12c7c39333410c10c2930b57116a943 800w,\n\t * // https://example.imgix.net/image.png?width=1600&s=3a975b5087ab7ad2ab91fe66072fd628 1600w\n\t * ```\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * const srcset = client.buildSignedWidthSrcSet(\n\t * \t\"https://example.imgix.net/image.png\",\n\t * \t{\n\t * \t\twidths: [400, 800, 1600],\n\t * \t\tsat: -100,\n\t * \t},\n\t * );\n\t * // => https://example.imgix.net/image.png?width=400&sat=-100&s=def3e221c3f4c4debda091b8e49420ea 400w,\n\t * // https://example.imgix.net/image.png?width=800&sat=-100&s=f12c7c39333410c10c2930b57116a943 800w,\n\t * // https://example.imgix.net/image.png?width=1600&sat=-100&s=3a975b5087ab7ad2ab91fe66072fd628 1600w\n\t * ```\n\t *\n\t * @param url - Full absolute URL to the Imgix image.\n\t * @param params - An object of Imgix URL API parameters. The `widths`\n\t * parameter defines the resulting `srcset` widths.\n\t *\n\t * @returns A `srcset` attribute value for `url` with the given Imgix URL API\n\t * parameters applied.\n\t */\n\tbuildSignedWidthSrcSet(url: string, params: BuildWidthSrcSetParams): string {\n\t\treturn buildSignedWidthSrcSet(url, this.secureURLToken, params);\n\t}\n\n\t/**\n\t * Builds an `<img>` `srcset` attribute value for a given set of widths for\n\t * the client's base URL. It can also optinally apply Imgix URL API parameters\n\t * to the URLs.\n\t *\n\t * The `width` URL parameter will be applied for each `srcset` entry. If a\n\t * `width` or `w` parameter is provided to the `params` parameter, it will be ignored.\n\t *\n\t * Note: The returned URLs are not signed. See `buildSignedWidthSrcSet` if\n\t * signatures are required.\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * const client = new SecureClient({\n\t * \tbaseURL: \"https://example.imgix.net\",\n\t * \tsecureURLToken: \"example-token\",\n\t * });\n\t * const srcset = client.buildWidthSrcSetForPath(\"/image.png\", {\n\t * \twidths: [400, 800, 1600],\n\t * });\n\t * // => https://example.imgix.net/image.png?width=400 400w,\n\t * // https://example.imgix.net/image.png?width=800 800w,\n\t * // https://example.imgix.net/image.png?width=1600 1600w\n\t * ```\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * const client = new SecureClient({\n\t * \tbaseURL: \"https://example.imgix.net\",\n\t * \tsecureURLToken: \"example-token\",\n\t * });\n\t * const srcset = client.buildWidthSrcSetForPath(\"/image.png\", {\n\t * \twidths: [400, 800, 1600],\n\t * \tsat: -100,\n\t * });\n\t * // => https://example.imgix.net/image.png?width=400&sat=-100 400w,\n\t * // https://example.imgix.net/image.png?width=800&sat=-100 800w,\n\t * // https://example.imgix.net/image.png?width=1600&sat=-100 1600w\n\t * ```\n\t *\n\t * @param path - Path to the image relative to the client's base URL.\n\t * @param params - An object of Imgix URL API parameters. The `widths`\n\t * parameter defines the resulting `srcset` widths.\n\t *\n\t * @returns A `srcset` attribute value for `url` with the given Imgix URL API\n\t * parameters applied.\n\t */\n\tbuildWidthSrcSetForPath(\n\t\tpath: string,\n\t\tparams: BuildWidthSrcSetParams,\n\t): string {\n\t\treturn buildWidthSrcSet(`${new URL(path, this.baseURL)}`, params);\n\t}\n\n\t/**\n\t * Builds an `<img>` `srcset` attribute value for a given set of widths for\n\t * the client's base URL. It can also optinally apply Imgix URL API parameters\n\t * to the URLs. The URLs are signed by appending a signature to their URL\n\t * parameters. This locks the URLs and their parameters to the signature to\n\t * prevent URL tampering.\n\t *\n\t * The `width` URL parameter will be applied for each `srcset` entry. If a\n\t * `width` or `w` parameter is provided to the `params` parameter, it will be ignored.\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * const client = new SecureClient({\n\t * \tbaseURL: \"https://example.imgix.net\",\n\t * \tsecureURLToken: \"example-token\",\n\t * });\n\t * const srcset = client.buildSignedWidthSrcSetForPath(\"/image.png\", {\n\t * \twidths: [400, 800, 1600],\n\t * });\n\t * // => https://example.imgix.net/image.png?width=400&s=def3e221c3f4c4debda091b8e49420ea 400w,\n\t * // https://example.imgix.net/image.png?width=800&s=f12c7c39333410c10c2930b57116a943 800w,\n\t * // https://example.imgix.net/image.png?width=1600&s=3a975b5087ab7ad2ab91fe66072fd628 1600w\n\t * ```\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * const client = new SecureClient({\n\t * \tbaseURL: \"https://example.imgix.net\",\n\t * \tsecureURLToken: \"example-token\",\n\t * });\n\t * const srcset = client.buildSignedWidthSrcSetForPath(\"/image.png\", {\n\t * \twidths: [400, 800, 1600],\n\t * \tsat: -100,\n\t * });\n\t * // => https://example.imgix.net/image.png?width=400&sat=-100&s=def3e221c3f4c4debda091b8e49420ea 400w,\n\t * // https://example.imgix.net/image.png?width=800&sat=-100&s=f12c7c39333410c10c2930b57116a943 800w,\n\t * // https://example.imgix.net/image.png?width=1600&sat=-100&s=3a975b5087ab7ad2ab91fe66072fd628 1600w\n\t * ```\n\t *\n\t * @param path - Path to the image relative to the client's base URL.\n\t * @param params - An object of Imgix URL API parameters. The `widths`\n\t * parameter defines the resulting `srcset` widths.\n\t *\n\t * @returns A `srcset` attribute value for `url` with the given Imgix URL API\n\t * parameters applied.\n\t */\n\tbuildSignedWidthSrcSetForPath(\n\t\tpath: string,\n\t\tparams: BuildWidthSrcSetParams,\n\t): string {\n\t\treturn this.buildSignedWidthSrcSet(\n\t\t\t`${new URL(path, this.baseURL)}`,\n\t\t\tparams,\n\t\t);\n\t}\n\n\t/**\n\t * Builds an `<img>` `srcset` attribute value for a given set of pixel\n\t * densities. It can also optinally apply Imgix URL API parameters to the\n\t * URLs. The URLs are signed by appending a signature to their URL parameters.\n\t * This locks the URLs and their parameters to the signature to prevent URL tampering.\n\t *\n\t * The `dpr` URL parameter will be applied for each `srcset` entry. If a `dpr`\n\t * parameter is provided to the `params` parameter, it will be ignored.\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * const srcset = client.buildSignedPixelDensitySrcSet(\n\t * \t\"https://example.imgix.net/image.png\",\n\t * \t{ pixelDensities: [1, 2, 3] },\n\t * );\n\t * // => https://example.imgix.net/image.png?dpr=1&s=def3e221c3f4c4debda091b8e49420ea 1x,\n\t * // https://example.imgix.net/image.png?dpr=2&s=f12c7c39333410c10c2930b57116a943 2x,\n\t * // https://example.imgix.net/image.png?dpr=3&s=3a975b5087ab7ad2ab91fe66072fd628 3x\n\t * ```\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * const srcset = client.buildSignedPixelDensitySrcSet(\n\t * \t\"https://example.imgix.net/image.png\",\n\t * \t{\n\t * \t\tpixelDensities: [1, 2, 3],\n\t * \t\tsat: -100,\n\t * \t},\n\t * );\n\t * // => https://example.imgix.net/image.png?dpr=1&sat=-100&s=def3e221c3f4c4debda091b8e49420ea 1x,\n\t * // https://example.imgix.net/image.png?dpr=2&sat=-100&s=f12c7c39333410c10c2930b57116a943 2x,\n\t * // https://example.imgix.net/image.png?dpr=3&sat=-100&s=3a975b5087ab7ad2ab91fe66072fd628 3x\n\t * ```\n\t *\n\t * @param url - Full absolute URL to the Imgix image.\n\t * @param params - An object of Imgix URL API parameters. The `pixelDensities`\n\t * parameter defines the resulting `srcset` widths.\n\t *\n\t * @returns A `srcset` attribute value for `url` with the given Imgix URL API\n\t * parameters applied.\n\t */\n\tbuildSignedPixelDensitySrcSet(\n\t\turl: string,\n\t\tparams: BuildPixelDensitySrcSetParams,\n\t): string {\n\t\treturn buildSignedPixelDensitySrcSet(url, this.secureURLToken, params);\n\t}\n\n\t/**\n\t * Builds an `<img>` `srcset` attribute value for a given set of pixel\n\t * densities for the client's base URL. It can also optinally apply Imgix URL\n\t * API parameters to the URLs.\n\t *\n\t * The `dpr` URL parameter will be applied for each `srcset` entry. If a `dpr`\n\t * parameter is provided to the `params` parameter, it will be ignored.\n\t *\n\t * Note: The returned URLs are not signed. See `buildSignedPixelDensitySrcSet`\n\t * if signatures are required.\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * const client = new SecureClient({\n\t * \tbaseURL: \"https://example.imgix.net\",\n\t * \tsecureURLToken: \"example-token\",\n\t * });\n\t * const srcset = client.buildPixelDensitySrcSetForPath(\"/image.png\", {\n\t * \tpixelDensities: [1, 2, 3],\n\t * });\n\t * // => https://example.imgix.net/image.png?dpr=1 1x,\n\t * // https://example.imgix.net/image.png?dpr=2 2x,\n\t * // https://example.imgix.net/image.png?dpr=3 3x\n\t * ```\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * const client = new SecureClient({\n\t * \tbaseURL: \"https://example.imgix.net\",\n\t * \tsecureURLToken: \"example-token\",\n\t * });\n\t * const srcset = client.buildPixelDensitySrcSetForPath(\"/image.png\", {\n\t * \tpixelDensities: [1, 2, 3],\n\t * \tsat: -100,\n\t * });\n\t * // => https://example.imgix.net/image.png?dpr=1&sat=-100 1x,\n\t * // https://example.imgix.net/image.png?dpr=2&sat=-100 2x,\n\t * // https://example.imgix.net/image.png?dpr=3&sat=-100 3x\n\t * ```\n\t *\n\t * @param path - Path to the image relative to the client's base URL.\n\t * @param params - An object of Imgix URL API parameters. The `pixelDensities`\n\t * parameter defines the resulting `srcset` widths.\n\t *\n\t * @returns A `srcset` attribute value for `url` with the given Imgix URL API\n\t * parameters applied.\n\t */\n\tbuildPixelDensitySrcSetForPath(\n\t\tpath: string,\n\t\tparams: BuildPixelDensitySrcSetParams,\n\t): string {\n\t\treturn buildPixelDensitySrcSet(`${new URL(path, this.baseURL)}`, params);\n\t}\n\n\t/**\n\t * Builds an `<img>` `srcset` attribute value for a given set of pixel\n\t * densities for the client's base URL. It can also optinally apply Imgix URL\n\t * API parameters to the URLs. The URLs are signed by appending a signature to\n\t * their URL parameters. This locks the URLs and their parameters to the\n\t * signature to prevent URL tampering.\n\t *\n\t * The `dpr` URL parameter will be applied for each `srcset` entry. If a `dpr`\n\t * parameter is provided to the `params` parameter, it will be ignored.\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * const client = new SecureClient({\n\t * \tbaseURL: \"https://example.imgix.net\",\n\t * \tsecureURLToken: \"example-token\",\n\t * });\n\t * const srcset = client.buildSignedPixelDensitySrcSetForPath(\n\t * \t\"/image.png\",\n\t * \t{ pixelDensities: [1, 2, 3] },\n\t * );\n\t * // => https://example.imgix.net/image.png?dpr=1&s=def3e221c3f4c4debda091b8e49420ea 1x,\n\t * // https://example.imgix.net/image.png?dpr=2&s=f12c7c39333410c10c2930b57116a943 2x,\n\t * // https://example.imgix.net/image.png?dpr=3&s=3a975b5087ab7ad2ab91fe66072fd628 3x\n\t * ```\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * const client = new SecureClient({\n\t * \tbaseURL: \"https://example.imgix.net\",\n\t * \tsecureURLToken: \"example-token\",\n\t * });\n\t * const srcset = client.buildSignedPixelDensitySrcSetForPath(\n\t * \t\"/image.png\",\n\t * \t{\n\t * \t\tpixelDensities: [1, 2, 3],\n\t * \t\tsat: -100,\n\t * \t},\n\t * );\n\t * // => https://example.imgix.net/image.png?dpr=1&sat=-100&s=def3e221c3f4c4debda091b8e49420ea 1x,\n\t * // https://example.imgix.net/image.png?dpr=2&sat=-100&s=f12c7c39333410c10c2930b57116a943 2x,\n\t * // https://example.imgix.net/image.png?dpr=3&sat=-100&s=3a975b5087ab7ad2ab91fe66072fd628 3x\n\t * ```\n\t *\n\t * @param path - Path to the image relative to the client's base URL.\n\t * @param params - An object of Imgix URL API parameters. The `pixelDensities`\n\t * parameter defines the resulting `srcset` widths.\n\t *\n\t * @returns A `srcset` attribute value for `url` with the given Imgix URL API\n\t * parameters applied.\n\t */\n\tbuildSignedPixelDensitySrcSetForPath(\n\t\tpath: string,\n\t\tparams: BuildPixelDensitySrcSetParams,\n\t): string {\n\t\treturn buildSignedPixelDensitySrcSet(\n\t\t\t`${new URL(path, this.baseURL)}`,\n\t\t\tthis.secureURLToken,\n\t\t\tparams,\n\t\t);\n\t}\n}\n"],"names":[],"mappings":"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"}
|
|
1
|
+
{"version":3,"file":"index.mjs","sources":["../../src/buildURL.ts","../../src/buildPixelDensitySrcSet.ts","../../src/node/signURL.ts","../../src/node/buildSignedURL.ts","../../src/node/buildSignedPixelDensitySrcSet.ts","../../src/node/buildSignedWidthSrcSet.ts","../../src/buildWidthSrcSet.ts","../../src/node/SecureClient.ts"],"sourcesContent":["import type { ImgixURLParams } from \"./types.generated\";\n\n/**\n * Converts a camel case string to a param case string.\n *\n * @example\n *\n * ```ts\n * camelCaseToParamCase(\"fooBar\");\n * // => 'foo-bar'\n * ```\n *\n * @param input - Camel case string to convert.\n *\n * @returns Param case version of `input`.\n */\nconst camelCaseToParamCase = (input: string): string => {\n\treturn input.replace(/[A-Z]/g, (match) => {\n\t\treturn `-${match.toLowerCase()}`;\n\t});\n};\n\n/**\n * Builds a URL to an Imgix image with Imgix URL API parameters.\n *\n * The given URL must be a full absolute URL containing the protocol and domain.\n *\n * URL parameters already applied to the image will be retained. To remove\n * existing parameters, set the parameter to `undefined` in the `params` argument.\n *\n * @example\n *\n * ```ts\n * const url = buildURL(\"https://example.imgix.net/image.png\", {\n * \twidth: 400,\n * });\n * // => https://example.imgix.net/image.png?width=400\n * ```\n *\n * @example\n *\n * ```ts\n * const url = buildURL(\"https://example.imgix.net/image.png?width=400\", {\n * \theight: 300,\n * });\n * // => https://example.imgix.net/image.png?width=400&height=300\n * ```\n *\n * @param url - Full absolute URL to the Imgix image.\n * @param params - An object of Imgix URL API parameters.\n *\n * @returns `url` with the given Imgix URL API parameters applied.\n *\n * @see Imgix URL API reference: https://docs.imgix.com/apis/rendering\n */\nexport const buildURL = (url: string, params: ImgixURLParams): string => {\n\tconst instance = new URL(url);\n\n\tfor (const camelCasedParamKey in params) {\n\t\tconst paramKey = camelCaseToParamCase(camelCasedParamKey);\n\t\tconst paramValue = params[camelCasedParamKey as keyof typeof params];\n\n\t\tif (paramValue === undefined) {\n\t\t\tinstance.searchParams.delete(paramKey);\n\t\t} else if (Array.isArray(paramValue)) {\n\t\t\tinstance.searchParams.set(paramKey, paramValue.join(\",\"));\n\t\t} else {\n\t\t\tinstance.searchParams.set(paramKey, `${paramValue}`);\n\t\t}\n\t}\n\n\t// Ensure the `s` parameter is the last parameter, if it exists.\n\t// @see https://github.com/imgix/imgix-blueprint#securing-urls\n\tconst s = instance.searchParams.get(\"s\");\n\tif (s) {\n\t\tinstance.searchParams.delete(\"s\");\n\t\tinstance.searchParams.append(\"s\", s);\n\t}\n\n\treturn instance.toString();\n};\n","import type { ImgixURLParams } from \"./types.generated\";\nimport { buildURL } from \"./buildURL\";\n\n/**\n * Parameters for `buildPixelDensitySrcSet`.\n */\nexport type BuildPixelDensitySrcSetParams = Omit<ImgixURLParams, \"dpr\"> & {\n\t/**\n\t * The pixel densities to include in the resulting `srcset` value.\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * [1, 2, 3];\n\t * ```\n\t */\n\tpixelDensities: number[];\n};\n\n/**\n * Builds an `<img>` `srcset` attribute value for a given set of pixel\n * densities. It can also optinally apply Imgix URL API parameters to the URLs.\n *\n * The `dpr` URL parameter will be applied for each `srcset` entry. If a `dpr`\n * parameter is provided to the `params` parameter, it will be ignored.\n *\n * @example\n *\n * ```ts\n * const srcset = buildPixelDensitySrcSet(\n * \t\"https://example.imgix.net/image.png\",\n * \t{ pixelDensities: [1, 2, 3] },\n * );\n * // => https://example.imgix.net/image.png?dpr=1 1x,\n * // https://example.imgix.net/image.png?dpr=2 2x,\n * // https://example.imgix.net/image.png?dpr=3 3x\n * ```\n *\n * @example\n *\n * ```ts\n * const srcset = buildPixelDensitySrcSet(\n * \t\"https://example.imgix.net/image.png\",\n * \t{\n * \t\tpixelDensities: [1, 2, 3],\n * \t\tsat: -100,\n * \t},\n * );\n * // => https://example.imgix.net/image.png?dpr=1&sat=-100 1x,\n * // https://example.imgix.net/image.png?dpr=2&sat=-100 2x,\n * // https://example.imgix.net/image.png?dpr=3&sat=-100 3x\n * ```\n *\n * @param url - Full absolute URL to the Imgix image.\n * @param params - An object of Imgix URL API parameters. The `pixelDensities`\n * parameter defines the resulting `srcset` widths.\n *\n * @returns A `srcset` attribute value for `url` with the given Imgix URL API\n * parameters applied.\n */\nexport const buildPixelDensitySrcSet = (\n\turl: string,\n\t{ pixelDensities, ...params }: BuildPixelDensitySrcSetParams,\n): string => {\n\treturn pixelDensities\n\t\t.map((dpr) => {\n\t\t\treturn `${buildURL(url, { ...params, dpr })} ${dpr}x`;\n\t\t})\n\t\t.join(\", \");\n};\n","import { createHash } from \"crypto\";\n\n/**\n * Signs an Imgix image URL by appending a signature to the URL parameters. This\n * locks the URL and its parameters to the signature to prevent URL tampering.\n *\n * **Important**: This function should only be used in a trusted environment and\n * never in a browser. The `secureURLToken` parameter is a secret and should not\n * be exposed to the public.\n *\n * @example\n *\n * ```ts\n * const url = signURL(\n * \t\"https://example.imgix.net/image.png?width=400\",\n * \t\"example-token\",\n * );\n * // => https://example.imgix.net/image.png?width=400&s=def3e221c3f4c4debda091b8e49420ea\n * ```\n *\n * @param url - Full absolute URL to the Imgix image to sign.\n * @param secureURLToken - The secret Imgix secure URL token used to generate\n * the signature.\n *\n * @returns `url` with a signature appended via an `s` URL parameter.\n *\n * @see Details on securing Imgix images: https://docs.imgix.com/setup/securing-images\n */\nexport const signURL = (url: string, secureURLToken: string): string => {\n\tconst instance = new URL(url);\n\n\t// If an `s` param is passed explicitly, it will be overridden. It must\n\t// also not be used when generating the signature.\n\tinstance.searchParams.delete(\"s\");\n\n\t// @see https://github.com/imgix/imgix-blueprint#securing-urls\n\tconst signature = createHash(\"md5\")\n\t\t.update(secureURLToken + instance.pathname + instance.search)\n\t\t.digest(\"hex\");\n\n\tinstance.searchParams.append(\"s\", signature);\n\n\treturn instance.toString();\n};\n","import type { ImgixURLParams } from \"../types.generated\";\nimport { buildURL } from \"../buildURL\";\nimport { signURL } from \"./signURL\";\n\n/**\n * Builds a URL to an Imgix image with Imgix URL API parameters. The URL is\n * signed by appending a signature to the URL parameters. This locks the URL and\n * its parameters to the signature to prevent URL tampering.\n *\n * The given URL must be a full absolute URL containing the protocol and domain.\n *\n * URL parameters already applied to the image will be retained. To remove\n * existing parameters, set the parameter to `undefined` in the `params` argument.\n *\n * **Important**: This function should only be used in a trusted environment and\n * never in a browser. The `secureURLToken` parameter is a secret and should not\n * be exposed to the public.\n *\n * @example\n *\n * ```ts\n * const url = buildSignedURL(\n * \t\"https://example.imgix.net/image.png\",\n * \t\"example-token\",\n * \t{ width: 400 },\n * );\n * // => https://example.imgix.net/image.png?width=400&s=def3e221c3f4c4debda091b8e49420ea\n * ```\n *\n * @example\n *\n * ```ts\n * const url = buildSignedURL(\n * \t\"https://example.imgix.net/image.png?width=400\",\n * \t\"example-token\",\n * \t{ height: 300 },\n * );\n * // => https://example.imgix.net/image.png?width=400&height=300&s=f12c7c39333410c10c2930b57116a943\n * ```\n *\n * @param url - Full absolute URL to the Imgix image.\n * @param secureURLToken - The secret secure URL token for the image's Imgix source.\n * @param params - An object of Imgix URL API parameters.\n *\n * @returns `url` with the given Imgix URL API parameters applied.\n *\n * @see Imgix URL API reference: https://docs.imgix.com/apis/rendering\n * @see Details on securing Imgix images: https://docs.imgix.com/setup/securing-images\n */\nexport const buildSignedURL = (\n\turl: string,\n\tsecureURLToken: string,\n\tparams: ImgixURLParams,\n): string => {\n\treturn signURL(buildURL(url, params), secureURLToken);\n};\n","import type { BuildPixelDensitySrcSetParams } from \"../buildPixelDensitySrcSet\";\nimport { buildSignedURL } from \"./buildSignedURL\";\n\n/**\n * Builds an `<img>` `srcset` attribute value for a given set of pixel\n * densities. It can also optinally apply Imgix URL API parameters to the URLs.\n * The URLs are signed by appending a signature to their URL parameters. This\n * locks the URLs and their parameters to the signature to prevent URL tampering.\n *\n * The `dpr` URL parameter will be applied for each `srcset` entry. If a `dpr`\n * parameter is provided to the `params` parameter, it will be ignored.\n *\n * **Important**: This function should only be used in a trusted environment and\n * never in a browser. The `secureURLToken` parameter is a secret and should not\n * be exposed to the public.\n *\n * @example\n *\n * ```ts\n * const srcset = buildSignedPixelDensitySrcSet(\n * \t\"https://example.imgix.net/image.png\",\n * \t\"example-token\",\n * \t{ pixelDensities: [1, 2, 3] },\n * );\n * // => https://example.imgix.net/image.png?dpr=1&s=def3e221c3f4c4debda091b8e49420ea 1x,\n * // https://example.imgix.net/image.png?dpr=2&s=f12c7c39333410c10c2930b57116a943 2x,\n * // https://example.imgix.net/image.png?dpr=3&s=3a975b5087ab7ad2ab91fe66072fd628 3x\n * ```\n *\n * @example\n *\n * ```ts\n * const srcset = buildSignedPixelDensitySrcSet(\n * \t\"https://example.imgix.net/image.png\",\n * \t\"example-token\",\n * \t{\n * \t\tpixelDensities: [1, 2, 3],\n * \t\tsat: -100,\n * \t},\n * );\n * // => https://example.imgix.net/image.png?dpr=1&sat=-100&s=def3e221c3f4c4debda091b8e49420ea 1x,\n * // https://example.imgix.net/image.png?dpr=2&sat=-100&s=f12c7c39333410c10c2930b57116a943 2x,\n * // https://example.imgix.net/image.png?dpr=3&sat=-100&s=3a975b5087ab7ad2ab91fe66072fd628 3x\n * ```\n *\n * @param url - Full absolute URL to the Imgix image.\n * @param secureURLToken - The secret secure URL token for the image's Imgix source.\n * @param params - An object of Imgix URL API parameters. The `pixelDensities`\n * parameter defines the resulting `srcset` widths.\n *\n * @returns A `srcset` attribute value for `url` with the given Imgix URL API\n * parameters applied.\n */\nexport const buildSignedPixelDensitySrcSet = (\n\turl: string,\n\tsecureURLToken: string,\n\t{ pixelDensities, ...params }: BuildPixelDensitySrcSetParams,\n): string => {\n\treturn pixelDensities\n\t\t.map((dpr) => {\n\t\t\treturn `${buildSignedURL(url, secureURLToken, {\n\t\t\t\t...params,\n\t\t\t\tdpr,\n\t\t\t})} ${dpr}x`;\n\t\t})\n\t\t.join(\", \");\n};\n","import type { BuildWidthSrcSetParams } from \"../buildWidthSrcSet\";\nimport { buildSignedURL } from \"./buildSignedURL\";\n\n/**\n * Builds an `<img>` `srcset` attribute value for a given set of widths. It can\n * also optinally apply Imgix URL API parameters to the URLs. The URLs are\n * signed by appending a signature to their URL parameters. This locks the URLs\n * and their parameters to the signature to prevent URL tampering.\n *\n * The `width` URL parameter will be applied for each `srcset` entry. If a\n * `width` or `w` parameter is provided to the `params` parameter, it will be ignored.\n *\n * **Important**: This function should only be used in a trusted environment and\n * never in a browser. The `secureURLToken` parameter is a secret and should not\n * be exposed to the public.\n *\n * @example\n *\n * ```ts\n * const srcset = buildSignedWidthSrcSet(\n * \t\"https://example.imgix.net/image.png\",\n * \t\"example-token\",\n * \t{ widths: [400, 800, 1600] },\n * );\n * // => https://example.imgix.net/image.png?width=400&s=def3e221c3f4c4debda091b8e49420ea 400w,\n * // https://example.imgix.net/image.png?width=800&s=f12c7c39333410c10c2930b57116a943 800w,\n * // https://example.imgix.net/image.png?width=1600&s=3a975b5087ab7ad2ab91fe66072fd628 1600w\n * ```\n *\n * @example\n *\n * ```ts\n * const srcset = buildSignedWidthSrcSet(\n * \t\"https://example.imgix.net/image.png\",\n * \t\"example-token\",\n * \t{\n * \t\twidths: [400, 800, 1600],\n * \t\tsat: -100,\n * \t},\n * );\n * // => https://example.imgix.net/image.png?width=400&sat=-100&s=def3e221c3f4c4debda091b8e49420ea 400w,\n * // https://example.imgix.net/image.png?width=800&sat=-100&s=f12c7c39333410c10c2930b57116a943 800w,\n * // https://example.imgix.net/image.png?width=1600&sat=-100&s=3a975b5087ab7ad2ab91fe66072fd628 1600w\n * ```\n *\n * @param url - Full absolute URL to the Imgix image.\n * @param secureURLToken - The secret secure URL token for the image's Imgix source.\n * @param params - An object of Imgix URL API parameters. The `widths` parameter\n * defines the resulting `srcset` widths.\n *\n * @returns A `srcset` attribute value for `url` with the given Imgix URL API\n * parameters applied.\n */\nexport const buildSignedWidthSrcSet = (\n\turl: string,\n\tsecureURLToken: string,\n\t{ widths, ...params }: BuildWidthSrcSetParams,\n): string => {\n\treturn widths\n\t\t.map((width) => {\n\t\t\treturn `${buildSignedURL(url, secureURLToken, {\n\t\t\t\t...params,\n\t\t\t\tw: undefined,\n\t\t\t\twidth,\n\t\t\t})} ${width}w`;\n\t\t})\n\t\t.join(\", \");\n};\n","import type { ImgixURLParams } from \"./types.generated\";\nimport { buildURL } from \"./buildURL\";\n\n/**\n * Parameters for `buildWidthSrcSet`.\n */\nexport type BuildWidthSrcSetParams = Omit<ImgixURLParams, \"width\" | \"w\"> & {\n\t/**\n\t * The pixel widths to include in the resulting `srcset` value.\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * [400, 800, 1600];\n\t * ```\n\t */\n\twidths: number[];\n};\n\n/**\n * Builds an `<img>` `srcset` attribute value for a given set of widths. It can\n * also optinally apply Imgix URL API parameters to the URLs.\n *\n * The `width` URL parameter will be applied for each `srcset` entry. If a\n * `width` or `w` parameter is provided to the `params` parameter, it will be ignored.\n *\n * @example\n *\n * ```ts\n * const srcset = buildWidthSrcSet(\"https://example.imgix.net/image.png\", {\n * \twidths: [400, 800, 1600],\n * });\n * // => https://example.imgix.net/image.png?width=400 400w,\n * // https://example.imgix.net/image.png?width=800 800w,\n * // https://example.imgix.net/image.png?width=1600 1600w\n * ```\n *\n * @example\n *\n * ```ts\n * const srcset = buildWidthSrcSet(\"https://example.imgix.net/image.png\", {\n * \twidths: [400, 800, 1600],\n * \tsat: -100,\n * });\n * // => https://example.imgix.net/image.png?width=400&sat=-100 400w,\n * // https://example.imgix.net/image.png?width=800&sat=-100 800w,\n * // https://example.imgix.net/image.png?width=1600&sat=-100 1600w\n * ```\n *\n * @param url - Full absolute URL to the Imgix image.\n * @param params - An object of Imgix URL API parameters. The `widths` parameter\n * defines the resulting `srcset` widths.\n *\n * @returns A `srcset` attribute value for `url` with the given Imgix URL API\n * parameters applied.\n */\nexport const buildWidthSrcSet = (\n\turl: string,\n\t{ widths, ...params }: BuildWidthSrcSetParams,\n): string => {\n\treturn widths\n\t\t.map((width) => {\n\t\t\treturn `${buildURL(url, { ...params, w: undefined, width })} ${width}w`;\n\t\t})\n\t\t.join(\", \");\n};\n","import type { BuildPixelDensitySrcSetParams } from \"../buildPixelDensitySrcSet\";\nimport type { BuildWidthSrcSetParams } from \"../buildWidthSrcSet\";\nimport type { ImgixURLParams } from \"../types.generated\";\nimport { buildPixelDensitySrcSet } from \"../buildPixelDensitySrcSet\";\nimport { buildSignedPixelDensitySrcSet } from \"./buildSignedPixelDensitySrcSet\";\nimport { buildSignedURL } from \"./buildSignedURL\";\nimport { buildSignedWidthSrcSet } from \"./buildSignedWidthSrcSet\";\nimport { buildURL } from \"../buildURL\";\nimport { buildWidthSrcSet } from \"../buildWidthSrcSet\";\nimport { signURL } from \"./signURL\";\n\n/**\n * Options to instantiate a new secure client.\n */\nexport type SecureClientOptions = {\n\t/**\n\t * The base URL used to construct image URLs from a path. The base URL must\n\t * include the protocol, domain, and optionally a path.\n\t *\n\t * @example `https://example.imgix.net`\n\t *\n\t * @example `https://example.imgix.net/folder`\n\t */\n\tbaseURL: string;\n\n\t/**\n\t * The secret secure URL token for the configured Imgix domain.\n\t *\n\t * @see How to get a token: https://docs.imgix.com/setup/securing-images\n\t */\n\tsecureURLToken: string;\n};\n\n/**\n * An Imgix Rendering API client with automatic URL signing. A client is paired\n * to a single Imgix domain and secure URL token.\n *\n * **Important**: This client should only be used in a trusted environment and\n * never in a browser. The `secureURLToken` parameter is a secret and should not\n * be exposed to the public.\n */\nexport class SecureClient {\n\t/**\n\t * The base URL used to construct image URLs from a path. The base URL must\n\t * include the protocol, domain, and optionally a path.\n\t */\n\tbaseURL: string;\n\n\t/**\n\t * The secret secure URL token for the configured Imgix domain.\n\t */\n\tsecureURLToken: string;\n\n\t/**\n\t * Creates a new `SecureClient` instance for an Imgix domain.\n\t *\n\t * @param options - Options to instantiate a new client.\n\t *\n\t * @returns A `SecureClient` instance for the given Imgix domain.\n\t */\n\tconstructor(options: SecureClientOptions) {\n\t\tthis.baseURL = options.baseURL;\n\t\tthis.secureURLToken = options.secureURLToken;\n\t}\n\n\t/**\n\t * Builds a Web Proxy URL that proxies a non-Imgix URL to Imgix. The client's\n\t * Imgix domain must be configured as a Web Proxy source. All Web Proxy URLs\n\t * will be signed automatically.\n\t *\n\t * **Important**: The given URL must not be URI encoded. If it is, decode it\n\t * before passing it to `buildWebProxyURL()`.\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * const client = new SecureClient({\n\t * \tbaseURL: \"https://example.imgix.net\",\n\t * \tsecureURLToken: \"example-token\",\n\t * });\n\t * const url = client.buildWebProxyURL(\"https://www.this.com/pic.jpg\", {\n\t * \twidth: 400,\n\t * });\n\t * // => https://example.imgix.net/https%3A%2F%2Fwww.this.com%2Fpic.jpg?width=400&s=def3e221c3f4c4debda091b8e49420ea\n\t * ```\n\t *\n\t * @param url - Full absolute URL to the source image to proxy.\n\t * @param params - An object of Imgix URL API parameters.\n\t *\n\t * @returns An Imgix url proxying `url` to the client's Imgix domain.\n\t */\n\tbuildWebProxyURL(url: string, params: ImgixURLParams = {}): string {\n\t\treturn this.buildSignedURLForPath(encodeURIComponent(url), params);\n\t}\n\n\t/**\n\t * Builds a URL to an Imgix image with Imgix URL API parameters for the\n\t * client's base URL.\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * const client = new SecureClient({\n\t * \tbaseURL: \"https://example.imgix.net\",\n\t * \tsecureURLToken: \"example-token\",\n\t * });\n\t * const url = client.buildURLForPath(\"/image.png\", { width: 400 });\n\t * // => https://example.imgix.net/image.png?width=400&s=def3e221c3f4c4debda091b8e49420ea\n\t * ```\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * const client = new SecureClient({\n\t * \tbaseURL: \"https://example.imgix.net/folder\",\n\t * \tsecureURLToken: \"example-token\",\n\t * });\n\t * const url = client.buildURLForPath(\"./image.png\", { width: 400 });\n\t * // => https://example.imgix.net/folder/image.png?width=400&s=f12c7c39333410c10c2930b57116a943\n\t * ```\n\t *\n\t * @param path - Path to the image relative to the client's base URL.\n\t * @param params - An object of Imgix URL API parameters.\n\t *\n\t * @returns The full absolute URL to the image with the given Imgix URL API\n\t * parameters applied.\n\t */\n\tbuildSignedURLForPath(path: string, params: ImgixURLParams = {}): string {\n\t\treturn this.signURL(this.buildURLForPath(path, params));\n\t}\n\n\t/**\n\t * Builds a URL to an Imgix image with Imgix URL API parameters for the\n\t * client's base URL.\n\t *\n\t * Note: The returned URL is not signed. See `buildSignedURL` if a signature\n\t * is required.\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * const client = new SecureClient({\n\t * \tbaseURL: \"https://example.imgix.net\",\n\t * \tsecureURLToken: \"example-token\",\n\t * });\n\t * const url = client.buildURLForPath(\"/image.png\", { width: 400 });\n\t * // => https://example.imgix.net/image.png?width=400\n\t * ```\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * const client = new SecureClient({\n\t * \tbaseURL: \"https://example.imgix.net/folder\",\n\t * \tsecureURLToken: \"example-token\",\n\t * });\n\t * const url = client.buildURLForPath(\"./image.png\", { width: 400 });\n\t * // => https://example.imgix.net/folder/image.png?width=400\n\t * ```\n\t *\n\t * @param path - Path to the image relative to the client's base URL.\n\t * @param params - An object of Imgix URL API parameters.\n\t *\n\t * @returns The full absolute URL to the image with the given Imgix URL API\n\t * parameters applied.\n\t */\n\tbuildURLForPath(path: string, params: ImgixURLParams = {}): string {\n\t\treturn buildURL(`${new URL(path, this.baseURL)}`, params);\n\t}\n\n\t/**\n\t * Builds a URL to an Imgix image with Imgix URL API parameters. The URL is\n\t * signed by appending a signature to the URL parameters. This locks the URL\n\t * and its parameters to the signature to prevent URL tampering.\n\t *\n\t * The given URL must be a full absolute URL containing the protocol and domain.\n\t *\n\t * URL parameters already applied to the image will be retained. To remove\n\t * existing parameters, set the parameter to `undefined` in the `params` argument.\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * const url = client.buildSignedURL(\n\t * \t\"https://example.imgix.net/image.png\",\n\t * \t{ width: 400 },\n\t * );\n\t * // => https://example.imgix.net/image.png?width=400&s=def3e221c3f4c4debda091b8e49420ea\n\t * ```\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * const url = client.buildSignedURL(\n\t * \t\"https://example.imgix.net/image.png?width=400\",\n\t * \t{ height: 300 },\n\t * );\n\t * // => https://example.imgix.net/image.png?width=400&height=300&s=f12c7c39333410c10c2930b57116a943\n\t * ```\n\t *\n\t * @param url - Full absolute URL to the Imgix image.\n\t * @param params - An object of Imgix URL API parameters.\n\t *\n\t * @returns `url` with the given Imgix URL API parameters applied.\n\t *\n\t * @see Imgix URL API reference: https://docs.imgix.com/apis/rendering\n\t * @see Details on securing Imgix images: https://docs.imgix.com/setup/securing-images\n\t */\n\tbuildSignedURL(url: string, params: ImgixURLParams = {}): string {\n\t\treturn buildSignedURL(url, this.secureURLToken, params);\n\t}\n\n\t/**\n\t * Signs an Imgix image URL by appending a signature to the URL parameters.\n\t * This locks the URL and its parameters to the signature to prevent URL tampering.\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * const url = client.signURL(\n\t * \t\"https://example.imgix.net/image.png?width=400\",\n\t * );\n\t * // => https://example.imgix.net/image.png?width=400&s=def3e221c3f4c4debda091b8e49420ea\n\t * ```\n\t *\n\t * @param url - Full absolute URL to the Imgix image to sign.\n\t *\n\t * @returns `url` with a signature appended via an `s` URL parameter.\n\t *\n\t * @see Details on securing Imgix images: https://docs.imgix.com/setup/securing-images\n\t */\n\tsignURL(url: string): string {\n\t\treturn signURL(url, this.secureURLToken);\n\t}\n\n\t/**\n\t * Builds an `<img>` `srcset` attribute value for a given set of widths. It\n\t * can also optinally apply Imgix URL API parameters to the URLs. The URLs are\n\t * signed by appending a signature to their URL parameters. This locks the\n\t * URLs and their parameters to the signature to prevent URL tampering.\n\t *\n\t * The `width` URL parameter will be applied for each `srcset` entry. If a\n\t * `width` or `w` parameter is provided to the `params` parameter, it will be ignored.\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * const srcset = client.buildSignedWidthSrcSet(\n\t * \t\"https://example.imgix.net/image.png\",\n\t * \t{ widths: [400, 800, 1600] },\n\t * );\n\t * // => https://example.imgix.net/image.png?width=400&s=def3e221c3f4c4debda091b8e49420ea 400w,\n\t * // https://example.imgix.net/image.png?width=800&s=f12c7c39333410c10c2930b57116a943 800w,\n\t * // https://example.imgix.net/image.png?width=1600&s=3a975b5087ab7ad2ab91fe66072fd628 1600w\n\t * ```\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * const srcset = client.buildSignedWidthSrcSet(\n\t * \t\"https://example.imgix.net/image.png\",\n\t * \t{\n\t * \t\twidths: [400, 800, 1600],\n\t * \t\tsat: -100,\n\t * \t},\n\t * );\n\t * // => https://example.imgix.net/image.png?width=400&sat=-100&s=def3e221c3f4c4debda091b8e49420ea 400w,\n\t * // https://example.imgix.net/image.png?width=800&sat=-100&s=f12c7c39333410c10c2930b57116a943 800w,\n\t * // https://example.imgix.net/image.png?width=1600&sat=-100&s=3a975b5087ab7ad2ab91fe66072fd628 1600w\n\t * ```\n\t *\n\t * @param url - Full absolute URL to the Imgix image.\n\t * @param params - An object of Imgix URL API parameters. The `widths`\n\t * parameter defines the resulting `srcset` widths.\n\t *\n\t * @returns A `srcset` attribute value for `url` with the given Imgix URL API\n\t * parameters applied.\n\t */\n\tbuildSignedWidthSrcSet(url: string, params: BuildWidthSrcSetParams): string {\n\t\treturn buildSignedWidthSrcSet(url, this.secureURLToken, params);\n\t}\n\n\t/**\n\t * Builds an `<img>` `srcset` attribute value for a given set of widths for\n\t * the client's base URL. It can also optinally apply Imgix URL API parameters\n\t * to the URLs.\n\t *\n\t * The `width` URL parameter will be applied for each `srcset` entry. If a\n\t * `width` or `w` parameter is provided to the `params` parameter, it will be ignored.\n\t *\n\t * Note: The returned URLs are not signed. See `buildSignedWidthSrcSet` if\n\t * signatures are required.\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * const client = new SecureClient({\n\t * \tbaseURL: \"https://example.imgix.net\",\n\t * \tsecureURLToken: \"example-token\",\n\t * });\n\t * const srcset = client.buildWidthSrcSetForPath(\"/image.png\", {\n\t * \twidths: [400, 800, 1600],\n\t * });\n\t * // => https://example.imgix.net/image.png?width=400 400w,\n\t * // https://example.imgix.net/image.png?width=800 800w,\n\t * // https://example.imgix.net/image.png?width=1600 1600w\n\t * ```\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * const client = new SecureClient({\n\t * \tbaseURL: \"https://example.imgix.net\",\n\t * \tsecureURLToken: \"example-token\",\n\t * });\n\t * const srcset = client.buildWidthSrcSetForPath(\"/image.png\", {\n\t * \twidths: [400, 800, 1600],\n\t * \tsat: -100,\n\t * });\n\t * // => https://example.imgix.net/image.png?width=400&sat=-100 400w,\n\t * // https://example.imgix.net/image.png?width=800&sat=-100 800w,\n\t * // https://example.imgix.net/image.png?width=1600&sat=-100 1600w\n\t * ```\n\t *\n\t * @param path - Path to the image relative to the client's base URL.\n\t * @param params - An object of Imgix URL API parameters. The `widths`\n\t * parameter defines the resulting `srcset` widths.\n\t *\n\t * @returns A `srcset` attribute value for `url` with the given Imgix URL API\n\t * parameters applied.\n\t */\n\tbuildWidthSrcSetForPath(\n\t\tpath: string,\n\t\tparams: BuildWidthSrcSetParams,\n\t): string {\n\t\treturn buildWidthSrcSet(`${new URL(path, this.baseURL)}`, params);\n\t}\n\n\t/**\n\t * Builds an `<img>` `srcset` attribute value for a given set of widths for\n\t * the client's base URL. It can also optinally apply Imgix URL API parameters\n\t * to the URLs. The URLs are signed by appending a signature to their URL\n\t * parameters. This locks the URLs and their parameters to the signature to\n\t * prevent URL tampering.\n\t *\n\t * The `width` URL parameter will be applied for each `srcset` entry. If a\n\t * `width` or `w` parameter is provided to the `params` parameter, it will be ignored.\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * const client = new SecureClient({\n\t * \tbaseURL: \"https://example.imgix.net\",\n\t * \tsecureURLToken: \"example-token\",\n\t * });\n\t * const srcset = client.buildSignedWidthSrcSetForPath(\"/image.png\", {\n\t * \twidths: [400, 800, 1600],\n\t * });\n\t * // => https://example.imgix.net/image.png?width=400&s=def3e221c3f4c4debda091b8e49420ea 400w,\n\t * // https://example.imgix.net/image.png?width=800&s=f12c7c39333410c10c2930b57116a943 800w,\n\t * // https://example.imgix.net/image.png?width=1600&s=3a975b5087ab7ad2ab91fe66072fd628 1600w\n\t * ```\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * const client = new SecureClient({\n\t * \tbaseURL: \"https://example.imgix.net\",\n\t * \tsecureURLToken: \"example-token\",\n\t * });\n\t * const srcset = client.buildSignedWidthSrcSetForPath(\"/image.png\", {\n\t * \twidths: [400, 800, 1600],\n\t * \tsat: -100,\n\t * });\n\t * // => https://example.imgix.net/image.png?width=400&sat=-100&s=def3e221c3f4c4debda091b8e49420ea 400w,\n\t * // https://example.imgix.net/image.png?width=800&sat=-100&s=f12c7c39333410c10c2930b57116a943 800w,\n\t * // https://example.imgix.net/image.png?width=1600&sat=-100&s=3a975b5087ab7ad2ab91fe66072fd628 1600w\n\t * ```\n\t *\n\t * @param path - Path to the image relative to the client's base URL.\n\t * @param params - An object of Imgix URL API parameters. The `widths`\n\t * parameter defines the resulting `srcset` widths.\n\t *\n\t * @returns A `srcset` attribute value for `url` with the given Imgix URL API\n\t * parameters applied.\n\t */\n\tbuildSignedWidthSrcSetForPath(\n\t\tpath: string,\n\t\tparams: BuildWidthSrcSetParams,\n\t): string {\n\t\treturn this.buildSignedWidthSrcSet(\n\t\t\t`${new URL(path, this.baseURL)}`,\n\t\t\tparams,\n\t\t);\n\t}\n\n\t/**\n\t * Builds an `<img>` `srcset` attribute value for a given set of pixel\n\t * densities. It can also optinally apply Imgix URL API parameters to the\n\t * URLs. The URLs are signed by appending a signature to their URL parameters.\n\t * This locks the URLs and their parameters to the signature to prevent URL tampering.\n\t *\n\t * The `dpr` URL parameter will be applied for each `srcset` entry. If a `dpr`\n\t * parameter is provided to the `params` parameter, it will be ignored.\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * const srcset = client.buildSignedPixelDensitySrcSet(\n\t * \t\"https://example.imgix.net/image.png\",\n\t * \t{ pixelDensities: [1, 2, 3] },\n\t * );\n\t * // => https://example.imgix.net/image.png?dpr=1&s=def3e221c3f4c4debda091b8e49420ea 1x,\n\t * // https://example.imgix.net/image.png?dpr=2&s=f12c7c39333410c10c2930b57116a943 2x,\n\t * // https://example.imgix.net/image.png?dpr=3&s=3a975b5087ab7ad2ab91fe66072fd628 3x\n\t * ```\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * const srcset = client.buildSignedPixelDensitySrcSet(\n\t * \t\"https://example.imgix.net/image.png\",\n\t * \t{\n\t * \t\tpixelDensities: [1, 2, 3],\n\t * \t\tsat: -100,\n\t * \t},\n\t * );\n\t * // => https://example.imgix.net/image.png?dpr=1&sat=-100&s=def3e221c3f4c4debda091b8e49420ea 1x,\n\t * // https://example.imgix.net/image.png?dpr=2&sat=-100&s=f12c7c39333410c10c2930b57116a943 2x,\n\t * // https://example.imgix.net/image.png?dpr=3&sat=-100&s=3a975b5087ab7ad2ab91fe66072fd628 3x\n\t * ```\n\t *\n\t * @param url - Full absolute URL to the Imgix image.\n\t * @param params - An object of Imgix URL API parameters. The `pixelDensities`\n\t * parameter defines the resulting `srcset` widths.\n\t *\n\t * @returns A `srcset` attribute value for `url` with the given Imgix URL API\n\t * parameters applied.\n\t */\n\tbuildSignedPixelDensitySrcSet(\n\t\turl: string,\n\t\tparams: BuildPixelDensitySrcSetParams,\n\t): string {\n\t\treturn buildSignedPixelDensitySrcSet(url, this.secureURLToken, params);\n\t}\n\n\t/**\n\t * Builds an `<img>` `srcset` attribute value for a given set of pixel\n\t * densities for the client's base URL. It can also optinally apply Imgix URL\n\t * API parameters to the URLs.\n\t *\n\t * The `dpr` URL parameter will be applied for each `srcset` entry. If a `dpr`\n\t * parameter is provided to the `params` parameter, it will be ignored.\n\t *\n\t * Note: The returned URLs are not signed. See `buildSignedPixelDensitySrcSet`\n\t * if signatures are required.\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * const client = new SecureClient({\n\t * \tbaseURL: \"https://example.imgix.net\",\n\t * \tsecureURLToken: \"example-token\",\n\t * });\n\t * const srcset = client.buildPixelDensitySrcSetForPath(\"/image.png\", {\n\t * \tpixelDensities: [1, 2, 3],\n\t * });\n\t * // => https://example.imgix.net/image.png?dpr=1 1x,\n\t * // https://example.imgix.net/image.png?dpr=2 2x,\n\t * // https://example.imgix.net/image.png?dpr=3 3x\n\t * ```\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * const client = new SecureClient({\n\t * \tbaseURL: \"https://example.imgix.net\",\n\t * \tsecureURLToken: \"example-token\",\n\t * });\n\t * const srcset = client.buildPixelDensitySrcSetForPath(\"/image.png\", {\n\t * \tpixelDensities: [1, 2, 3],\n\t * \tsat: -100,\n\t * });\n\t * // => https://example.imgix.net/image.png?dpr=1&sat=-100 1x,\n\t * // https://example.imgix.net/image.png?dpr=2&sat=-100 2x,\n\t * // https://example.imgix.net/image.png?dpr=3&sat=-100 3x\n\t * ```\n\t *\n\t * @param path - Path to the image relative to the client's base URL.\n\t * @param params - An object of Imgix URL API parameters. The `pixelDensities`\n\t * parameter defines the resulting `srcset` widths.\n\t *\n\t * @returns A `srcset` attribute value for `url` with the given Imgix URL API\n\t * parameters applied.\n\t */\n\tbuildPixelDensitySrcSetForPath(\n\t\tpath: string,\n\t\tparams: BuildPixelDensitySrcSetParams,\n\t): string {\n\t\treturn buildPixelDensitySrcSet(`${new URL(path, this.baseURL)}`, params);\n\t}\n\n\t/**\n\t * Builds an `<img>` `srcset` attribute value for a given set of pixel\n\t * densities for the client's base URL. It can also optinally apply Imgix URL\n\t * API parameters to the URLs. The URLs are signed by appending a signature to\n\t * their URL parameters. This locks the URLs and their parameters to the\n\t * signature to prevent URL tampering.\n\t *\n\t * The `dpr` URL parameter will be applied for each `srcset` entry. If a `dpr`\n\t * parameter is provided to the `params` parameter, it will be ignored.\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * const client = new SecureClient({\n\t * \tbaseURL: \"https://example.imgix.net\",\n\t * \tsecureURLToken: \"example-token\",\n\t * });\n\t * const srcset = client.buildSignedPixelDensitySrcSetForPath(\n\t * \t\"/image.png\",\n\t * \t{ pixelDensities: [1, 2, 3] },\n\t * );\n\t * // => https://example.imgix.net/image.png?dpr=1&s=def3e221c3f4c4debda091b8e49420ea 1x,\n\t * // https://example.imgix.net/image.png?dpr=2&s=f12c7c39333410c10c2930b57116a943 2x,\n\t * // https://example.imgix.net/image.png?dpr=3&s=3a975b5087ab7ad2ab91fe66072fd628 3x\n\t * ```\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * const client = new SecureClient({\n\t * \tbaseURL: \"https://example.imgix.net\",\n\t * \tsecureURLToken: \"example-token\",\n\t * });\n\t * const srcset = client.buildSignedPixelDensitySrcSetForPath(\n\t * \t\"/image.png\",\n\t * \t{\n\t * \t\tpixelDensities: [1, 2, 3],\n\t * \t\tsat: -100,\n\t * \t},\n\t * );\n\t * // => https://example.imgix.net/image.png?dpr=1&sat=-100&s=def3e221c3f4c4debda091b8e49420ea 1x,\n\t * // https://example.imgix.net/image.png?dpr=2&sat=-100&s=f12c7c39333410c10c2930b57116a943 2x,\n\t * // https://example.imgix.net/image.png?dpr=3&sat=-100&s=3a975b5087ab7ad2ab91fe66072fd628 3x\n\t * ```\n\t *\n\t * @param path - Path to the image relative to the client's base URL.\n\t * @param params - An object of Imgix URL API parameters. The `pixelDensities`\n\t * parameter defines the resulting `srcset` widths.\n\t *\n\t * @returns A `srcset` attribute value for `url` with the given Imgix URL API\n\t * parameters applied.\n\t */\n\tbuildSignedPixelDensitySrcSetForPath(\n\t\tpath: string,\n\t\tparams: BuildPixelDensitySrcSetParams,\n\t): string {\n\t\treturn buildSignedPixelDensitySrcSet(\n\t\t\t`${new URL(path, this.baseURL)}`,\n\t\t\tthis.secureURLToken,\n\t\t\tparams,\n\t\t);\n\t}\n}\n"],"names":[],"mappings":"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"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "imgix-url-builder",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.2",
|
|
4
4
|
"description": "JavaScript/TypeScript Imgix URL builders for browsers and Node.js",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"typescript",
|
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
},
|
|
13
13
|
"license": "Apache-2.0",
|
|
14
14
|
"author": "Prismic <contact@prismic.io> (https://prismic.io)",
|
|
15
|
+
"sideEffects": false,
|
|
15
16
|
"type": "module",
|
|
16
17
|
"exports": {
|
|
17
18
|
".": {
|
|
@@ -46,10 +47,6 @@
|
|
|
46
47
|
"test": "npm run lint && npm run unit && npm run build && npm run size",
|
|
47
48
|
"unit": "nyc --reporter=lcovonly --reporter=text --exclude-after-remap=false ava"
|
|
48
49
|
},
|
|
49
|
-
"dependencies": {
|
|
50
|
-
"camel-case": "^4.1.2",
|
|
51
|
-
"param-case": "^3.0.4"
|
|
52
|
-
},
|
|
53
50
|
"devDependencies": {
|
|
54
51
|
"@size-limit/preset-small-lib": "^7.0.5",
|
|
55
52
|
"@types/prettier": "^2.4.3",
|
package/src/buildURL.ts
CHANGED
|
@@ -1,7 +1,25 @@
|
|
|
1
|
-
import { paramCase } from "param-case";
|
|
2
|
-
|
|
3
1
|
import type { ImgixURLParams } from "./types.generated";
|
|
4
2
|
|
|
3
|
+
/**
|
|
4
|
+
* Converts a camel case string to a param case string.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
*
|
|
8
|
+
* ```ts
|
|
9
|
+
* camelCaseToParamCase("fooBar");
|
|
10
|
+
* // => 'foo-bar'
|
|
11
|
+
* ```
|
|
12
|
+
*
|
|
13
|
+
* @param input - Camel case string to convert.
|
|
14
|
+
*
|
|
15
|
+
* @returns Param case version of `input`.
|
|
16
|
+
*/
|
|
17
|
+
const camelCaseToParamCase = (input: string): string => {
|
|
18
|
+
return input.replace(/[A-Z]/g, (match) => {
|
|
19
|
+
return `-${match.toLowerCase()}`;
|
|
20
|
+
});
|
|
21
|
+
};
|
|
22
|
+
|
|
5
23
|
/**
|
|
6
24
|
* Builds a URL to an Imgix image with Imgix URL API parameters.
|
|
7
25
|
*
|
|
@@ -39,7 +57,7 @@ export const buildURL = (url: string, params: ImgixURLParams): string => {
|
|
|
39
57
|
const instance = new URL(url);
|
|
40
58
|
|
|
41
59
|
for (const camelCasedParamKey in params) {
|
|
42
|
-
const paramKey =
|
|
60
|
+
const paramKey = camelCaseToParamCase(camelCasedParamKey);
|
|
43
61
|
const paramValue = params[camelCasedParamKey as keyof typeof params];
|
|
44
62
|
|
|
45
63
|
if (paramValue === undefined) {
|