ipx 1.0.0-2 → 1.0.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/cli.cjs CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  const consola = require('consola');
4
4
  const listhen = require('listhen');
5
- const middleware = require('./shared/ipx.399255f0.cjs');
5
+ const middleware = require('./shared/ipx.73dbe528.cjs');
6
6
  require('defu');
7
7
  require('image-meta');
8
8
  require('ufo');
package/dist/cli.d.ts CHANGED
@@ -1 +1,2 @@
1
1
 
2
+ export { }
package/dist/cli.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  import consola from 'consola';
2
2
  import { listen } from 'listhen';
3
- import { c as createIPX, a as createIPXMiddleware } from './shared/ipx.d1cfdfa2.mjs';
3
+ import { c as createIPX, a as createIPXMiddleware } from './shared/ipx.5d237d4e.mjs';
4
4
  import 'defu';
5
5
  import 'image-meta';
6
6
  import 'ufo';
package/dist/index.cjs CHANGED
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- const middleware = require('./shared/ipx.399255f0.cjs');
3
+ const middleware = require('./shared/ipx.73dbe528.cjs');
4
4
  require('defu');
5
5
  require('image-meta');
6
6
  require('ufo');
package/dist/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- export { c as createIPX, a as createIPXMiddleware, h as handleRequest } from './shared/ipx.d1cfdfa2.mjs';
1
+ export { c as createIPX, a as createIPXMiddleware, h as handleRequest } from './shared/ipx.5d237d4e.mjs';
2
2
  import 'defu';
3
3
  import 'image-meta';
4
4
  import 'ufo';
@@ -12,38 +12,38 @@ import xss from 'xss';
12
12
 
13
13
  const Handlers = {
14
14
  __proto__: null,
15
- get quality () { return quality; },
16
- get fit () { return fit; },
17
- get position () { return position; },
15
+ get b () { return b; },
18
16
  get background () { return background; },
17
+ get blur () { return blur; },
18
+ get crop () { return crop; },
19
19
  get enlarge () { return enlarge; },
20
- get width () { return width; },
21
- get height () { return height; },
22
- get resize () { return resize; },
23
- get trim () { return trim; },
24
20
  get extend () { return extend; },
25
21
  get extract () { return extract; },
26
- get rotate () { return rotate; },
22
+ get fit () { return fit; },
23
+ get flatten () { return flatten; },
27
24
  get flip () { return flip; },
28
25
  get flop () { return flop; },
29
- get sharpen () { return sharpen; },
30
- get median () { return median; },
31
- get blur () { return blur; },
32
- get flatten () { return flatten; },
33
26
  get gamma () { return gamma; },
27
+ get grayscale () { return grayscale; },
28
+ get h () { return h; },
29
+ get height () { return height; },
30
+ get median () { return median; },
31
+ get modulate () { return modulate; },
34
32
  get negate () { return negate; },
35
33
  get normalize () { return normalize; },
34
+ get pos () { return pos; },
35
+ get position () { return position; },
36
+ get q () { return q; },
37
+ get quality () { return quality; },
38
+ get resize () { return resize; },
39
+ get rotate () { return rotate; },
40
+ get s () { return s; },
41
+ get sharpen () { return sharpen; },
36
42
  get threshold () { return threshold; },
37
- get modulate () { return modulate; },
38
43
  get tint () { return tint; },
39
- get grayscale () { return grayscale; },
40
- get crop () { return crop; },
41
- get q () { return q; },
42
- get b () { return b; },
44
+ get trim () { return trim; },
43
45
  get w () { return w; },
44
- get h () { return h; },
45
- get s () { return s; },
46
- get pos () { return pos; }
46
+ get width () { return width; }
47
47
  };
48
48
 
