node-datalith 0.0.4 → 0.1.1

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.
Files changed (3) hide show
  1. package/lib/lib.d.ts +10 -1
  2. package/lib/lib.js +21 -0
  3. package/package.json +1 -1
package/lib/lib.d.ts CHANGED
@@ -134,6 +134,7 @@ export interface ImagePutOptions extends WithBodyTimeoutOptions {
134
134
  idleTimeout?: number | null;
135
135
  }
136
136
  export type ResourceGetOptions = WithBodyTimeoutOptions;
137
+ export type Resolution = `${1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10}x` | "original";
137
138
  export interface ImageGetOptions extends WithBodyTimeoutOptions {
138
139
  /**
139
140
  * The desired resolution of the image.
@@ -144,7 +145,7 @@ export interface ImageGetOptions extends WithBodyTimeoutOptions {
144
145
  *
145
146
  * @default undefined (Datalith defaults to `"1x"`)
146
147
  */
147
- resolution?: `${1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10}x` | "original";
148
+ resolution?: Resolution;
148
149
  /**
149
150
  * Whether to use a fallback image (in PNG/JPEG format instead of WebP).
150
151
  *
@@ -235,3 +236,11 @@ export declare class Datalith {
235
236
  */
236
237
  convertResourceToImage(id: string, options: DeleteOptions & Pick<ImagePutOptions, "maxWidth" | "maxHeight" | "centerCrop">): Promise<Image>;
237
238
  }
239
+ /**
240
+ * Validates if the input string is a valid center crop string (in the format of `"<float>:<float>"`).
241
+ */
242
+ export declare const validateCenterCrop: (centerCrop?: string) => boolean;
243
+ /**
244
+ * Validates if the given resolution is either `undefined`, `"original"`, or follows the format of `"<positive integer>x"`.
245
+ */
246
+ export declare const validateResolution: (resolution?: string) => resolution is Resolution;
package/lib/lib.js CHANGED
@@ -339,3 +339,24 @@ export class Datalith {
339
339
  }
340
340
  }
341
341
  }
342
+ /**
343
+ * Validates if the input string is a valid center crop string (in the format of `"<float>:<float>"`).
344
+ */
345
+ export const validateCenterCrop = (centerCrop) => {
346
+ if (typeof centerCrop === "undefined") {
347
+ return true;
348
+ }
349
+ return (/^-?\d+\.?\d*:-?\d+\.?\d*$/).test(centerCrop);
350
+ };
351
+ /**
352
+ * Validates if the given resolution is either `undefined`, `"original"`, or follows the format of `"<positive integer>x"`.
353
+ */
354
+ export const validateResolution = (resolution) => {
355
+ if (typeof resolution === "undefined") {
356
+ return true;
357
+ }
358
+ if (resolution === "original") {
359
+ return true;
360
+ }
361
+ return (/^[1-9][0-9]*x$/).test(resolution);
362
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-datalith",
3
- "version": "0.0.4",
3
+ "version": "0.1.1",
4
4
  "description": "Datalith is a file management system powered by SQLite for metadata storage and the file system for file storage. This library can help you conmunicate with Datalith in Node.js.",
5
5
  "type": "module",
6
6
  "exports": "./lib/lib.js",