ipx 1.2.0 → 2.0.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/LICENSE CHANGED
File without changes
package/README.md CHANGED
@@ -3,33 +3,74 @@
3
3
  [![npm version][npm-version-src]][npm-version-href]
4
4
  [![npm downloads][npm-downloads-src]][npm-downloads-href]
5
5
 
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).
6
+ High performance, secure and easy-to-use image optimizer.
7
7
 
8
- ## Usage
8
+ Powered by [sharp](https://github.com/lovell/sharp) and [libvips](https://github.com/libvips/libvips).
9
9
 
10
- ### Quick Start
10
+ > [!IMPORTANT]
11
+ > This is the development branch for IPX v2. Check out [ipx/v1](https://github.com/unjs/ipx/tree/v1) for latest stable docs.
11
12
 
12
- You can use `ipx` command to start server using:
13
+ ## Using CLI
14
+
15
+ You can use `ipx` command to start server.
16
+
17
+ Using `npx`:
13
18
 
14
19
  ```bash
15
- $ npx ipx
20
+ npx ipx@latest serve --dir ./
16
21
  ```
17
22
 
18
- The default server directory is the current working directory.
23
+ Usin `bun`
24
+
25
+ ```bash
26
+ bun x ipx@latest serve --dir ./
27
+ ```
28
+
29
+ The default serve directory is the current working directory.
30
+
31
+ ## Programatic API
19
32
 
20
- ### Programatic Usage
33
+ You can use IPX as a middleware or directly use IPX interface.
21
34
 
22
- You can use IPX as a Connect/Express middleware or directly use ipx api.
35
+ ```ts
36
+ import {
37
+ createIPX,
38
+ createIPXMiddleware,
39
+ ipxFSStorage,
40
+ ipxHttpStorage,
41
+ } from "./src";
42
+
43
+ const ipx = createIPX({
44
+ storage: ipxFSStorage({ dir: "./public" }),
45
+ httpStorage: ipxHttpStorage({ domains: ["picsum.photos"] }),
46
+ });
47
+
48
+ const ipxMiddleware = createIPXMiddleware(ipx);
49
+ ```
50
+
51
+ **Example**: Using with [unjs/h3](https://github.com/unjs/h3):
23
52
 
24
53
  ```js
25
54
  import { createIPX, createIPXMiddleware } from "ipx";
55
+ import { listen } from "listhen";
56
+
57
+ const app = createApp().use("/", fromNodeMiddleware(ipxMiddleware));
58
+
59
+ listen(toNodeListener(app));
60
+ ```
26
61
 
27
- const ipx = createIPX(/* options */);
28
- const app = express();
29
- app.use("/image", createIPXMiddleware(ipx));
62
+ **Example:** Using [express](https://expressjs.com):
63
+
64
+ ```js
65
+ import { listen } from "listhen";
66
+ import express from "express";
67
+
68
+ const app = express().use("/", ipxMiddleware);
69
+
70
+ listen(app);
30
71
  ```
31
72
 
32
- ### Examples
73
+ ## URL Examples
33
74
 
34
75
  Get original image:
35
76
 
@@ -47,17 +88,59 @@ Resize to `200x200px` using `embed` method and change format to `webp`:
47
88
 
48
89
  `/embed,f_webp,s_200x200/static/buffalo.png`
49
90
 
50
- ### Modifiers
91
+ ## Config
92
+
93
+ You can universally customize IPX configuration using `IPX_*` environment variables.
94
+
95
+ - `IPX_ALIAS`
96
+
97
+ - Default: `{}`
98
+
99
+ ### Filesystem Source Options
100
+
101
+ (enabled by default with CLI only)
102
+
103
+ #### `IPX_FS_DIR`
104
+
105
+ - Default: `.` (current working directory)
106
+
107
+ #### `IPX_FS_MAX_AGE`
108
+
109
+ - Default: `300`
110
+
111
+ ### HTTP(s) Source Options
112
+
113
+ (enabled by default with CLI only)
114
+
115
+ #### `IPX_HTTP_DOMAINS`
116
+
117
+ - Default: `[]`
118
+
119
+ #### `IPX_HTTP_MAX_AGE`
120
+
121
+ - Default: `300`
122
+
123
+ #### `IPX_HTTP_FETCH_OPTIONS`
124
+
125
+ - Default: `{}`
126
+
127
+ #### `IPX_HTTP_ALLOW_ALL_DOMAINS`
128
+
129
+ - Default: `false`
130
+
131
+ ## Modifiers
51
132
 
52
133
  | Property | Docs | Example | Comments |
53
134
  | -------------- | :-------------------------------------------------------------- | :--------------------------------------------------- | :---------------------------------------------------------------------------------------------------------------------------------------------------------------- |
54
135
  | width / w | [Docs](https://sharp.pixelplumbing.com/api-resize#resize) | `/width_200/buffalo.png` |
55
136
  | height / h | [Docs](https://sharp.pixelplumbing.com/api-resize#resize) | `/height_200/buffalo.png` |
56
137
  | resize / s | [Docs](https://sharp.pixelplumbing.com/api-resize#resize) | `/s_200x200/buffalo.png` |
138
+ | kernel | [Docs](https://sharp.pixelplumbing.com/api-resize#resize) | `/s_200x200,kernel_nearest/buffalo.png` | Supported kernel: `nearest`, `cubic`, `mitchell`, `lanczos2` and `lanczos3` (default). |
57
139
  | fit | [Docs](https://sharp.pixelplumbing.com/api-resize#resize) | `/s_200x200,fit_outside/buffalo.png` | Sets `fit` option for `resize`. |
58
140
  | position / pos | [Docs](https://sharp.pixelplumbing.com/api-resize#resize) | `/s_200x200,pos_top/buffalo.png` | Sets `position` option for `resize`. |
59
141
  | trim | [Docs](https://sharp.pixelplumbing.com/api-resize#trim) | `/trim_100/buffalo.png` |
60
142
  | 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. |
143
+ | background / b | \_ | `/r_45,b_00ff00/buffalo.png` |
61
144
  | extract | [Docs](https://sharp.pixelplumbing.com/api-resize#extract) | `/extract_{left}_{top}_{width}_{height}/buffalo.png` | Extract/crop a region of the image. |
62
145
  | 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) |
63
146
  | quality / q | \_ | `/quality_50/buffalo.png` | Accepted values: 0 to 100 |
@@ -76,30 +159,6 @@ Resize to `200x200px` using `embed` method and change format to `webp`:
76
159
  | grayscale | [Docs](https://sharp.pixelplumbing.com/api-colour#grayscale) | `/grayscale/buffalo.png` |
77
160
  | animated | - | `/animated/buffalo.gif` | Experimental |
78
161
 
79
- ### Config
80
-
81
- Config can be customized using `IPX_*` environment variables.
82
-
83
- - `IPX_DIR`
84
-
85
- - Default: `.` (current working directory)
86
-
87
- - `IPX_DOMAINS`
88
-
89
- - Default: `[]`
90
-
91
- - `IPX_MAX_AGE`
92
-
93
- - Default: `300`
94
-
95
- - `IPX_ALIAS`
96
-
97
- - Default: `{}`
98
-
99
- - `IPX_FETCH_OPTIONS`
100
-
101
- - Default: `{}`
102
-
103
162
  ## License
104
163
 
105
164
  [MIT](./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
@@ -1,33 +1,63 @@
1
1
  'use strict';
2
2
 
3
- const consola = require('consola');
4
3
  const listhen = require('listhen');
5
- const index = require('./index.cjs');
4
+ const citty = require('citty');
5
+ const cli = require('listhen/cli');
6
+ const nodeFs = require('./shared/ipx.0fc4e4c7.cjs');
6
7
  require('defu');
7
8
  require('image-meta');
8
9
  require('ufo');
9
- require('node:fs');
10
- require('pathe');
10
+ require('h3');
11
11
  require('destr');
12
- require('node:http');
13
- require('node:https');
14
- require('node-fetch-native');
15
12
  require('@fastify/accept-negotiator');
16
13
  require('etag');
17
- require('xss');
18
-
19
- function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
14
+ require('node-fetch-native');
15
+ require('pathe');
20
16
 
21
- const consola__default = /*#__PURE__*/_interopDefaultCompat(consola);
17
+ const name = "ipx";
18
+ const version = "2.0.0-0";
19
+ const description = "High performance, secure and easy-to-use image optimizer.";
22
20
 
23
- async function main() {
24
- const ipx = index.createIPX({});
25
- const middleware = index.createIPXMiddleware(ipx);
26
- await listhen.listen(middleware, {
27
- clipboard: false
28
- });
29
- }
30
- main().catch((error) => {
31
- consola__default.error(error);
32
- process.exit(1);
21
+ const serve = citty.defineCommand({
22
+ meta: {
23
+ description: "Start IPX Server"
24
+ },
25
+ args: {
26
+ dir: {
27
+ type: "string",
28
+ required: false,
29
+ description: "Directory to serve (default: current directory) ENV: IPX_FS_DIR"
30
+ },
31
+ domains: {
32
+ type: "string",
33
+ required: false,
34
+ description: "Allowed domains (comma separated) ENV: IPX_HTTP_DOMAINS"
35
+ },
36
+ ...cli.getArgs()
37
+ },
38
+ async run({ args }) {
39
+ const ipx = nodeFs.createIPX({
40
+ storage: nodeFs.ipxFSStorage({
41
+ dir: args.dir
42
+ }),
43
+ httpStorage: nodeFs.ipxHttpStorage({
44
+ domains: args.domains
45
+ })
46
+ });
47
+ await listhen.listen(nodeFs.createIPXNodeServer(ipx), {
48
+ name: "IPX",
49
+ ...cli.parseArgs(args)
50
+ });
51
+ }
52
+ });
53
+ const main = citty.defineCommand({
54
+ meta: {
55
+ name,
56
+ version,
57
+ description
58
+ },
59
+ subCommands: {
60
+ serve
61
+ }
33
62
  });
63
+ citty.runMain(main);
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,27 +1,61 @@
1
- import consola from 'consola';
2
1
  import { listen } from 'listhen';
3
- import { createIPX, createIPXMiddleware } from './index.mjs';
2
+ import { defineCommand, runMain } from 'citty';
3
+ import { getArgs, parseArgs } from 'listhen/cli';
4
+ import { c as createIPX, g as ipxFSStorage, i as ipxHttpStorage, e as createIPXNodeServer } from './shared/ipx.42c0c175.mjs';
4
5
  import 'defu';
5
6
  import 'image-meta';
6
7
  import 'ufo';
7
- import 'node:fs';
8
- import 'pathe';
8
+ import 'h3';
9
9
  import 'destr';
10
- import 'node:http';
11
- import 'node:https';
12
- import 'node-fetch-native';
13
10
  import '@fastify/accept-negotiator';
14
11
  import 'etag';
15
- import 'xss';
12
+ import 'node-fetch-native';
13
+ import 'pathe';
14
+
15
+ const name = "ipx";
16
+ const version = "2.0.0-0";
17
+ const description = "High performance, secure and easy-to-use image optimizer.";
16
18
 
17
- async function main() {
18
- const ipx = createIPX({});
19
- const middleware = createIPXMiddleware(ipx);
20
- await listen(middleware, {
21
- clipboard: false
22
- });
23
- }
24
- main().catch((error) => {
25
- consola.error(error);
26
- process.exit(1);
19
+ const serve = defineCommand({
20
+ meta: {
21
+ description: "Start IPX Server"
22
+ },
23
+ args: {
24
+ dir: {
25
+ type: "string",
26
+ required: false,
27
+ description: "Directory to serve (default: current directory) ENV: IPX_FS_DIR"
28
+ },
29
+ domains: {
30
+ type: "string",
31
+ required: false,
32
+ description: "Allowed domains (comma separated) ENV: IPX_HTTP_DOMAINS"
33
+ },
34
+ ...getArgs()
35
+ },
36
+ async run({ args }) {
37
+ const ipx = createIPX({
38
+ storage: ipxFSStorage({
39
+ dir: args.dir
40
+ }),
41
+ httpStorage: ipxHttpStorage({
42
+ domains: args.domains
43
+ })
44
+ });
45
+ await listen(createIPXNodeServer(ipx), {
46
+ name: "IPX",
47
+ ...parseArgs(args)
48
+ });
49
+ }
50
+ });
51
+ const main = defineCommand({
52
+ meta: {
53
+ name,
54
+ version,
55
+ description
56
+ },
57
+ subCommands: {
58
+ serve
59
+ }
27
60
  });
61
+ runMain(main);