@opensea/seadn 2.0.6 → 2.0.8
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/README.md +7 -0
- package/dist/index.d.mts +4 -2
- package/dist/index.d.ts +4 -2
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -4
- package/src/index.ts +1 -1
- package/src/sdk.spec.ts +11 -0
- package/src/sdk.ts +6 -1
package/README.md
CHANGED
package/dist/index.d.mts
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
type MediaFormat = "webp" | "avif" | "jpeg" | "png";
|
|
2
|
+
type MediaFit = "cover" | "contain" | "fill" | "inside" | "outside";
|
|
2
3
|
type MediaParams = {
|
|
3
4
|
width?: number | `${number}`;
|
|
4
5
|
height?: number | `${number}`;
|
|
5
6
|
format?: MediaFormat;
|
|
6
7
|
quality?: number | `${number}`;
|
|
8
|
+
fit?: MediaFit;
|
|
7
9
|
};
|
|
8
|
-
declare function optimize(image: string | URL, { width, height, format, quality }: MediaParams): string;
|
|
10
|
+
declare function optimize(image: string | URL, { width, height, format, quality, fit }: MediaParams): string;
|
|
9
11
|
|
|
10
|
-
export { type MediaFormat, type MediaParams, optimize };
|
|
12
|
+
export { type MediaFit, type MediaFormat, type MediaParams, optimize };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
type MediaFormat = "webp" | "avif" | "jpeg" | "png";
|
|
2
|
+
type MediaFit = "cover" | "contain" | "fill" | "inside" | "outside";
|
|
2
3
|
type MediaParams = {
|
|
3
4
|
width?: number | `${number}`;
|
|
4
5
|
height?: number | `${number}`;
|
|
5
6
|
format?: MediaFormat;
|
|
6
7
|
quality?: number | `${number}`;
|
|
8
|
+
fit?: MediaFit;
|
|
7
9
|
};
|
|
8
|
-
declare function optimize(image: string | URL, { width, height, format, quality }: MediaParams): string;
|
|
10
|
+
declare function optimize(image: string | URL, { width, height, format, quality, fit }: MediaParams): string;
|
|
9
11
|
|
|
10
|
-
export { type MediaFormat, type MediaParams, optimize };
|
|
12
|
+
export { type MediaFit, type MediaFormat, type MediaParams, optimize };
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var o=Object.defineProperty;var u=Object.getOwnPropertyDescriptor;var d=Object.getOwnPropertyNames;var c=Object.prototype.hasOwnProperty;var p=(e,t)=>{for(var r in t)o(e,r,{get:t[r],enumerable:!0})},b=(e,t,r,a)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of d(t))!c.call(e,n)&&n!==r&&o(e,n,{get:()=>t[n],enumerable:!(a=u(t,n))||a.enumerable});return e};var m=e=>b(o({},"__esModule",{value:!0}),e);var w={};p(w,{optimize:()=>f});module.exports=m(w);function f(e,{width:t,height:r,format:a,quality:n,fit:s}){try{typeof e=="string"&&(e=new URL(e))}catch(M){return e.toString()}if(!(e instanceof URL))return e;if(!h(e))return e.toString();let i=new URLSearchParams;if(r!==void 0&&i.set("h",String(r)),t!==void 0&&i.set("w",String(t)),a!==void 0&&i.set("format",a),n){if(Number(n)<=0||Number(n)>100)throw new Error("Quality has to be a positive number between 1 and 100");i.set("q",String(n))}return s!==void 0&&i.set("fit",s),e.search=i.toString(),e.toString()}function h(e){if(!l(e))return!1;let t=e.pathname.split(".");if(t.length<=1)return!0;switch(t[t.length-1]){case"png":case"jpeg":case"webp":case"avif":case"ico":case"gif":case void 0:return!0;default:return!1}}function l(e){return e.hostname.endsWith("seadn.io")}0&&(module.exports={optimize});
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/sdk.ts"],"sourcesContent":["export { optimize, MediaParams, MediaFormat } from \"./sdk\";\n","export type MediaFormat = \"webp\" | \"avif\" | \"jpeg\" | \"png\";\n\nexport type MediaParams = {\n width?: number | `${number}`;\n height?: number | `${number}`;\n format?: MediaFormat;\n quality?: number | `${number}`;\n};\n\nexport function optimize(\n image: string | URL,\n { width, height, format, quality }: MediaParams,\n): string {\n try {\n if (typeof image === \"string\") {\n image = new URL(image);\n }\n } catch {\n return image.toString();\n }\n\n if (!(image instanceof URL)) {\n return image;\n }\n\n if (!canBeResized(image)) {\n return image.toString();\n }\n\n const params = new URLSearchParams();\n if (height !== undefined) {\n params.set(\"h\", String(height));\n }\n if (width !== undefined) {\n params.set(\"w\", String(width));\n }\n if (format !== undefined) {\n params.set(\"format\", format);\n }\n if (quality) {\n if (Number(quality) <= 0 || Number(quality) > 100) {\n throw new Error(\"Quality has to be a positive number between 1 and 100\");\n }\n params.set(\"q\", String(quality));\n }\n\n image.search = params.toString();\n return image.toString();\n}\n\nfunction canBeResized(url: URL): boolean {\n if (!isSeadnURL(url)) {\n return false;\n }\n\n const split = url.pathname.split(\".\");\n if (split.length <= 1) {\n return true;\n }\n\n const extension = split[split.length - 1];\n switch (extension) {\n case \"png\":\n case \"jpeg\":\n case \"webp\":\n case \"avif\":\n case \"ico\":\n case \"gif\":\n case undefined:\n return true;\n default:\n return false;\n }\n}\n\nexport function isSeadnURL(url: URL): boolean {\n return url.hostname.endsWith(\"seadn.io\");\n}\n"],"mappings":"yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,cAAAE,IAAA,eAAAC,EAAAH,
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/sdk.ts"],"sourcesContent":["export { optimize, MediaParams, MediaFormat, MediaFit } from \"./sdk\";\n","export type MediaFormat = \"webp\" | \"avif\" | \"jpeg\" | \"png\";\nexport type MediaFit = \"cover\" | \"contain\" | \"fill\" | \"inside\" | \"outside\";\n\nexport type MediaParams = {\n width?: number | `${number}`;\n height?: number | `${number}`;\n format?: MediaFormat;\n quality?: number | `${number}`;\n fit?: MediaFit;\n};\n\nexport function optimize(\n image: string | URL,\n { width, height, format, quality, fit }: MediaParams,\n): string {\n try {\n if (typeof image === \"string\") {\n image = new URL(image);\n }\n } catch {\n return image.toString();\n }\n\n if (!(image instanceof URL)) {\n return image;\n }\n\n if (!canBeResized(image)) {\n return image.toString();\n }\n\n const params = new URLSearchParams();\n if (height !== undefined) {\n params.set(\"h\", String(height));\n }\n if (width !== undefined) {\n params.set(\"w\", String(width));\n }\n if (format !== undefined) {\n params.set(\"format\", format);\n }\n if (quality) {\n if (Number(quality) <= 0 || Number(quality) > 100) {\n throw new Error(\"Quality has to be a positive number between 1 and 100\");\n }\n params.set(\"q\", String(quality));\n }\n if (fit !== undefined) {\n params.set(\"fit\", fit);\n }\n\n image.search = params.toString();\n return image.toString();\n}\n\nfunction canBeResized(url: URL): boolean {\n if (!isSeadnURL(url)) {\n return false;\n }\n\n const split = url.pathname.split(\".\");\n if (split.length <= 1) {\n return true;\n }\n\n const extension = split[split.length - 1];\n switch (extension) {\n case \"png\":\n case \"jpeg\":\n case \"webp\":\n case \"avif\":\n case \"ico\":\n case \"gif\":\n case undefined:\n return true;\n default:\n return false;\n }\n}\n\nexport function isSeadnURL(url: URL): boolean {\n return url.hostname.endsWith(\"seadn.io\");\n}\n"],"mappings":"yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,cAAAE,IAAA,eAAAC,EAAAH,GCWO,SAASI,EACdC,EACA,CAAE,MAAAC,EAAO,OAAAC,EAAQ,OAAAC,EAAQ,QAAAC,EAAS,IAAAC,CAAI,EAC9B,CACR,GAAI,CACE,OAAOL,GAAU,WACnBA,EAAQ,IAAI,IAAIA,CAAK,EAEzB,OAAQM,EAAA,CACN,OAAON,EAAM,SAAS,CACxB,CAEA,GAAI,EAAEA,aAAiB,KACrB,OAAOA,EAGT,GAAI,CAACO,EAAaP,CAAK,EACrB,OAAOA,EAAM,SAAS,EAGxB,IAAMQ,EAAS,IAAI,gBAUnB,GATIN,IAAW,QACbM,EAAO,IAAI,IAAK,OAAON,CAAM,CAAC,EAE5BD,IAAU,QACZO,EAAO,IAAI,IAAK,OAAOP,CAAK,CAAC,EAE3BE,IAAW,QACbK,EAAO,IAAI,SAAUL,CAAM,EAEzBC,EAAS,CACX,GAAI,OAAOA,CAAO,GAAK,GAAK,OAAOA,CAAO,EAAI,IAC5C,MAAM,IAAI,MAAM,uDAAuD,EAEzEI,EAAO,IAAI,IAAK,OAAOJ,CAAO,CAAC,CACjC,CACA,OAAIC,IAAQ,QACVG,EAAO,IAAI,MAAOH,CAAG,EAGvBL,EAAM,OAASQ,EAAO,SAAS,EACxBR,EAAM,SAAS,CACxB,CAEA,SAASO,EAAaE,EAAmB,CACvC,GAAI,CAACC,EAAWD,CAAG,EACjB,MAAO,GAGT,IAAME,EAAQF,EAAI,SAAS,MAAM,GAAG,EACpC,GAAIE,EAAM,QAAU,EAClB,MAAO,GAIT,OADkBA,EAAMA,EAAM,OAAS,CAAC,EACrB,CACjB,IAAK,MACL,IAAK,OACL,IAAK,OACL,IAAK,OACL,IAAK,MACL,IAAK,MACL,KAAK,OACH,MAAO,GACT,QACE,MAAO,EACX,CACF,CAEO,SAASD,EAAWD,EAAmB,CAC5C,OAAOA,EAAI,SAAS,SAAS,UAAU,CACzC","names":["src_exports","__export","optimize","__toCommonJS","optimize","image","width","height","format","quality","fit","e","canBeResized","params","url","isSeadnURL","split"]}
|
package/dist/index.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
function
|
|
1
|
+
function s(e,{width:t,height:i,format:a,quality:r,fit:o}){try{typeof e=="string"&&(e=new URL(e))}catch(d){return e.toString()}if(!(e instanceof URL))return e;if(!f(e))return e.toString();let n=new URLSearchParams;if(i!==void 0&&n.set("h",String(i)),t!==void 0&&n.set("w",String(t)),a!==void 0&&n.set("format",a),r){if(Number(r)<=0||Number(r)>100)throw new Error("Quality has to be a positive number between 1 and 100");n.set("q",String(r))}return o!==void 0&&n.set("fit",o),e.search=n.toString(),e.toString()}function f(e){if(!u(e))return!1;let t=e.pathname.split(".");if(t.length<=1)return!0;switch(t[t.length-1]){case"png":case"jpeg":case"webp":case"avif":case"ico":case"gif":case void 0:return!0;default:return!1}}function u(e){return e.hostname.endsWith("seadn.io")}export{s as optimize};
|
|
2
2
|
//# sourceMappingURL=index.mjs.map
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/sdk.ts"],"sourcesContent":["export type MediaFormat = \"webp\" | \"avif\" | \"jpeg\" | \"png\";\n\nexport type MediaParams = {\n width?: number | `${number}`;\n height?: number | `${number}`;\n format?: MediaFormat;\n quality?: number | `${number}`;\n};\n\nexport function optimize(\n image: string | URL,\n { width, height, format, quality }: MediaParams,\n): string {\n try {\n if (typeof image === \"string\") {\n image = new URL(image);\n }\n } catch {\n return image.toString();\n }\n\n if (!(image instanceof URL)) {\n return image;\n }\n\n if (!canBeResized(image)) {\n return image.toString();\n }\n\n const params = new URLSearchParams();\n if (height !== undefined) {\n params.set(\"h\", String(height));\n }\n if (width !== undefined) {\n params.set(\"w\", String(width));\n }\n if (format !== undefined) {\n params.set(\"format\", format);\n }\n if (quality) {\n if (Number(quality) <= 0 || Number(quality) > 100) {\n throw new Error(\"Quality has to be a positive number between 1 and 100\");\n }\n params.set(\"q\", String(quality));\n }\n\n image.search = params.toString();\n return image.toString();\n}\n\nfunction canBeResized(url: URL): boolean {\n if (!isSeadnURL(url)) {\n return false;\n }\n\n const split = url.pathname.split(\".\");\n if (split.length <= 1) {\n return true;\n }\n\n const extension = split[split.length - 1];\n switch (extension) {\n case \"png\":\n case \"jpeg\":\n case \"webp\":\n case \"avif\":\n case \"ico\":\n case \"gif\":\n case undefined:\n return true;\n default:\n return false;\n }\n}\n\nexport function isSeadnURL(url: URL): boolean {\n return url.hostname.endsWith(\"seadn.io\");\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../src/sdk.ts"],"sourcesContent":["export type MediaFormat = \"webp\" | \"avif\" | \"jpeg\" | \"png\";\nexport type MediaFit = \"cover\" | \"contain\" | \"fill\" | \"inside\" | \"outside\";\n\nexport type MediaParams = {\n width?: number | `${number}`;\n height?: number | `${number}`;\n format?: MediaFormat;\n quality?: number | `${number}`;\n fit?: MediaFit;\n};\n\nexport function optimize(\n image: string | URL,\n { width, height, format, quality, fit }: MediaParams,\n): string {\n try {\n if (typeof image === \"string\") {\n image = new URL(image);\n }\n } catch {\n return image.toString();\n }\n\n if (!(image instanceof URL)) {\n return image;\n }\n\n if (!canBeResized(image)) {\n return image.toString();\n }\n\n const params = new URLSearchParams();\n if (height !== undefined) {\n params.set(\"h\", String(height));\n }\n if (width !== undefined) {\n params.set(\"w\", String(width));\n }\n if (format !== undefined) {\n params.set(\"format\", format);\n }\n if (quality) {\n if (Number(quality) <= 0 || Number(quality) > 100) {\n throw new Error(\"Quality has to be a positive number between 1 and 100\");\n }\n params.set(\"q\", String(quality));\n }\n if (fit !== undefined) {\n params.set(\"fit\", fit);\n }\n\n image.search = params.toString();\n return image.toString();\n}\n\nfunction canBeResized(url: URL): boolean {\n if (!isSeadnURL(url)) {\n return false;\n }\n\n const split = url.pathname.split(\".\");\n if (split.length <= 1) {\n return true;\n }\n\n const extension = split[split.length - 1];\n switch (extension) {\n case \"png\":\n case \"jpeg\":\n case \"webp\":\n case \"avif\":\n case \"ico\":\n case \"gif\":\n case undefined:\n return true;\n default:\n return false;\n }\n}\n\nexport function isSeadnURL(url: URL): boolean {\n return url.hostname.endsWith(\"seadn.io\");\n}\n"],"mappings":"AAWO,SAASA,EACdC,EACA,CAAE,MAAAC,EAAO,OAAAC,EAAQ,OAAAC,EAAQ,QAAAC,EAAS,IAAAC,CAAI,EAC9B,CACR,GAAI,CACE,OAAOL,GAAU,WACnBA,EAAQ,IAAI,IAAIA,CAAK,EAEzB,OAAQM,EAAA,CACN,OAAON,EAAM,SAAS,CACxB,CAEA,GAAI,EAAEA,aAAiB,KACrB,OAAOA,EAGT,GAAI,CAACO,EAAaP,CAAK,EACrB,OAAOA,EAAM,SAAS,EAGxB,IAAMQ,EAAS,IAAI,gBAUnB,GATIN,IAAW,QACbM,EAAO,IAAI,IAAK,OAAON,CAAM,CAAC,EAE5BD,IAAU,QACZO,EAAO,IAAI,IAAK,OAAOP,CAAK,CAAC,EAE3BE,IAAW,QACbK,EAAO,IAAI,SAAUL,CAAM,EAEzBC,EAAS,CACX,GAAI,OAAOA,CAAO,GAAK,GAAK,OAAOA,CAAO,EAAI,IAC5C,MAAM,IAAI,MAAM,uDAAuD,EAEzEI,EAAO,IAAI,IAAK,OAAOJ,CAAO,CAAC,CACjC,CACA,OAAIC,IAAQ,QACVG,EAAO,IAAI,MAAOH,CAAG,EAGvBL,EAAM,OAASQ,EAAO,SAAS,EACxBR,EAAM,SAAS,CACxB,CAEA,SAASO,EAAaE,EAAmB,CACvC,GAAI,CAACC,EAAWD,CAAG,EACjB,MAAO,GAGT,IAAME,EAAQF,EAAI,SAAS,MAAM,GAAG,EACpC,GAAIE,EAAM,QAAU,EAClB,MAAO,GAIT,OADkBA,EAAMA,EAAM,OAAS,CAAC,EACrB,CACjB,IAAK,MACL,IAAK,OACL,IAAK,OACL,IAAK,OACL,IAAK,MACL,IAAK,MACL,KAAK,OACH,MAAO,GACT,QACE,MAAO,EACX,CACF,CAEO,SAASD,EAAWD,EAAmB,CAC5C,OAAOA,EAAI,SAAS,SAAS,UAAU,CACzC","names":["optimize","image","width","height","format","quality","fit","e","canBeResized","params","url","isSeadnURL","split"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@opensea/seadn",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.8",
|
|
4
4
|
"description": "Javascript SDK to work with SeaDN",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "OpenSea Developers",
|
|
@@ -20,8 +20,8 @@
|
|
|
20
20
|
},
|
|
21
21
|
"devDependencies": {
|
|
22
22
|
"@arethetypeswrong/cli": "0.15.3",
|
|
23
|
-
"tsup": "8.0
|
|
24
|
-
"typescript": "5.
|
|
25
|
-
"vitest": "1.
|
|
23
|
+
"tsup": "8.1.0",
|
|
24
|
+
"typescript": "5.5.3",
|
|
25
|
+
"vitest": "1.6.0"
|
|
26
26
|
}
|
|
27
27
|
}
|
package/src/index.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { optimize, MediaParams, MediaFormat } from "./sdk";
|
|
1
|
+
export { optimize, MediaParams, MediaFormat, MediaFit } from "./sdk";
|
package/src/sdk.spec.ts
CHANGED
|
@@ -72,6 +72,17 @@ test.each([
|
|
|
72
72
|
} satisfies MediaParams,
|
|
73
73
|
"https://i2.seadn.io/bored-ape?h=100&w=100&format=avif&q=50",
|
|
74
74
|
],
|
|
75
|
+
[
|
|
76
|
+
"https://i2.seadn.io/bored-ape",
|
|
77
|
+
{
|
|
78
|
+
height: 100,
|
|
79
|
+
width: 100,
|
|
80
|
+
format: "avif",
|
|
81
|
+
quality: 50,
|
|
82
|
+
fit: "contain",
|
|
83
|
+
} satisfies MediaParams,
|
|
84
|
+
"https://i2.seadn.io/bored-ape?h=100&w=100&format=avif&q=50&fit=contain",
|
|
85
|
+
],
|
|
75
86
|
[
|
|
76
87
|
"https://xyz.com/bored-ape.png",
|
|
77
88
|
{ height: 100, width: 100, format: "avif" } satisfies MediaParams,
|
package/src/sdk.ts
CHANGED
|
@@ -1,15 +1,17 @@
|
|
|
1
1
|
export type MediaFormat = "webp" | "avif" | "jpeg" | "png";
|
|
2
|
+
export type MediaFit = "cover" | "contain" | "fill" | "inside" | "outside";
|
|
2
3
|
|
|
3
4
|
export type MediaParams = {
|
|
4
5
|
width?: number | `${number}`;
|
|
5
6
|
height?: number | `${number}`;
|
|
6
7
|
format?: MediaFormat;
|
|
7
8
|
quality?: number | `${number}`;
|
|
9
|
+
fit?: MediaFit;
|
|
8
10
|
};
|
|
9
11
|
|
|
10
12
|
export function optimize(
|
|
11
13
|
image: string | URL,
|
|
12
|
-
{ width, height, format, quality }: MediaParams,
|
|
14
|
+
{ width, height, format, quality, fit }: MediaParams,
|
|
13
15
|
): string {
|
|
14
16
|
try {
|
|
15
17
|
if (typeof image === "string") {
|
|
@@ -43,6 +45,9 @@ export function optimize(
|
|
|
43
45
|
}
|
|
44
46
|
params.set("q", String(quality));
|
|
45
47
|
}
|
|
48
|
+
if (fit !== undefined) {
|
|
49
|
+
params.set("fit", fit);
|
|
50
|
+
}
|
|
46
51
|
|
|
47
52
|
image.search = params.toString();
|
|
48
53
|
return image.toString();
|