Skip to content

Commit 0a285dd

Browse files
authored
use enums instead of union types for gravity/resize types
1 parent 1e93784 commit 0a285dd

File tree

7 files changed

+36
-20
lines changed

7 files changed

+36
-20
lines changed

example/pages/index.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import Head from 'next/head';
44
import ProxyImage, {
55
ImgProxyParamBuilder,
66
buildProxyImagePath,
7+
ResizeType,
8+
GravityType,
79
} from '../../dist';
810

911
const demoContent: {
@@ -65,12 +67,12 @@ const demoContent: {
6567
height: 100,
6668
proxyParams: new ImgProxyParamBuilder()
6769
.resize({
68-
type: 'fit',
70+
type: ResizeType.FILL,
6971
width: 100,
7072
height: 100,
7173
enlarge: true,
7274
gravity: {
73-
type: 'no',
75+
type: GravityType.NORTH,
7476
center: {
7577
x: 10,
7678
y: 10,

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@bitpatty/next-image-s3-imgproxy-loader",
3-
"version": "0.1.1",
3+
"version": "0.2.0",
44
"description": "imgproxy S3 extension for next/image",
55
"author": "Matteias Collet <matteias.collet@bluewin.ch>",
66
"main": "dist/index.js",

src/enums/gravity-type.enum.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
enum GravityType {
2+
NORTH = 'no',
3+
SOUTH = 'so',
4+
EAST = 'ea',
5+
WEST = 'we',
6+
NORTHEAST = 'noea',
7+
NORTHWEST = 'nowe',
8+
SOUTHEAST = 'soea',
9+
SOUTHWEST = 'sowe',
10+
CENTER = 'center',
11+
}
12+
13+
export default GravityType;

src/enums/resize-type.enum.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
enum ResizeType {
2+
FIT = 'fit',
3+
FILL = 'fill',
4+
AUTO = 'auto',
5+
}
6+
7+
export default ResizeType;

src/index.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import { request as httpsRequest } from 'https';
77
import { ServerResponse, request as httpRequest } from 'http';
88

99
import ImgProxyParamBuilder from './param-builder';
10+
import GravityType from './enums/gravity-type.enum';
11+
import ResizeType from './enums/resize-type.enum';
1012

1113
const IMGPROXY_ENDPOINT = '/_next/imgproxy';
1214

@@ -119,8 +121,10 @@ const ProxyImage = ({
119121

120122
export default ProxyImage;
121123
export {
124+
IMGPROXY_ENDPOINT,
122125
buildProxyImagePath,
123126
imageOptimizer,
124-
IMGPROXY_ENDPOINT,
125127
ImgProxyParamBuilder,
128+
GravityType,
129+
ResizeType,
126130
};

src/param-builder.ts

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,5 @@
1-
type ResizeType = 'fit' | 'fill' | 'auto';
2-
3-
type GravityType =
4-
| 'no'
5-
| 'so'
6-
| 'ea'
7-
| 'we'
8-
| 'noea'
9-
| 'nowe'
10-
| 'soea'
11-
| 'sowe'
12-
| 'ce';
1+
import GravityType from './enums/gravity-type.enum';
2+
import ResizeType from './enums/resize-type.enum';
133

144
type ForwardType = Partial<ImgProxyParamBuilder> & {
155
modifiers: string[];
@@ -36,7 +26,7 @@ class ImgProxyParamBuilder {
3626
enlarge?: boolean;
3727
extend?: boolean;
3828
gravity?: {
39-
type: Omit<GravityType, 'sm'>;
29+
type: GravityType;
4030
center?: {
4131
x: number;
4232
y: number;
@@ -49,7 +39,7 @@ class ImgProxyParamBuilder {
4939
options
5040
? [
5141
'resize',
52-
type ?? 'fit',
42+
type ?? ResizeType.FIT,
5343
width ?? 0,
5444
height ?? 0,
5545
!!enlarge,

0 commit comments

Comments
 (0)