@sudobility/svgr_types 1.0.6 → 1.0.7
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 +70 -0
- package/dist/index.d.ts +138 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +70 -0
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/dist/index.cjs
CHANGED
|
@@ -1,10 +1,50 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @fileoverview SVGR type definitions - shared contract between API and clients.
|
|
4
|
+
* Provides types for image-to-SVG conversion requests/responses and helper functions
|
|
5
|
+
* for constructing standardized API responses.
|
|
6
|
+
* @module @sudobility/svgr_types
|
|
7
|
+
*/
|
|
2
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
9
|
exports.successResponse = successResponse;
|
|
4
10
|
exports.errorResponse = errorResponse;
|
|
5
11
|
// ============================================
|
|
6
12
|
// Helper Functions
|
|
7
13
|
// ============================================
|
|
14
|
+
/**
|
|
15
|
+
* Constructs a successful API response with the given data.
|
|
16
|
+
*
|
|
17
|
+
* Wraps arbitrary data in the standard {@link BaseResponse} success envelope with a current timestamp.
|
|
18
|
+
* The generic type parameter T allows the data to be any shape.
|
|
19
|
+
*
|
|
20
|
+
* @template T - The type of data being returned
|
|
21
|
+
* @param {T} data - The conversion result or other data to include in the success response
|
|
22
|
+
* @returns {BaseResponse<T>} A success response object with success=true, data, and timestamp
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* // For ConvertResult
|
|
26
|
+
* const response = successResponse({
|
|
27
|
+
* svg: '<svg>...</svg>',
|
|
28
|
+
* width: 100,
|
|
29
|
+
* height: 100
|
|
30
|
+
* });
|
|
31
|
+
* // Returns:
|
|
32
|
+
* // {
|
|
33
|
+
* // success: true,
|
|
34
|
+
* // data: { svg: '...', width: 100, height: 100 },
|
|
35
|
+
* // timestamp: '2026-02-23T12:34:56.789Z'
|
|
36
|
+
* // }
|
|
37
|
+
*
|
|
38
|
+
* @example
|
|
39
|
+
* // Generic usage with any data type
|
|
40
|
+
* const msgResponse = successResponse({ message: 'Processing started' });
|
|
41
|
+
* // Returns:
|
|
42
|
+
* // {
|
|
43
|
+
* // success: true,
|
|
44
|
+
* // data: { message: 'Processing started' },
|
|
45
|
+
* // timestamp: '2026-02-23T12:34:56.789Z'
|
|
46
|
+
* // }
|
|
47
|
+
*/
|
|
8
48
|
function successResponse(data) {
|
|
9
49
|
return {
|
|
10
50
|
success: true,
|
|
@@ -12,6 +52,36 @@ function successResponse(data) {
|
|
|
12
52
|
timestamp: new Date().toISOString(),
|
|
13
53
|
};
|
|
14
54
|
}
|
|
55
|
+
/**
|
|
56
|
+
* Constructs an error API response with the given error message.
|
|
57
|
+
*
|
|
58
|
+
* Creates a standard {@link BaseResponse} error envelope with success=false, no data field,
|
|
59
|
+
* and a current timestamp. The return type uses `never` for the generic parameter to indicate
|
|
60
|
+
* that successful data cannot exist in error responses.
|
|
61
|
+
*
|
|
62
|
+
* @param {string} error - A descriptive error message
|
|
63
|
+
* @returns {BaseResponse<never>} An error response object with success=false, error message, and timestamp
|
|
64
|
+
*
|
|
65
|
+
* @example
|
|
66
|
+
* // For conversion errors
|
|
67
|
+
* const response = errorResponse('Invalid image format: expected PNG, JPG, WEBP, BMP, or GIF');
|
|
68
|
+
* // Returns:
|
|
69
|
+
* // {
|
|
70
|
+
* // success: false,
|
|
71
|
+
* // error: 'Invalid image format: expected PNG, JPG, WEBP, BMP, or GIF',
|
|
72
|
+
* // timestamp: '2026-02-23T12:34:56.789Z'
|
|
73
|
+
* // }
|
|
74
|
+
*
|
|
75
|
+
* @example
|
|
76
|
+
* // For other errors
|
|
77
|
+
* const response = errorResponse('Quality must be between 1 and 10');
|
|
78
|
+
* // Returns:
|
|
79
|
+
* // {
|
|
80
|
+
* // success: false,
|
|
81
|
+
* // error: 'Quality must be between 1 and 10',
|
|
82
|
+
* // timestamp: '2026-02-23T12:34:56.789Z'
|
|
83
|
+
* // }
|
|
84
|
+
*/
|
|
15
85
|
function errorResponse(error) {
|
|
16
86
|
return {
|
|
17
87
|
success: false,
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview SVGR type definitions - shared contract between API and clients.
|
|
3
|
+
* Provides types for image-to-SVG conversion requests/responses and helper functions
|
|
4
|
+
* for constructing standardized API responses.
|
|
5
|
+
* @module @sudobility/svgr_types
|
|
6
|
+
*/
|
|
1
7
|
export type { ApiResponse, BaseResponse } from '@sudobility/types';
|
|
2
|
-
/**
|
|
8
|
+
/**
|
|
9
|
+
* Request payload for POST /convert endpoint.
|
|
10
|
+
*
|
|
11
|
+
* Contains a raster image to be converted to SVG along with optional conversion parameters.
|
|
12
|
+
*
|
|
13
|
+
* @interface ConvertRequest
|
|
14
|
+
* @property {string} original - Base64-encoded raster image data (PNG, JPG, WEBP, BMP, or GIF format)
|
|
15
|
+
* @property {string} [filename] - Optional filename for metadata or audit purposes
|
|
16
|
+
* @property {number} [quality] - Conversion quality level from 1 to 10, where 1 produces the smallest file
|
|
17
|
+
* and 10 produces the highest fidelity output. Default is 5 for balanced results.
|
|
18
|
+
* @property {boolean} [transparentBg] - If true, removes the background from the resulting SVG,
|
|
19
|
+
* making it transparent. Default is false.
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* const request: ConvertRequest = {
|
|
23
|
+
* original: 'data:image/png;base64,...',
|
|
24
|
+
* filename: 'logo.png',
|
|
25
|
+
* quality: 7,
|
|
26
|
+
* transparentBg: true
|
|
27
|
+
* };
|
|
28
|
+
*/
|
|
3
29
|
export interface ConvertRequest {
|
|
4
30
|
/** Base64-encoded raster image (PNG, JPG, WEBP, BMP, GIF) */
|
|
5
31
|
original: string;
|
|
@@ -10,7 +36,23 @@ export interface ConvertRequest {
|
|
|
10
36
|
/** Remove the background from the SVG, making it transparent. Default: false */
|
|
11
37
|
transparentBg?: boolean;
|
|
12
38
|
}
|
|
13
|
-
/**
|
|
39
|
+
/**
|
|
40
|
+
* Result returned from a successful SVG conversion.
|
|
41
|
+
*
|
|
42
|
+
* Contains the converted SVG content and metadata about the original image dimensions.
|
|
43
|
+
*
|
|
44
|
+
* @interface ConvertResult
|
|
45
|
+
* @property {string} svg - The complete SVG content as a valid SVG string, ready to be rendered or saved
|
|
46
|
+
* @property {number} width - Width of the original raster image in pixels
|
|
47
|
+
* @property {number} height - Height of the original raster image in pixels
|
|
48
|
+
*
|
|
49
|
+
* @example
|
|
50
|
+
* const result: ConvertResult = {
|
|
51
|
+
* svg: '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100">...</svg>',
|
|
52
|
+
* width: 500,
|
|
53
|
+
* height: 500
|
|
54
|
+
* };
|
|
55
|
+
*/
|
|
14
56
|
export interface ConvertResult {
|
|
15
57
|
/** SVG content as a string */
|
|
16
58
|
svg: string;
|
|
@@ -20,7 +62,101 @@ export interface ConvertResult {
|
|
|
20
62
|
height: number;
|
|
21
63
|
}
|
|
22
64
|
import type { BaseResponse } from '@sudobility/types';
|
|
65
|
+
/**
|
|
66
|
+
* Full API response for conversion requests.
|
|
67
|
+
*
|
|
68
|
+
* A discriminated union type that wraps a {@link ConvertResult} in the standard response envelope.
|
|
69
|
+
* When success is true, includes the conversion result; when false, includes an error message.
|
|
70
|
+
*
|
|
71
|
+
* This type alias uses the {@link BaseResponse} generic from @sudobility/types, which provides:
|
|
72
|
+
* - `success: boolean` - Whether the operation succeeded
|
|
73
|
+
* - `data?: ConvertResult` - Present only when success is true
|
|
74
|
+
* - `error?: string` - Present only when success is false
|
|
75
|
+
* - `timestamp: string` - ISO 8601 timestamp of the response
|
|
76
|
+
*
|
|
77
|
+
* @typedef {BaseResponse<ConvertResult>} ConvertResponse
|
|
78
|
+
*
|
|
79
|
+
* @example
|
|
80
|
+
* // Success response
|
|
81
|
+
* const success: ConvertResponse = {
|
|
82
|
+
* success: true,
|
|
83
|
+
* data: { svg: '...', width: 500, height: 500 },
|
|
84
|
+
* timestamp: '2026-02-23T12:34:56.789Z'
|
|
85
|
+
* };
|
|
86
|
+
*
|
|
87
|
+
* @example
|
|
88
|
+
* // Error response
|
|
89
|
+
* const error: ConvertResponse = {
|
|
90
|
+
* success: false,
|
|
91
|
+
* error: 'Invalid image format',
|
|
92
|
+
* timestamp: '2026-02-23T12:34:56.789Z'
|
|
93
|
+
* };
|
|
94
|
+
*/
|
|
23
95
|
export type ConvertResponse = BaseResponse<ConvertResult>;
|
|
96
|
+
/**
|
|
97
|
+
* Constructs a successful API response with the given data.
|
|
98
|
+
*
|
|
99
|
+
* Wraps arbitrary data in the standard {@link BaseResponse} success envelope with a current timestamp.
|
|
100
|
+
* The generic type parameter T allows the data to be any shape.
|
|
101
|
+
*
|
|
102
|
+
* @template T - The type of data being returned
|
|
103
|
+
* @param {T} data - The conversion result or other data to include in the success response
|
|
104
|
+
* @returns {BaseResponse<T>} A success response object with success=true, data, and timestamp
|
|
105
|
+
*
|
|
106
|
+
* @example
|
|
107
|
+
* // For ConvertResult
|
|
108
|
+
* const response = successResponse({
|
|
109
|
+
* svg: '<svg>...</svg>',
|
|
110
|
+
* width: 100,
|
|
111
|
+
* height: 100
|
|
112
|
+
* });
|
|
113
|
+
* // Returns:
|
|
114
|
+
* // {
|
|
115
|
+
* // success: true,
|
|
116
|
+
* // data: { svg: '...', width: 100, height: 100 },
|
|
117
|
+
* // timestamp: '2026-02-23T12:34:56.789Z'
|
|
118
|
+
* // }
|
|
119
|
+
*
|
|
120
|
+
* @example
|
|
121
|
+
* // Generic usage with any data type
|
|
122
|
+
* const msgResponse = successResponse({ message: 'Processing started' });
|
|
123
|
+
* // Returns:
|
|
124
|
+
* // {
|
|
125
|
+
* // success: true,
|
|
126
|
+
* // data: { message: 'Processing started' },
|
|
127
|
+
* // timestamp: '2026-02-23T12:34:56.789Z'
|
|
128
|
+
* // }
|
|
129
|
+
*/
|
|
24
130
|
export declare function successResponse<T>(data: T): BaseResponse<T>;
|
|
131
|
+
/**
|
|
132
|
+
* Constructs an error API response with the given error message.
|
|
133
|
+
*
|
|
134
|
+
* Creates a standard {@link BaseResponse} error envelope with success=false, no data field,
|
|
135
|
+
* and a current timestamp. The return type uses `never` for the generic parameter to indicate
|
|
136
|
+
* that successful data cannot exist in error responses.
|
|
137
|
+
*
|
|
138
|
+
* @param {string} error - A descriptive error message
|
|
139
|
+
* @returns {BaseResponse<never>} An error response object with success=false, error message, and timestamp
|
|
140
|
+
*
|
|
141
|
+
* @example
|
|
142
|
+
* // For conversion errors
|
|
143
|
+
* const response = errorResponse('Invalid image format: expected PNG, JPG, WEBP, BMP, or GIF');
|
|
144
|
+
* // Returns:
|
|
145
|
+
* // {
|
|
146
|
+
* // success: false,
|
|
147
|
+
* // error: 'Invalid image format: expected PNG, JPG, WEBP, BMP, or GIF',
|
|
148
|
+
* // timestamp: '2026-02-23T12:34:56.789Z'
|
|
149
|
+
* // }
|
|
150
|
+
*
|
|
151
|
+
* @example
|
|
152
|
+
* // For other errors
|
|
153
|
+
* const response = errorResponse('Quality must be between 1 and 10');
|
|
154
|
+
* // Returns:
|
|
155
|
+
* // {
|
|
156
|
+
* // success: false,
|
|
157
|
+
* // error: 'Quality must be between 1 and 10',
|
|
158
|
+
* // timestamp: '2026-02-23T12:34:56.789Z'
|
|
159
|
+
* // }
|
|
160
|
+
*/
|
|
25
161
|
export declare function errorResponse(error: string): BaseResponse<never>;
|
|
26
162
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAKH,YAAY,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAMnE;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,WAAW,cAAc;IAC7B,6DAA6D;IAC7D,QAAQ,EAAE,MAAM,CAAC;IACjB,qCAAqC;IACrC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,gFAAgF;IAChF,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,gFAAgF;IAChF,aAAa,CAAC,EAAE,OAAO,CAAC;CACzB;AAMD;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,WAAW,aAAa;IAC5B,8BAA8B;IAC9B,GAAG,EAAE,MAAM,CAAC;IACZ,qCAAqC;IACrC,KAAK,EAAE,MAAM,CAAC;IACd,sCAAsC;IACtC,MAAM,EAAE,MAAM,CAAC;CAChB;AAKD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAEtD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,MAAM,MAAM,eAAe,GAAG,YAAY,CAAC,aAAa,CAAC,CAAC;AAM1D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,wBAAgB,eAAe,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,GAAG,YAAY,CAAC,CAAC,CAAC,CAM3D;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,GAAG,YAAY,CAAC,KAAK,CAAC,CAMhE"}
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview SVGR type definitions - shared contract between API and clients.
|
|
3
|
+
* Provides types for image-to-SVG conversion requests/responses and helper functions
|
|
4
|
+
* for constructing standardized API responses.
|
|
5
|
+
* @module @sudobility/svgr_types
|
|
6
|
+
*/
|
|
1
7
|
// ============================================
|
|
2
8
|
// Helper Functions
|
|
3
9
|
// ============================================
|
|
10
|
+
/**
|
|
11
|
+
* Constructs a successful API response with the given data.
|
|
12
|
+
*
|
|
13
|
+
* Wraps arbitrary data in the standard {@link BaseResponse} success envelope with a current timestamp.
|
|
14
|
+
* The generic type parameter T allows the data to be any shape.
|
|
15
|
+
*
|
|
16
|
+
* @template T - The type of data being returned
|
|
17
|
+
* @param {T} data - The conversion result or other data to include in the success response
|
|
18
|
+
* @returns {BaseResponse<T>} A success response object with success=true, data, and timestamp
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* // For ConvertResult
|
|
22
|
+
* const response = successResponse({
|
|
23
|
+
* svg: '<svg>...</svg>',
|
|
24
|
+
* width: 100,
|
|
25
|
+
* height: 100
|
|
26
|
+
* });
|
|
27
|
+
* // Returns:
|
|
28
|
+
* // {
|
|
29
|
+
* // success: true,
|
|
30
|
+
* // data: { svg: '...', width: 100, height: 100 },
|
|
31
|
+
* // timestamp: '2026-02-23T12:34:56.789Z'
|
|
32
|
+
* // }
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* // Generic usage with any data type
|
|
36
|
+
* const msgResponse = successResponse({ message: 'Processing started' });
|
|
37
|
+
* // Returns:
|
|
38
|
+
* // {
|
|
39
|
+
* // success: true,
|
|
40
|
+
* // data: { message: 'Processing started' },
|
|
41
|
+
* // timestamp: '2026-02-23T12:34:56.789Z'
|
|
42
|
+
* // }
|
|
43
|
+
*/
|
|
4
44
|
export function successResponse(data) {
|
|
5
45
|
return {
|
|
6
46
|
success: true,
|
|
@@ -8,6 +48,36 @@ export function successResponse(data) {
|
|
|
8
48
|
timestamp: new Date().toISOString(),
|
|
9
49
|
};
|
|
10
50
|
}
|
|
51
|
+
/**
|
|
52
|
+
* Constructs an error API response with the given error message.
|
|
53
|
+
*
|
|
54
|
+
* Creates a standard {@link BaseResponse} error envelope with success=false, no data field,
|
|
55
|
+
* and a current timestamp. The return type uses `never` for the generic parameter to indicate
|
|
56
|
+
* that successful data cannot exist in error responses.
|
|
57
|
+
*
|
|
58
|
+
* @param {string} error - A descriptive error message
|
|
59
|
+
* @returns {BaseResponse<never>} An error response object with success=false, error message, and timestamp
|
|
60
|
+
*
|
|
61
|
+
* @example
|
|
62
|
+
* // For conversion errors
|
|
63
|
+
* const response = errorResponse('Invalid image format: expected PNG, JPG, WEBP, BMP, or GIF');
|
|
64
|
+
* // Returns:
|
|
65
|
+
* // {
|
|
66
|
+
* // success: false,
|
|
67
|
+
* // error: 'Invalid image format: expected PNG, JPG, WEBP, BMP, or GIF',
|
|
68
|
+
* // timestamp: '2026-02-23T12:34:56.789Z'
|
|
69
|
+
* // }
|
|
70
|
+
*
|
|
71
|
+
* @example
|
|
72
|
+
* // For other errors
|
|
73
|
+
* const response = errorResponse('Quality must be between 1 and 10');
|
|
74
|
+
* // Returns:
|
|
75
|
+
* // {
|
|
76
|
+
* // success: false,
|
|
77
|
+
* // error: 'Quality must be between 1 and 10',
|
|
78
|
+
* // timestamp: '2026-02-23T12:34:56.789Z'
|
|
79
|
+
* // }
|
|
80
|
+
*/
|
|
11
81
|
export function errorResponse(error) {
|
|
12
82
|
return {
|
|
13
83
|
success: false,
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AA8GH,+CAA+C;AAC/C,mBAAmB;AACnB,+CAA+C;AAE/C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,MAAM,UAAU,eAAe,CAAI,IAAO;IACxC,OAAO;QACL,OAAO,EAAE,IAAI;QACb,IAAI;QACJ,SAAS,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;KACpC,CAAC;AACJ,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,MAAM,UAAU,aAAa,CAAC,KAAa;IACzC,OAAO;QACL,OAAO,EAAE,KAAK;QACd,KAAK;QACL,SAAS,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;KACpC,CAAC;AACJ,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sudobility/svgr_types",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.7",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.cjs",
|
|
6
6
|
"module": "./dist/index.js",
|
|
@@ -34,11 +34,11 @@
|
|
|
34
34
|
"dist/**/*"
|
|
35
35
|
],
|
|
36
36
|
"peerDependencies": {
|
|
37
|
-
"@sudobility/types": "^1.9.
|
|
37
|
+
"@sudobility/types": "^1.9.54"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
40
|
"@eslint/js": "^9.38.0",
|
|
41
|
-
"@sudobility/types": "^1.9.
|
|
41
|
+
"@sudobility/types": "^1.9.54",
|
|
42
42
|
"@typescript-eslint/eslint-plugin": "^8.46.2",
|
|
43
43
|
"@typescript-eslint/parser": "^8.46.2",
|
|
44
44
|
"eslint": "^9.38.0",
|