ipx 1.1.0 → 1.3.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/README.md CHANGED
@@ -1,83 +1,113 @@
1
- # IPX
1
+ # 🖼️ IPX
2
2
 
3
- [![NPM Vernion](https://flat.badgen.net/npm/v/ipx)](https://www.npmjs.com/package/ipx)
4
- [![NPM Downloads](https://flat.badgen.net/npm/dt/ipx)](https://www.npmjs.com/package/ipx)
5
- [![Package Size](https://flat.badgen.net/packagephobia/install/ipx)](https://packagephobia.now.sh/result?p=ipx)
3
+ [![npm version][npm-version-src]][npm-version-href]
4
+ [![npm downloads][npm-downloads-src]][npm-downloads-href]
6
5
 
7
6
  High performance, secure and easy to use image proxy based on [sharp](https://github.com/lovell/sharp) and [libvips](https://github.com/libvips/libvips).
8
7
 
9
- ## Usage
10
-
11
- ### Quick Start
8
+ ## Using CLI
12
9
 
13
10
  You can use `ipx` command to start server using:
14
11
 
15
12
  ```bash
16
- $ npx ipx
13
+ npx ipx@latest
17
14
  ```
18
15
 
19
16
  The default server directory is the current working directory.
20
17
 
21
- ### Programatic Usage
18
+ ## Programatic API
19
+
20
+ You can use IPX as a middleware or directly use IPX interface.
21
+
22
+ ```ts
23
+ import { createIPX, createIPXMiddleware } from "ipx";
24
+
25
+ const ipx = createIPX({ domains: ["unjs.io"] });
26
+
27
+ // (req, res) => void
28
+ const ipxMiddleware = createIPXMiddleware(ipx);
29
+ ```
22
30
 
23
- You can use IPX as a Connect/Express middleware or directly use ipx api.
31
+ **Example**: Using with [unjs/h3](https://github.com/unjs/h3):
24
32
 
25
33
  ```js
26
34
  import { createIPX, createIPXMiddleware } from "ipx";
35
+ import { listen } from "listhen";
36
+ import { createApp, fromNodeMiddleware, toNodeListener } from "h3";
37
+
38
+ const ipx = createIPX({});
39
+ const ipxMiddleware = createIPXMiddleware(ipx);
40
+
41
+ const app = createApp().use("/", fromNodeMiddleware(ipxMiddleware));
27
42
 
28
- const ipx = createIPX(/* options */);
29
- const app = express();
30
- app.use("/image", createIPXMiddleware(ipx));
43
+ listen(toNodeListener(app));
31
44
  ```
32
45
 
33
- ### Examples
46
+ **Example:** Using [express](https://expressjs.com):
47
+
48
+ ```js
49
+ import { createIPX, createIPXMiddleware } from "ipx";
50
+ import { listen } from "listhen";
51
+ import express from "express";
34
52
 
35
- > The examples assume that a `static` folder with `buffalo.png` file is present in the directory where IPX server is running.
53
+ const ipx = createIPX({});
54
+ const ipxMiddleware = createIPXMiddleware(ipx);
55
+
56
+ const app = express().use("/", ipxMiddleware);
57
+
58
+ listen(app);
59
+ ```
60
+
61
+ ## Examples
36
62
 
37
63
  Get original image:
38
64
 
39
- `http://localhost:3000/_/static/buffalo.png`
65
+ `/_/static/buffalo.png`
40
66
 
41
67
  Change format to `webp` and keep other things same as source:
42
68
 
43
- `http://localhost:3000/f_webp/static/buffalo.png`
69
+ `/f_webp/static/buffalo.png`
44
70
 
45
71
  Keep original format (`png`) and set width to `200`:
46
72
 
47
- `http://localhost:3000/w_200/static/buffalo.png`
73
+ `/w_200/static/buffalo.png`
48
74
 
49
75
  Resize to `200x200px` using `embed` method and change format to `webp`:
50
76
 
51
- `http://localhost:3000/embed,f_webp,s_200x200/static/buffalo.png`
52
-
53
- ### Modifiers
54
-
55
- | Property | Docs | Example | Comments |
56
- | --------------- | :-------------------------------------------------------------- | :---------------------------------------------------------- | :---------------------------------------------------------------------------------------------------------------------------------------------------------------- |
57
- | width / w | [Docs](https://sharp.pixelplumbing.com/api-resize#resize) | `http://localhost:3000/width_200/buffalo.png` |
58
- | height / h | [Docs](https://sharp.pixelplumbing.com/api-resize#resize) | `http://localhost:3000/height_200/buffalo.png` |
59
- | resize / s | [Docs](https://sharp.pixelplumbing.com/api-resize#resize) | `http://localhost:3000/s_200x200/buffalo.png` |
60
- | fit | [Docs](https://sharp.pixelplumbing.com/api-resize#resize) | `http://localhost:3000/s_200x200,fit_outside/buffalo.png` | Sets `fit` option for `resize`.
61
- | position / pos | [Docs](https://sharp.pixelplumbing.com/api-resize#resize) | `http://localhost:3000/s_200x200,pos_top/buffalo.png` | Sets `position` option for `resize`.
62
- | trim | [Docs](https://sharp.pixelplumbing.com/api-resize#trim) | `http://localhost:3000/trim_100/buffalo.png` |
63
- | format | [Docs](https://sharp.pixelplumbing.com/api-output#toformat) | `http://localhost:3000/format_webp/buffalo.png` | Supported format: `jpg`, `jpeg`, `png`, `webp`, `avif`, `gif`, `heif` |
64
- | quality / q | \_ | `http://localhost:3000/quality_50/buffalo.png` | Accepted values: 0 to 100 |
65
- | rotate | [Docs](https://sharp.pixelplumbing.com/api-operation#rotate) | `http://localhost:3000/rotate_45/buffalo.png` |
66
- | enlarge | \_ | `http://localhost:3000/enlarge,s_2000x2000/buffalo.png` | Allow the image to be upscaled. By default the returned image will never be larger than the source in any dimension, while preserving the requested aspect ratio. |
67
- | flip | [Docs](https://sharp.pixelplumbing.com/api-operation#flip) | `http://localhost:3000/flip/buffalo.png` |
68
- | flop | [Docs](https://sharp.pixelplumbing.com/api-operation#flop) | `http://localhost:3000/flop/buffalo.png` |
69
- | sharpen | [Docs](https://sharp.pixelplumbing.com/api-operation#sharpen) | `http://localhost:3000/sharpen_30/buffalo.png` |
70
- | median | [Docs](https://sharp.pixelplumbing.com/api-operation#median) | `http://localhost:3000/median_10/buffalo.png` |
71
- | blur | [Docs](https://sharp.pixelplumbing.com/api-operation#blur) | `http://localhost:3000/blur_5/buffalo.png` |
72
- | gamma | [Docs](https://sharp.pixelplumbing.com/api-operation#gamma) | `http://localhost:3000/gamma_3/buffalo.png` |
73
- | negate | [Docs](https://sharp.pixelplumbing.com/api-operation#negate) | `http://localhost:3000/negate/buffalo.png` |
74
- | normalize | [Docs](https://sharp.pixelplumbing.com/api-operation#normalize) | `http://localhost:3000/normalize/buffalo.png` |
75
- | threshold | [Docs](https://sharp.pixelplumbing.com/api-operation#threshold) | `http://localhost:3000/threshold_10/buffalo.png` |
76
- | tint | [Docs](https://sharp.pixelplumbing.com/api-colour#tint) | `http://localhost:3000/tint_1098123/buffalo.png` |
77
- | grayscale | [Docs](https://sharp.pixelplumbing.com/api-colour#grayscale) | `http://localhost:3000/grayscale/buffalo.png` |
78
- | animated | - | `http://localhost:3000/animated/buffalo.gif` | Experimental |
79
-
80
- ### Config
77
+ `/embed,f_webp,s_200x200/static/buffalo.png`
78
+
79
+ ## Modifiers
80
+
81
+ | Property | Docs | Example | Comments |
82
+ | -------------- | :-------------------------------------------------------------- | :--------------------------------------------------- | :---------------------------------------------------------------------------------------------------------------------------------------------------------------- |
83
+ | width / w | [Docs](https://sharp.pixelplumbing.com/api-resize#resize) | `/width_200/buffalo.png` |
84
+ | height / h | [Docs](https://sharp.pixelplumbing.com/api-resize#resize) | `/height_200/buffalo.png` |
85
+ | resize / s | [Docs](https://sharp.pixelplumbing.com/api-resize#resize) | `/s_200x200/buffalo.png` |
86
+ | kernel | [Docs](https://sharp.pixelplumbing.com/api-resize#resize) | `/s_200x200,kernel_nearest/buffalo.png` | Supported kernel: `nearest`, `cubic`, `mitchell`, `lanczos2` and `lanczos3` (default). |
87
+ | fit | [Docs](https://sharp.pixelplumbing.com/api-resize#resize) | `/s_200x200,fit_outside/buffalo.png` | Sets `fit` option for `resize`. |
88
+ | position / pos | [Docs](https://sharp.pixelplumbing.com/api-resize#resize) | `/s_200x200,pos_top/buffalo.png` | Sets `position` option for `resize`. |
89
+ | trim | [Docs](https://sharp.pixelplumbing.com/api-resize#trim) | `/trim_100/buffalo.png` |
90
+ | extend | [Docs](https://sharp.pixelplumbing.com/api-resize#extend) | `/extend_{top}_{right}_{bottom}_{left}/buffalo.png` | Extend / pad / extrude one or more edges of the image with either the provided background colour or pixels derived from the image. |
91
+ | background / b | \_ | `/r_45,b_00ff00/buffalo.png` |
92
+ | extract | [Docs](https://sharp.pixelplumbing.com/api-resize#extract) | `/extract_{left}_{top}_{width}_{height}/buffalo.png` | Extract/crop a region of the image. |
93
+ | format / f | [Docs](https://sharp.pixelplumbing.com/api-output#toformat) | `/format_webp/buffalo.png` | Supported format: `jpg`, `jpeg`, `png`, `webp`, `avif`, `gif`, `heif`, `tiff` and `auto` (experimental only with middleware) |
94
+ | quality / q | \_ | `/quality_50/buffalo.png` | Accepted values: 0 to 100 |
95
+ | rotate | [Docs](https://sharp.pixelplumbing.com/api-operation#rotate) | `/rotate_45/buffalo.png` |
96
+ | enlarge | \_ | `/enlarge,s_2000x2000/buffalo.png` | Allow the image to be upscaled. By default the returned image will never be larger than the source in any dimension, while preserving the requested aspect ratio. |
97
+ | flip | [Docs](https://sharp.pixelplumbing.com/api-operation#flip) | `/flip/buffalo.png` |
98
+ | flop | [Docs](https://sharp.pixelplumbing.com/api-operation#flop) | `/flop/buffalo.png` |
99
+ | sharpen | [Docs](https://sharp.pixelplumbing.com/api-operation#sharpen) | `/sharpen_30/buffalo.png` |
100
+ | median | [Docs](https://sharp.pixelplumbing.com/api-operation#median) | `/median_10/buffalo.png` |
101
+ | blur | [Docs](https://sharp.pixelplumbing.com/api-operation#blur) | `/blur_5/buffalo.png` |
102
+ | gamma | [Docs](https://sharp.pixelplumbing.com/api-operation#gamma) | `/gamma_3/buffalo.png` |
103
+ | negate | [Docs](https://sharp.pixelplumbing.com/api-operation#negate) | `/negate/buffalo.png` |
104
+ | normalize | [Docs](https://sharp.pixelplumbing.com/api-operation#normalize) | `/normalize/buffalo.png` |
105
+ | threshold | [Docs](https://sharp.pixelplumbing.com/api-operation#threshold) | `/threshold_10/buffalo.png` |
106
+ | tint | [Docs](https://sharp.pixelplumbing.com/api-colour#tint) | `/tint_1098123/buffalo.png` |
107
+ | grayscale | [Docs](https://sharp.pixelplumbing.com/api-colour#grayscale) | `/grayscale/buffalo.png` |
108
+ | animated | - | `/animated/buffalo.gif` | Experimental |
109
+
110
+ ## Config
81
111
 
82
112
  Config can be customized using `IPX_*` environment variables.
83
113
 
@@ -86,8 +116,36 @@ Config can be customized using `IPX_*` environment variables.
86
116
  - Default: `.` (current working directory)
87
117
 
88
118
  - `IPX_DOMAINS`
119
+
89
120
  - Default: `[]`
90
121
 
122
+ - `IPX_MAX_AGE`
123
+
124
+ - Default: `300`
125
+
126
+ - `IPX_ALIAS`
127
+
128
+ - Default: `{}`
129
+
130
+ - `IPX_FETCH_OPTIONS`
131
+
132
+ - Default: `{}`
133
+
91
134
  ## License
92
135
 
93
- MIT
136
+ [MIT](./LICENSE)
137
+
138
+ <!-- Badges -->
139
+
140
+ [npm-version-src]: https://img.shields.io/npm/v/ipx?style=flat&colorA=18181B&colorB=F0DB4F
141
+ [npm-version-href]: https://npmjs.com/package/ipx
142
+ [npm-downloads-src]: https://img.shields.io/npm/dm/ipx?style=flat&colorA=18181B&colorB=F0DB4F
143
+ [npm-downloads-href]: https://npmjs.com/package/ipx
144
+ [github-actions-src]: https://img.shields.io/github/workflow/status/unjs/ipx/ci/main?style=flat&colorA=18181B&colorB=F0DB4F
145
+ [github-actions-href]: https://github.com/unjs/ipx/actions?query=workflow%3Aci
146
+ [codecov-src]: https://img.shields.io/codecov/c/gh/unjs/ipx/main?style=flat&colorA=18181B&colorB=F0DB4F
147
+ [codecov-href]: https://codecov.io/gh/unjs/ipx
148
+ [bundle-src]: https://img.shields.io/bundlephobia/minzip/ipx?style=flat&colorA=18181B&colorB=F0DB4F
149
+ [bundle-href]: https://bundlephobia.com/result?p=ipx
150
+ [license-src]: https://img.shields.io/github/license/unjs/ipx.svg?style=flat&colorA=18181B&colorB=F0DB4F
151
+ [license-href]: https://github.com/unjs/ipx/blob/main/LICENSE
package/bin/ipx.mjs CHANGED
@@ -1,2 +1,2 @@
1
1
  #!/usr/bin/env node
2
- import '../dist/cli.mjs'
2
+ import "../dist/cli.mjs";
package/dist/cli.cjs CHANGED
@@ -2,16 +2,17 @@
2
2
 
3
3
  const consola = require('consola');
4
4
  const listhen = require('listhen');
5
- const middleware = require('./shared/ipx.e9f7a9b5.cjs');
5
+ const index = require('./index.cjs');
6
6
  require('defu');
7
7
  require('image-meta');
8
8
  require('ufo');
9
9
  require('node:fs');
10
10
  require('pathe');
11
+ require('destr');
11
12
  require('node:http');
12
13
  require('node:https');
13
14
  require('node-fetch-native');
14
- require('destr');
15
+ require('@fastify/accept-negotiator');
15
16
  require('etag');
16
17
  require('xss');
17
18
 
@@ -20,9 +21,9 @@ function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'defau
20
21
  const consola__default = /*#__PURE__*/_interopDefaultCompat(consola);
21
22
 
22
23
  async function main() {
23
- const ipx = middleware.createIPX({});
24
- const middleware$1 = middleware.createIPXMiddleware(ipx);
25
- await listhen.listen(middleware$1, {
24
+ const ipx = index.createIPX({});
25
+ const middleware = index.createIPXMiddleware(ipx);
26
+ await listhen.listen(middleware, {
26
27
  clipboard: false
27
28
  });
28
29
  }
package/dist/cli.d.cts ADDED
@@ -0,0 +1,2 @@
1
+
2
+ export { }
package/dist/cli.d.mts ADDED
@@ -0,0 +1,2 @@
1
+
2
+ export { }
package/dist/cli.d.ts CHANGED
@@ -1,2 +1,2 @@
1
1
 
2
- export { }
2
+ export { }
package/dist/cli.mjs CHANGED
@@ -1,15 +1,16 @@
1
1
  import consola from 'consola';
2
2
  import { listen } from 'listhen';
3
- import { c as createIPX, a as createIPXMiddleware } from './shared/ipx.cc3515c9.mjs';
3
+ import { createIPX, createIPXMiddleware } from './index.mjs';
4
4
  import 'defu';
5
5
  import 'image-meta';
6
6
  import 'ufo';
7
7
  import 'node:fs';
8
8
  import 'pathe';
9
+ import 'destr';
9
10
  import 'node:http';
10
11
  import 'node:https';
11
12
  import 'node-fetch-native';
12
- import 'destr';
13
+ import '@fastify/accept-negotiator';
13
14
  import 'etag';
14
15
  import 'xss';
15
16