imgix-url-builder 0.0.5 → 0.0.6

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.
@@ -3,7 +3,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
3
  const buildURL = require("./buildURL.cjs");
4
4
  const buildWidthSrcSet = (url, { widths, ...params }) => {
5
5
  return widths.map((width) => {
6
- return `${buildURL.buildURL(url, { ...params, w: void 0, width })} ${width}w`;
6
+ return `${buildURL.buildURL(url, { ...params, w: void 0, h: void 0, height: void 0, width })} ${width}w`;
7
7
  }).join(", ");
8
8
  };
9
9
  exports.buildWidthSrcSet = buildWidthSrcSet;
@@ -1 +1 @@
1
- {"version":3,"file":"buildWidthSrcSet.cjs","sources":["../../src/buildWidthSrcSet.ts"],"sourcesContent":["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\n * 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"],"names":["buildURL"],"mappings":";;;AAyDO,MAAM,mBAAmB,CAC/B,KACA,EAAE,QAAQ,GAAG,aACF;AACJ,SAAA,OACL,IAAI,CAAC,UAAS;AACd,WAAO,GAAGA,SAAA,SAAS,KAAK,EAAE,GAAG,QAAQ,GAAG,QAAW,MAAK,CAAE,CAAC,IAAI,KAAK;AAAA,EAAA,CACpE,EACA,KAAK,IAAI;AACZ;;"}
1
+ {"version":3,"file":"buildWidthSrcSet.cjs","sources":["../../src/buildWidthSrcSet.ts"],"sourcesContent":["import type { ImgixURLParams } from \"./types.generated\";\nimport { buildURL } from \"./buildURL\";\n\n/**\n * Parameters for `buildWidthSrcSet`.\n */\nexport type BuildWidthSrcSetParams = Omit<\n\tImgixURLParams,\n\t\"width\" | \"w\" | \"height\" | \"h\"\n> & {\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\n * ignored. Similarly, if a `height` or `h` parameter is provided to the\n * `params` parameter, it will be ignored to prevent unexpected aspect ratio.\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, h: undefined, height: undefined, width })} ${width}w`;\n\t\t})\n\t\t.join(\", \");\n};\n"],"names":["buildURL"],"mappings":";;;AA6DO,MAAM,mBAAmB,CAC/B,KACA,EAAE,QAAQ,GAAG,aACF;AACJ,SAAA,OACL,IAAI,CAAC,UAAS;AACd,WAAO,GAAGA,SAAS,SAAA,KAAK,EAAE,GAAG,QAAQ,GAAG,QAAW,GAAG,QAAW,QAAQ,QAAW,MAAA,CAAO,CAAC,IAAI,KAAK;AAAA,EAAA,CACrG,EACA,KAAK,IAAI;AACZ;;"}
@@ -2,7 +2,7 @@ import type { ImgixURLParams } from "./types.generated";
2
2
  /**
3
3
  * Parameters for `buildWidthSrcSet`.
4
4
  */
