@dudousxd/nestjs-media-image-sharp 0.1.0

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 ADDED
@@ -0,0 +1,79 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
9
+ var __export = (target, all) => {
10
+ for (var name in all)
11
+ __defProp(target, name, { get: all[name], enumerable: true });
12
+ };
13
+ var __copyProps = (to, from, except, desc) => {
14
+ if (from && typeof from === "object" || typeof from === "function") {
15
+ for (let key of __getOwnPropNames(from))
16
+ if (!__hasOwnProp.call(to, key) && key !== except)
17
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
18
+ }
19
+ return to;
20
+ };
21
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
22
+ // If the importer is in node compatibility mode or this is not an ESM
23
+ // file that has been converted to a CommonJS file using a Babel-
24
+ // compatible transform (i.e. "__esModule" has not been set), then set
25
+ // "default" to the CommonJS "module.exports" for node compatibility.
26
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
27
+ mod
28
+ ));
29
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
30
+
31
+ // src/index.ts
32
+ var index_exports = {};
33
+ __export(index_exports, {
34
+ SharpImageProcessor: () => SharpImageProcessor
35
+ });
36
+ module.exports = __toCommonJS(index_exports);
37
+
38
+ // src/sharp-image-processor.ts
39
+ var import_sharp = __toESM(require("sharp"), 1);
40
+ var CONTENT_TYPE = {
41
+ jpeg: "image/jpeg",
42
+ png: "image/png",
43
+ webp: "image/webp",
44
+ avif: "image/avif"
45
+ };
46
+ var SharpImageProcessor = class {
47
+ static {
48
+ __name(this, "SharpImageProcessor");
49
+ }
50
+ async convert(input, preset) {
51
+ let pipeline = (0, import_sharp.default)(input);
52
+ if (preset.width || preset.height) {
53
+ pipeline = pipeline.resize({
54
+ ...preset.width ? {
55
+ width: preset.width
56
+ } : {},
57
+ ...preset.height ? {
58
+ height: preset.height
59
+ } : {},
60
+ fit: preset.fit ?? "cover"
61
+ });
62
+ }
63
+ const format = preset.format ?? "webp";
64
+ pipeline = pipeline.toFormat(format, preset.quality ? {
65
+ quality: preset.quality
66
+ } : {});
67
+ const data = await pipeline.toBuffer();
68
+ return {
69
+ data,
70
+ format,
71
+ contentType: CONTENT_TYPE[format] ?? "application/octet-stream"
72
+ };
73
+ }
74
+ };
75
+ // Annotate the CommonJS export names for ESM import in node:
76
+ 0 && (module.exports = {
77
+ SharpImageProcessor
78
+ });
79
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts","../src/sharp-image-processor.ts"],"sourcesContent":["export * from './sharp-image-processor';\n","import type {\n ConversionPreset,\n ConversionResult,\n ImageProcessor,\n} from '@dudousxd/nestjs-media-core';\nimport sharp from 'sharp';\n\nconst CONTENT_TYPE: Record<string, string> = {\n jpeg: 'image/jpeg',\n png: 'image/png',\n webp: 'image/webp',\n avif: 'image/avif',\n};\n\nexport class SharpImageProcessor implements ImageProcessor {\n async convert(input: Buffer, preset: ConversionPreset): Promise<ConversionResult> {\n let pipeline = sharp(input);\n\n if (preset.width || preset.height) {\n pipeline = pipeline.resize({\n ...(preset.width ? { width: preset.width } : {}),\n ...(preset.height ? { height: preset.height } : {}),\n fit: preset.fit ?? 'cover',\n });\n }\n\n const format = preset.format ?? 'webp';\n pipeline = pipeline.toFormat(format, preset.quality ? { quality: preset.quality } : {});\n\n const data = await pipeline.toBuffer();\n return { data, format, contentType: CONTENT_TYPE[format] ?? 'application/octet-stream' };\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;ACKA,mBAAkB;AAElB,IAAMA,eAAuC;EAC3CC,MAAM;EACNC,KAAK;EACLC,MAAM;EACNC,MAAM;AACR;AAEO,IAAMC,sBAAN,MAAMA;EATb,OASaA;;;EACX,MAAMC,QAAQC,OAAeC,QAAqD;AAChF,QAAIC,eAAWC,aAAAA,SAAMH,KAAAA;AAErB,QAAIC,OAAOG,SAASH,OAAOI,QAAQ;AACjCH,iBAAWA,SAASI,OAAO;QACzB,GAAIL,OAAOG,QAAQ;UAAEA,OAAOH,OAAOG;QAAM,IAAI,CAAC;QAC9C,GAAIH,OAAOI,SAAS;UAAEA,QAAQJ,OAAOI;QAAO,IAAI,CAAC;QACjDE,KAAKN,OAAOM,OAAO;MACrB,CAAA;IACF;AAEA,UAAMC,SAASP,OAAOO,UAAU;AAChCN,eAAWA,SAASO,SAASD,QAAQP,OAAOS,UAAU;MAAEA,SAAST,OAAOS;IAAQ,IAAI,CAAC,CAAA;AAErF,UAAMC,OAAO,MAAMT,SAASU,SAAQ;AACpC,WAAO;MAAED;MAAMH;MAAQK,aAAapB,aAAae,MAAAA,KAAW;IAA2B;EACzF;AACF;","names":["CONTENT_TYPE","jpeg","png","webp","avif","SharpImageProcessor","convert","input","preset","pipeline","sharp","width","height","resize","fit","format","toFormat","quality","data","toBuffer","contentType"]}
@@ -0,0 +1,7 @@
1
+ import { ImageProcessor, ConversionPreset, ConversionResult } from '@dudousxd/nestjs-media-core';
2
+
3
+ declare class SharpImageProcessor implements ImageProcessor {
4
+ convert(input: Buffer, preset: ConversionPreset): Promise<ConversionResult>;
5
+ }
6
+
7
+ export { SharpImageProcessor };
@@ -0,0 +1,7 @@
1
+ import { ImageProcessor, ConversionPreset, ConversionResult } from '@dudousxd/nestjs-media-core';
2
+
3
+ declare class SharpImageProcessor implements ImageProcessor {
4
+ convert(input: Buffer, preset: ConversionPreset): Promise<ConversionResult>;
5
+ }
6
+
7
+ export { SharpImageProcessor };
package/dist/index.js ADDED
@@ -0,0 +1,44 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
+
4
+ // src/sharp-image-processor.ts
5
+ import sharp from "sharp";
6
+ var CONTENT_TYPE = {
7
+ jpeg: "image/jpeg",
8
+ png: "image/png",
9
+ webp: "image/webp",
10
+ avif: "image/avif"
11
+ };
12
+ var SharpImageProcessor = class {
13
+ static {
14
+ __name(this, "SharpImageProcessor");
15
+ }
16
+ async convert(input, preset) {
17
+ let pipeline = sharp(input);
18
+ if (preset.width || preset.height) {
19
+ pipeline = pipeline.resize({
20
+ ...preset.width ? {
21
+ width: preset.width
22
+ } : {},
23
+ ...preset.height ? {
24
+ height: preset.height
25
+ } : {},
26
+ fit: preset.fit ?? "cover"
27
+ });
28
+ }
29
+ const format = preset.format ?? "webp";
30
+ pipeline = pipeline.toFormat(format, preset.quality ? {
31
+ quality: preset.quality
32
+ } : {});
33
+ const data = await pipeline.toBuffer();
34
+ return {
35
+ data,
36
+ format,
37
+ contentType: CONTENT_TYPE[format] ?? "application/octet-stream"
38
+ };
39
+ }
40
+ };
41
+ export {
42
+ SharpImageProcessor
43
+ };
44
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/sharp-image-processor.ts"],"sourcesContent":["import type {\n ConversionPreset,\n ConversionResult,\n ImageProcessor,\n} from '@dudousxd/nestjs-media-core';\nimport sharp from 'sharp';\n\nconst CONTENT_TYPE: Record<string, string> = {\n jpeg: 'image/jpeg',\n png: 'image/png',\n webp: 'image/webp',\n avif: 'image/avif',\n};\n\nexport class SharpImageProcessor implements ImageProcessor {\n async convert(input: Buffer, preset: ConversionPreset): Promise<ConversionResult> {\n let pipeline = sharp(input);\n\n if (preset.width || preset.height) {\n pipeline = pipeline.resize({\n ...(preset.width ? { width: preset.width } : {}),\n ...(preset.height ? { height: preset.height } : {}),\n fit: preset.fit ?? 'cover',\n });\n }\n\n const format = preset.format ?? 'webp';\n pipeline = pipeline.toFormat(format, preset.quality ? { quality: preset.quality } : {});\n\n const data = await pipeline.toBuffer();\n return { data, format, contentType: CONTENT_TYPE[format] ?? 'application/octet-stream' };\n }\n}\n"],"mappings":";;;;AAKA,OAAOA,WAAW;AAElB,IAAMC,eAAuC;EAC3CC,MAAM;EACNC,KAAK;EACLC,MAAM;EACNC,MAAM;AACR;AAEO,IAAMC,sBAAN,MAAMA;EATb,OASaA;;;EACX,MAAMC,QAAQC,OAAeC,QAAqD;AAChF,QAAIC,WAAWC,MAAMH,KAAAA;AAErB,QAAIC,OAAOG,SAASH,OAAOI,QAAQ;AACjCH,iBAAWA,SAASI,OAAO;QACzB,GAAIL,OAAOG,QAAQ;UAAEA,OAAOH,OAAOG;QAAM,IAAI,CAAC;QAC9C,GAAIH,OAAOI,SAAS;UAAEA,QAAQJ,OAAOI;QAAO,IAAI,CAAC;QACjDE,KAAKN,OAAOM,OAAO;MACrB,CAAA;IACF;AAEA,UAAMC,SAASP,OAAOO,UAAU;AAChCN,eAAWA,SAASO,SAASD,QAAQP,OAAOS,UAAU;MAAEA,SAAST,OAAOS;IAAQ,IAAI,CAAC,CAAA;AAErF,UAAMC,OAAO,MAAMT,SAASU,SAAQ;AACpC,WAAO;MAAED;MAAMH;MAAQK,aAAapB,aAAae,MAAAA,KAAW;IAA2B;EACzF;AACF;","names":["sharp","CONTENT_TYPE","jpeg","png","webp","avif","SharpImageProcessor","convert","input","preset","pipeline","sharp","width","height","resize","fit","format","toFormat","quality","data","toBuffer","contentType"]}
package/package.json ADDED
@@ -0,0 +1,39 @@
1
+ {
2
+ "name": "@dudousxd/nestjs-media-image-sharp",
3
+ "version": "0.1.0",
4
+ "description": "nestjs-media image processor backed by sharp",
5
+ "license": "MIT",
6
+ "type": "module",
7
+ "main": "./dist/index.cjs",
8
+ "module": "./dist/index.js",
9
+ "types": "./dist/index.d.ts",
10
+ "exports": {
11
+ ".": {
12
+ "import": {
13
+ "types": "./dist/index.d.ts",
14
+ "default": "./dist/index.js"
15
+ },
16
+ "require": {
17
+ "types": "./dist/index.d.cts",
18
+ "default": "./dist/index.cjs"
19
+ }
20
+ }
21
+ },
22
+ "files": [
23
+ "dist"
24
+ ],
25
+ "peerDependencies": {
26
+ "sharp": "^0.33.0",
27
+ "@dudousxd/nestjs-media-core": "0.1.0"
28
+ },
29
+ "devDependencies": {
30
+ "sharp": "0.33.5",
31
+ "tsup": "8.3.5",
32
+ "typescript": "5.9.3",
33
+ "@dudousxd/nestjs-media-core": "0.1.0"
34
+ },
35
+ "scripts": {
36
+ "build": "tsup",
37
+ "typecheck": "tsc -p tsconfig.json --noEmit"
38
+ }
39
+ }