@opensea/seadn 2.0.0 → 2.0.1

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opensea/seadn",
3
- "version": "2.0.0",
3
+ "version": "2.0.1",
4
4
  "description": "Javascript SDK to work with SeaDN",
5
5
  "license": "MIT",
6
6
  "author": "OpenSea Developers",
package/src/sdk.spec.ts CHANGED
@@ -57,6 +57,16 @@ test.each([
57
57
  { height: 100, width: 100, format: "avif" } satisfies MediaParams,
58
58
  "https://i2.seadn.io/bored-ape?h=100&w=100&format=avif",
59
59
  ],
60
+ [
61
+ "https://i2.seadn.io/bored-ape",
62
+ {
63
+ height: 100,
64
+ width: 100,
65
+ format: "avif",
66
+ quality: 50,
67
+ } satisfies MediaParams,
68
+ "https://i2.seadn.io/bored-ape?h=100&w=100&format=avif&q=50",
69
+ ],
60
70
  [
61
71
  "https://xyz.com/bored-ape.png",
62
72
  { height: 100, width: 100, format: "avif" } satisfies MediaParams,
package/src/sdk.ts CHANGED
@@ -4,11 +4,12 @@ export type MediaParams = {
4
4
  width?: number | `${number}`;
5
5
  height?: number | `${number}`;
6
6
  format?: MediaFormat;
7
+ quality?: number;
7
8
  };
8
9
 
9
10
  export function optimize(
10
11
  image: string | URL,
11
- { width, height, format }: MediaParams,
12
+ { width, height, format, quality }: MediaParams,
12
13
  ): string {
13
14
  try {
14
15
  if (typeof image === "string") {
@@ -36,6 +37,13 @@ export function optimize(
36
37
  if (format !== undefined) {
37
38
  params.set("format", format);
38
39
  }
40
+ if (quality) {
41
+ if (quality <= 0 || quality > 100) {
42
+ throw new Error("Quality has to be a positive number between 1 and 100");
43
+ }
44
+ params.set("q", String(quality));
45
+ }
46
+
39
47
  image.search = params.toString();
40
48
  return image.toString();
41
49
  }