5
- export type BuildWidthSrcSetParams = Omit<ImgixURLParams, "width" | "w"> & {
5
+ export type BuildWidthSrcSetParams = Omit<ImgixURLParams, "width" | "w" | "height" | "h"> & {
6
6
  /**
7
7
  * The pixel widths to include in the resulting `srcset` value.
8
8
  *
@@ -20,7 +20,8 @@ export type BuildWidthSrcSetParams = Omit<ImgixURLParams, "width" | "w"> & {
20
20
  *
21
21
  * The `width` URL parameter will be applied for each `srcset` entry. If a
22
22
  * `width` or `w` parameter is provided to the `params` parameter, it will be
23
- * ignored.
23
+ * ignored. Similarly, if a `height` or `h` parameter is provided to the
24
+ * `params` parameter, it will be ignored to prevent unexpected aspect ratio.
24
25
  *
25
26
  * @example
26
27
  *
@@ -1,7 +1,7 @@
1
1
  import { buildURL } from "./buildURL.js";
2
2
  const buildWidthSrcSet = (url, { widths, ...params }) => {
3
3
  return widths.map((width) => {
4
- return `${buildURL(url, { ...params, w: void 0, width })} ${width}w`;
4
+ return `${buildURL(url, { ...params, w: void 0, h: void 0, height: void 0, width })} ${width}w`;
5
5
  }).join(", ");
6
6
  };
7
7
  export {
@@ -1 +1 @@
1
- {"version":3,"file":"buildWidthSrcSet.js","sources":["../../src/buildWidthSrcSet.ts"],"sourcesContent":["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\n * 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"],"names":[],"mappings":";AAyDO,MAAM,mBAAmB,CAC/B,KACA,EAAE,QAAQ,GAAG,aACF;AACJ,SAAA,OACL,IAAI,CAAC,UAAS;AACd,WAAO,GAAG,SAAS,KAAK,EAAE,GAAG,QAAQ,GAAG,QAAW,MAAK,CAAE,CAAC,IAAI,KAAK;AAAA,EAAA,CACpE,EACA,KAAK,IAAI;AACZ;"}
1
+ {"version":3,"file":"buildWidthSrcSet.js","sources":["../../src/buildWidthSrcSet.ts"],"sourcesContent":["import type { ImgixURLParams } from \"./types.generated\";\nimport { buildURL } from \"./buildURL\";\n\n/**\n * Parameters for `buildWidthSrcSet`.\n */\nexport type BuildWidthSrcSetParams = Omit<\n\tImgixURLParams,\n\t\"width\" | \"w\" | \"height\" | \"h\"\n> & {\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\n * ignored. Similarly, if a `height` or `h` parameter is provided to the\n * `params` parameter, it will be ignored to prevent unexpected aspect ratio.\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, h: undefined, height: undefined, width })} ${width}w`;\n\t\t})\n\t\t.join(\", \");\n};\n"],"names":[],"mappings":";AA6DO,MAAM,mBAAmB,CAC/B,KACA,EAAE,QAAQ,GAAG,aACF;AACJ,SAAA,OACL,IAAI,CAAC,UAAS;AACd,WAAO,GAAG,SAAS,KAAK,EAAE,GAAG,QAAQ,GAAG,QAAW,GAAG,QAAW,QAAQ,QAAW,MAAA,CAAO,CAAC,IAAI,KAAK;AAAA,EAAA,CACrG,EACA,KAAK,IAAI;AACZ;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "imgix-url-builder",
3
- "version": "0.0.5",
3
+ "version": "0.0.6",
4
4
  "description": "JavaScript/TypeScript Imgix URL builders for browsers and Node.js",
5
5
  "keywords": [
6
6
  "typescript",
@@ -4,7 +4,10 @@ import { buildURL } from "./buildURL";
4
4
  /**
5
5
  * Parameters for `buildWidthSrcSet`.
6
6
  */
7
- export type BuildWidthSrcSetParams = Omit<ImgixURLParams, "width" | "w"> & {
7
+ export type BuildWidthSrcSetParams = Omit<
8
+ ImgixURLParams,
9
+ "width" | "w" | "height" | "h"
10
+ > & {
8
11
  /**
9
12
  * The pixel widths to include in the resulting `srcset` value.
10
13
  *
@@ -23,7 +26,8 @@ export type BuildWidthSrcSetParams = Omit<ImgixURLParams, "width" | "w"> & {
23
26
  *
24
27
  * The `width` URL parameter will be applied for each `srcset` entry. If a
25
28
  * `width` or `w` parameter is provided to the `params` parameter, it will be
26
- * ignored.
29
+ * ignored. Similarly, if a `height` or `h` parameter is provided to the
30
+ * `params` parameter, it will be ignored to prevent unexpected aspect ratio.
27
31
  *
28
32
  * @example
29
33
  *
@@ -61,7 +65,7 @@ export const buildWidthSrcSet = (
61
65
  ): string => {
62
66
  return widths
63
67
  .map((width) => {
64
- return `${buildURL(url, { ...params, w: undefined, width })} ${width}w`;
68
+ return `${buildURL(url, { ...params, w: undefined, h: undefined, height: undefined, width })} ${width}w`;
65
69
  })
66
70
  .join(", ");
67
71
  };