49
49
  function getEnv(name, defaultValue) {
@@ -111,12 +111,14 @@ const createHTTPSource = (options) => {
111
111
  if (typeof _domains === "string") {
112
112
  _domains = _domains.split(",").map((s) => s.trim());
113
113
  }
114
- const domains = new Set(_domains.map((d) => {
115
- if (!HTTP_RE.test(d)) {
116
- d = "http://" + d;
117
- }
118
- return new URL(d).hostname;
119
- }).filter(Boolean));
114
+ const domains = new Set(
115
+ _domains.map((d) => {
116
+ if (!HTTP_RE.test(d)) {
117
+ d = "http://" + d;
118
+ }
119
+ return new URL(d).hostname;
120
+ }).filter(Boolean)
121
+ );
120
122
  return async (id, requestOptions) => {
121
123
  const hostname = new URL(id).hostname;
122
124
  if (!hostname) {
@@ -126,11 +128,16 @@ const createHTTPSource = (options) => {
126
128
  throw createError("Forbidden host", 403, hostname);
127
129
  }
128
130
  const response = await fetch(id, {
131
+ // @ts-ignore
129
132
  agent: id.startsWith("https") ? httpsAgent : httpAgent,
130
133
  ...options.fetchOptions
131
134
  });
132
135
  if (!response.ok) {
133
- throw createError("Fetch error", response.status || 500, response.statusText);
136
+ throw createError(
137
+ "Fetch error",
138
+ response.status || 500,
139
+ response.statusText
140
+ );
134
141
  }
135
142
  let maxAge = options.maxAge;
136
143
  const _cacheControl = response.headers.get("cache-control");
@@ -148,7 +155,10 @@ const createHTTPSource = (options) => {
148
155
  return {
149
156
  mtime,
150
157
  maxAge,
151
- getData: cachedPromise(() => response.arrayBuffer().then((ab) => Buffer.from(ab)))
158
+ // @ts-ignore
159
+ getData: cachedPromise(
160
+ () => response.arrayBuffer().then((ab) => Buffer.from(ab))
161
+ )
152
162
  };
153
163
  };
154
164
  };
@@ -224,13 +234,17 @@ const enlarge = {
224
234
  const width = {
225
235
  args: [VArg],
226
236
  apply: (context, pipe, width2) => {
227
- return pipe.resize(width2, void 0, { withoutEnlargement: !context.enlarge });
237
+ return pipe.resize(width2, void 0, {
238
+ withoutEnlargement: !context.enlarge
239
+ });
228
240
  }
229
241
  };
230
242
  const height = {
231
243
  args: [VArg],
232
244
  apply: (context, pipe, height2) => {
233
- return pipe.resize(void 0, height2, { withoutEnlargement: !context.enlarge });
245
+ return pipe.resize(void 0, height2, {
246
+ withoutEnlargement: !context.enlarge
247
+ });
234
248
  }
235
249
  };
236
250
  const resize = {
@@ -244,7 +258,10 @@ const resize = {
244
258
  height2 = width2;
245
259
  }
246
260
  if (!context.enlarge) {
247
- const clamped = clampDimensionsPreservingAspectRatio(context.meta, { width: width2, height: height2 });
261
+ const clamped = clampDimensionsPreservingAspectRatio(context.meta, {
262
+ width: width2,
263
+ height: height2
264
+ });
248
265
  width2 = clamped.width;
249
266
  height2 = clamped.height;
250
267
  }
@@ -385,7 +402,14 @@ const h = height;
385
402
  const s = resize;
386
403
  const pos = position;
387
404
 
388
- const SUPPORTED_FORMATS = /* @__PURE__ */ new Set(["jpeg", "png", "webp", "avif", "tiff", "gif"]);
405
+ const SUPPORTED_FORMATS = /* @__PURE__ */ new Set([
406
+ "jpeg",
407
+ "png",
408
+ "webp",
409
+ "avif",
410
+ "tiff",
411
+ "gif"
412
+ ]);
389
413
  function createIPX(userOptions) {
390
414
  const defaults = {
391
415
  dir: getEnv("IPX_DIR", "."),
@@ -396,7 +420,9 @@ function createIPX(userOptions) {
396
420
  sharp: {}
397
421
  };
398
422
  const options = defu(userOptions, defaults);
399
- options.alias = Object.fromEntries(Object.entries(options.alias).map((e) => [withLeadingSlash(e[0]), e[1]]));
423
+ options.alias = Object.fromEntries(
424
+ Object.entries(options.alias).map((e) => [withLeadingSlash(e[0]), e[1]])
425
+ );
400
426
  const context = {
401
427
  sources: {}
402
428
  };
@@ -447,10 +473,16 @@ function createIPX(userOptions) {
447
473
  };
448
474
  }
449
475
  const animated = modifiers.animated !== void 0 || modifiers.a !== void 0 || format === "gif";
450
- const Sharp = await import('sharp').then((r) => r.default || r);
476
+ const Sharp = await import('sharp').then(
477
+ (r) => r.default || r
478
+ );
451
479
  let sharp = Sharp(data, { animated });
452
480
  Object.assign(sharp.options, options.sharp);
453
- const handlers = Object.entries(modifiers).map(([name, arguments_]) => ({ handler: getHandler(name), name, args: arguments_ })).filter((h) => h.handler).sort((a, b) => {
481
+ const handlers = Object.entries(modifiers).map(([name, arguments_]) => ({
482
+ handler: getHandler(name),
483
+ name,
484
+ args: arguments_
485
+ })).filter((h) => h.handler).sort((a, b) => {
454
486
  const aKey = (a.handler.order || a.name || "").toString();
455
487
  const bKey = (b.handler.order || b.name || "").toString();
456
488
  return aKey.localeCompare(bKey);
@@ -488,7 +520,10 @@ async function _handleRequest(request, ipx) {
488
520
  headers: {},
489
521
  body: ""
490
522
  };
491
- const [modifiersString = "", ...idSegments] = request.url.slice(1).split("/");
523
+ const [modifiersString = "", ...idSegments] = request.url.slice(
524
+ 1
525
+ /* leading slash */
526
+ ).split("/");
492
527
  const id = safeString(decode(idSegments.join("/")));
493
528
  if (!modifiersString) {
494
529
  throw createError("Modifiers are missing", 400, request.url);
@@ -546,7 +581,10 @@ function handleRequest(request, ipx) {
546
581
  }
547
582
  function createIPXMiddleware(ipx) {
548
583
  return function IPXMiddleware(request, res) {
549
- return handleRequest({ url: request.url, headers: request.headers }, ipx).then((_res) => {
584
+ return handleRequest(
585
+ { url: request.url, headers: request.headers },
586
+ ipx
587
+ ).then((_res) => {
550
588
  res.statusCode = _res.statusCode;
551
589
  res.statusMessage = _res.statusMessage;
552
590
  for (const name in _res.headers) {
@@ -14,38 +14,38 @@ const xss = require('xss');
14
14
 
15
15
  const Handlers = {
16
16
  __proto__: null,
17
- get quality () { return quality; },
18
- get fit () { return fit; },
19
- get position () { return position; },
17
+ get b () { return b; },
20
18
  get background () { return background; },
19
+ get blur () { return blur; },
20
+ get crop () { return crop; },
21
21
  get enlarge () { return enlarge; },
22
- get width () { return width; },
23
- get height () { return height; },
24
- get resize () { return resize; },
25
- get trim () { return trim; },
26
22
  get extend () { return extend; },
27
23
  get extract () { return extract; },
28
- get rotate () { return rotate; },
24
+ get fit () { return fit; },
25
+ get flatten () { return flatten; },
29
26
  get flip () { return flip; },
30
27
  get flop () { return flop; },
31
- get sharpen () { return sharpen; },
32
- get median () { return median; },
33
- get blur () { return blur; },
34
- get flatten () { return flatten; },
35
28
  get gamma () { return gamma; },
29
+ get grayscale () { return grayscale; },
30
+ get h () { return h; },
31
+ get height () { return height; },
32
+ get median () { return median; },
33
+ get modulate () { return modulate; },
36
34
  get negate () { return negate; },
37
35
  get normalize () { return normalize; },
36
+ get pos () { return pos; },
37
+ get position () { return position; },
38
+ get q () { return q; },
39
+ get quality () { return quality; },
40
+ get resize () { return resize; },
41
+ get rotate () { return rotate; },
42
+ get s () { return s; },
43
+ get sharpen () { return sharpen; },
38
44
  get threshold () { return threshold; },
39
- get modulate () { return modulate; },
40
45
  get tint () { return tint; },
41
- get grayscale () { return grayscale; },
42
- get crop () { return crop; },
43
- get q () { return q; },
44
- get b () { return b; },
46
+ get trim () { return trim; },
45
47
  get w () { return w; },
46
- get h () { return h; },
47
- get s () { return s; },
48
- get pos () { return pos; }
48
+ get width () { return width; }
49
49
  };
50
50
 
51
51
  function getEnv(name, defaultValue) {
@@ -113,12 +113,14 @@ const createHTTPSource = (options) => {
113
113
  if (typeof _domains === "string") {
114
114
  _domains = _domains.split(",").map((s) => s.trim());
115
115
  }
116
- const domains = new Set(_domains.map((d) => {
117
- if (!HTTP_RE.test(d)) {
118
- d = "http://" + d;
119
- }
120
- return new URL(d).hostname;
121
- }).filter(Boolean));
116
+ const domains = new Set(
117
+ _domains.map((d) => {
118
+ if (!HTTP_RE.test(d)) {
119
+ d = "http://" + d;
120
+ }
121
+ return new URL(d).hostname;
122
+ }).filter(Boolean)
123
+ );
122
124
  return async (id, requestOptions) => {
123
125
  const hostname = new URL(id).hostname;
124
126
  if (!hostname) {
@@ -128,11 +130,16 @@ const createHTTPSource = (options) => {
128
130
  throw createError("Forbidden host", 403, hostname);
129
131
  }
130
132
  const response = await nodeFetchNative.fetch(id, {
133
+ // @ts-ignore
131
134
  agent: id.startsWith("https") ? httpsAgent : httpAgent,
132
135
  ...options.fetchOptions
133
136
  });
134
137
  if (!response.ok) {
135
- throw createError("Fetch error", response.status || 500, response.statusText);
138
+ throw createError(
139
+ "Fetch error",
140
+ response.status || 500,
141
+ response.statusText
142
+ );
136
143
  }
137
144
  let maxAge = options.maxAge;
138
145
  const _cacheControl = response.headers.get("cache-control");
@@ -150,7 +157,10 @@ const createHTTPSource = (options) => {
150
157
  return {
151
158
  mtime,
152
159
  maxAge,
153
- getData: cachedPromise(() => response.arrayBuffer().then((ab) => Buffer.from(ab)))
160
+ // @ts-ignore
161
+ getData: cachedPromise(
162
+ () => response.arrayBuffer().then((ab) => Buffer.from(ab))
163
+ )
154
164
  };
155
165
  };
156
166
  };
@@ -226,13 +236,17 @@ const enlarge = {
226
236
  const width = {
227
237
  args: [VArg],
228
238
  apply: (context, pipe, width2) => {
229
- return pipe.resize(width2, void 0, { withoutEnlargement: !context.enlarge });
239
+ return pipe.resize(width2, void 0, {
240
+ withoutEnlargement: !context.enlarge
241
+ });
230
242
  }
231
243
  };
232
244
  const height = {
233
245
  args: [VArg],
234
246
  apply: (context, pipe, height2) => {
235
- return pipe.resize(void 0, height2, { withoutEnlargement: !context.enlarge });
247
+ return pipe.resize(void 0, height2, {
248
+ withoutEnlargement: !context.enlarge
249
+ });
236
250
  }
237
251
  };
238
252
  const resize = {
@@ -246,7 +260,10 @@ const resize = {
246
260
  height2 = width2;
247
261
  }
248
262
  if (!context.enlarge) {
249
- const clamped = clampDimensionsPreservingAspectRatio(context.meta, { width: width2, height: height2 });
263
+ const clamped = clampDimensionsPreservingAspectRatio(context.meta, {
264
+ width: width2,
265
+ height: height2
266
+ });
250
267
  width2 = clamped.width;
251
268
  height2 = clamped.height;
252
269
  }
@@ -387,7 +404,14 @@ const h = height;
387
404
  const s = resize;
388
405
  const pos = position;
389
406
 
390
- const SUPPORTED_FORMATS = /* @__PURE__ */ new Set(["jpeg", "png", "webp", "avif", "tiff", "gif"]);
407
+ const SUPPORTED_FORMATS = /* @__PURE__ */ new Set([
408
+ "jpeg",
409
+ "png",
410
+ "webp",
411
+ "avif",
412
+ "tiff",
413
+ "gif"
414
+ ]);
391
415
  function createIPX(userOptions) {
392
416
  const defaults = {
393
417
  dir: getEnv("IPX_DIR", "."),
@@ -398,7 +422,9 @@ function createIPX(userOptions) {
398
422
  sharp: {}
399
423
  };
400
424
  const options = defu.defu(userOptions, defaults);
401
- options.alias = Object.fromEntries(Object.entries(options.alias).map((e) => [ufo.withLeadingSlash(e[0]), e[1]]));
425
+ options.alias = Object.fromEntries(
426
+ Object.entries(options.alias).map((e) => [ufo.withLeadingSlash(e[0]), e[1]])
427
+ );
402
428
  const context = {
403
429
  sources: {}
404
430
  };
@@ -449,10 +475,16 @@ function createIPX(userOptions) {
449
475
  };
450
476
  }
451
477
  const animated = modifiers.animated !== void 0 || modifiers.a !== void 0 || format === "gif";
452
- const Sharp = await import('sharp').then((r) => r.default || r);
478
+ const Sharp = await import('sharp').then(
479
+ (r) => r.default || r
480
+ );
453
481
  let sharp = Sharp(data, { animated });
454
482
  Object.assign(sharp.options, options.sharp);
455
- const handlers = Object.entries(modifiers).map(([name, arguments_]) => ({ handler: getHandler(name), name, args: arguments_ })).filter((h) => h.handler).sort((a, b) => {
483
+ const handlers = Object.entries(modifiers).map(([name, arguments_]) => ({
484
+ handler: getHandler(name),
485
+ name,
486
+ args: arguments_
487
+ })).filter((h) => h.handler).sort((a, b) => {
456
488
  const aKey = (a.handler.order || a.name || "").toString();
457
489
  const bKey = (b.handler.order || b.name || "").toString();
458
490
  return aKey.localeCompare(bKey);
@@ -490,7 +522,10 @@ async function _handleRequest(request, ipx) {
490
522
  headers: {},
491
523
  body: ""
492
524
  };
493
- const [modifiersString = "", ...idSegments] = request.url.slice(1).split("/");
525
+ const [modifiersString = "", ...idSegments] = request.url.slice(
526
+ 1
527
+ /* leading slash */
528
+ ).split("/");
494
529
  const id = safeString(ufo.decode(idSegments.join("/")));
495
530
  if (!modifiersString) {
496
531
  throw createError("Modifiers are missing", 400, request.url);
@@ -548,7 +583,10 @@ function handleRequest(request, ipx) {
548
583
  }
549
584
  function createIPXMiddleware(ipx) {
550
585
  return function IPXMiddleware(request, res) {
551
- return handleRequest({ url: request.url, headers: request.headers }, ipx).then((_res) => {
586
+ return handleRequest(
587
+ { url: request.url, headers: request.headers },
588
+ ipx
589
+ ).then((_res) => {
552
590
  res.statusCode = _res.statusCode;
553
591
  res.statusMessage = _res.statusMessage;
554
592
  for (const name in _res.headers) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ipx",
3
- "version": "1.0.0-2",
3
+ "version": "1.0.0",
4
4
  "repository": "unjs/ipx",
5
5
  "license": "MIT",
6
6
  "exports": {
@@ -20,42 +20,41 @@
20
20
  "scripts": {
21
21
  "build": "unbuild",
22
22
  "dev": "nodemon",
23
- "lint": "eslint --ext .ts .",
23
+ "lint": "eslint --ext .ts . && prettier -c src test",
24
+ "lint:fix": "eslint --ext .ts . --fix && prettier -w src test",
24
25
  "prepack": "pnpm build",
25
- "release": "pnpm test && standard-version && git push --follow-tags && pnpm publish",
26
+ "release": "pnpm test && changelogen --release --push && npm publish",
26
27
  "start": "node bin/ipx.js",
27
28
  "test": "pnpm lint && vitest run --coverage"
28
29
  },
29
30
  "dependencies": {
30
31
  "consola": "^2.15.3",
31
- "defu": "^6.1.1",
32
- "destr": "^1.2.1",
32
+ "defu": "^6.1.2",
33
+ "destr": "^1.2.2",
33
34
  "etag": "^1.8.1",
34
35
  "image-meta": "^0.1.1",
35
- "listhen": "^1.0.0",
36
- "node-fetch-native": "^1.0.1",
37
- "pathe": "^1.0.0",
38
- "sharp": "^0.31.2",
39
- "ufo": "^1.0.0",
36
+ "listhen": "^1.0.4",
37
+ "node-fetch-native": "^1.0.2",
38
+ "pathe": "^1.1.0",
39
+ "sharp": "^0.32.0",
40
+ "ufo": "^1.1.1",
40
41
  "xss": "^1.0.14"
41
42
  },
42
43
  "devDependencies": {
43
- "@nuxtjs/eslint-config-typescript": "^12.0.0",
44
44
  "@types/etag": "^1.8.1",
45
45
  "@types/is-valid-path": "^0.1.0",
46
- "@types/node-fetch": "^2.6.2",
47
- "@types/sharp": "^0.31.0",
48
- "@vitest/coverage-c8": "^0.25.3",
49
- "changelogen": "^0.4.0",
50
- "eslint": "^8.28.0",
51
- "eslint-config-unjs": "^0.0.2",
52
- "jiti": "^1.16.0",
53
- "nodemon": "^2.0.20",
46
+ "@types/sharp": "^0.31.1",
47
+ "@vitest/coverage-c8": "^0.29.8",
48
+ "changelogen": "^0.5.2",
49
+ "eslint": "^8.37.0",
50
+ "eslint-config-unjs": "^0.1.0",
51
+ "jiti": "^1.18.2",
52
+ "nodemon": "^2.0.22",
53
+ "prettier": "^2.8.7",
54
54
  "serve-handler": "^6.1.5",
55
- "standard-version": "^9.5.0",
56
- "typescript": "^4.9.3",
57
- "unbuild": "^1.0.1",
58
- "vitest": "^0.25.3"
55
+ "typescript": "^5.0.3",
56
+ "unbuild": "^1.1.2",
57
+ "vitest": "^0.29.8"
59
58
  },
60
- "packageManager": "pnpm@7.17.0"
61
- }
59
+ "packageManager": "pnpm@8.0.0"
60
+ }