@cloudparker/moldex.js 0.0.50 → 0.0.52

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 (50) hide show
  1. package/dist/services/dialog/dialog-service.d.ts +27 -0
  2. package/dist/services/dialog/dialog-service.js +110 -0
  3. package/dist/services/index.d.ts +6 -0
  4. package/dist/services/index.js +6 -1
  5. package/dist/services/navigation/navigation-service.js +5 -5
  6. package/dist/services/utils/color-service.d.ts +46 -0
  7. package/dist/services/utils/color-service.js +73 -0
  8. package/dist/services/utils/download-service.d.ts +91 -0
  9. package/dist/services/utils/download-service.js +159 -0
  10. package/dist/services/utils/file-service.d.ts +138 -0
  11. package/dist/services/utils/file-service.js +258 -0
  12. package/dist/services/utils/http-service.d.ts +77 -0
  13. package/dist/services/utils/http-service.js +158 -0
  14. package/dist/services/utils/image-service.d.ts +81 -0
  15. package/dist/services/utils/image-service.js +194 -0
  16. package/dist/services/utils/utils-service.d.ts +257 -55
  17. package/dist/services/utils/utils-service.js +347 -327
  18. package/dist/tailwind.css +1 -1
  19. package/dist/views/core/index.js +0 -1
  20. package/dist/views/core/input/components/color-field/color-field.svelte +2 -2
  21. package/dist/views/core/input/components/color-field/color-field.svelte.d.ts +2 -11
  22. package/dist/views/core/input/components/combobox-field/combobox-field.svelte +2 -2
  23. package/dist/views/core/input/components/date-field/date-field.svelte +1 -1
  24. package/dist/views/core/input/components/date-field/date-field.svelte.d.ts +1 -10
  25. package/dist/views/core/input/components/datetime-field/datetime-field.svelte +1 -1
  26. package/dist/views/core/input/components/datetime-field/datetime-field.svelte.d.ts +1 -10
  27. package/dist/views/core/input/components/email-field/email-field.svelte +1 -1
  28. package/dist/views/core/input/components/email-field/email-field.svelte.d.ts +1 -10
  29. package/dist/views/core/input/components/file-field/file-field.svelte +15 -8
  30. package/dist/views/core/input/components/file-field/file-field.svelte.d.ts +2 -11
  31. package/dist/views/core/input/components/number-field/number-field.svelte +1 -1
  32. package/dist/views/core/input/components/number-field/number-field.svelte.d.ts +1 -10
  33. package/dist/views/core/input/components/password-field/password-field.svelte +1 -1
  34. package/dist/views/core/input/components/password-field/password-field.svelte.d.ts +1 -10
  35. package/dist/views/core/input/components/phone-field/phone-field.svelte +1 -1
  36. package/dist/views/core/input/components/phone-field/phone-field.svelte.d.ts +1 -10
  37. package/dist/views/core/input/components/search-field/search-field.svelte +1 -1
  38. package/dist/views/core/input/components/search-field/search-field.svelte.d.ts +1 -10
  39. package/dist/views/core/input/components/text-field/text-field.svelte +1 -1
  40. package/dist/views/core/input/components/text-field/text-field.svelte.d.ts +2 -11
  41. package/dist/views/core/input/components/textarea-field/textarea-field.svelte +1 -1
  42. package/dist/views/core/input/components/textarea-field/textarea-field.svelte.d.ts +2 -11
  43. package/dist/views/core/input/components/time-field/time-field.svelte +1 -1
  44. package/dist/views/core/input/components/time-field/time-field.svelte.d.ts +2 -11
  45. package/dist/views/core/text/components/text-copy/text-copy.svelte +3 -3
  46. package/package.json +2 -2
  47. package/dist/views/core/referrer/components/referrer.svelte +0 -16
  48. package/dist/views/core/referrer/components/referrer.svelte.d.ts +0 -18
  49. package/dist/views/core/referrer/index.d.ts +0 -2
  50. package/dist/views/core/referrer/index.js +0 -2
@@ -0,0 +1,81 @@
1
+ export declare const ACCEPT_IMAGE_FILES: string;
2
+ /**
3
+ * Processes an image file by resizing, reducing file size, and converting it to a specified format based on the provided options.
4
+ * @param file - The original image file.
5
+ * @param options - Options for resizing, compressing, and converting the image.
6
+ * @returns A promise that resolves to a processed File object with the correct filename and extension.
7
+ */
8
+ export declare function processImageFile(file: File, options?: {
9
+ maxWidth?: number;
10
+ maxHeight?: number;
11
+ maxSizeInBytes?: number;
12
+ outputFormat?: 'image/webp' | 'image/jpeg' | 'image/png';
13
+ quality?: number;
14
+ }): Promise<File>;
15
+ /**
16
+ * Generates a new filename based on the original filename and output format.
17
+ * @param originalName - The original filename.
18
+ * @param outputFormat - The desired output format (e.g., 'image/jpeg', 'image/png').
19
+ * @returns A new filename with the correct extension.
20
+ */
21
+ export declare function generateNewFileName(originalName: string, outputFormat: string): string;
22
+ /**
23
+ * Calculates the new dimensions for resizing the image while maintaining aspect ratio.
24
+ * @param img - The original image.
25
+ * @param maxWidth - The maximum width for the new image.
26
+ * @param maxHeight - The maximum height for the new image.
27
+ * @returns An object with the new width and height.
28
+ */
29
+ export declare function calculateNewDimensions(img: HTMLImageElement, maxWidth?: number, maxHeight?: number): {
30
+ width: number;
31
+ height: number;
32
+ };
33
+ /**
34
+ * Compresses an image to reduce its file size to be under the specified max size.
35
+ * @param canvas - The canvas element with the image drawn on it.
36
+ * @param maxSizeInBytes - The maximum allowed size in bytes.
37
+ * @param format - The output format of the image (e.g., 'image/webp', 'image/jpeg').
38
+ * @param initialQuality - The initial image quality (0 to 1).
39
+ * @returns A promise that resolves to a compressed Blob object.
40
+ */
41
+ export declare function compressImage(canvas: HTMLCanvasElement, maxSizeInBytes: number, format: string, initialQuality: number): Promise<Blob>;
42
+ /**
43
+ * Reads the contents of a given File object as an HTMLImageElement.
44
+ *
45
+ * This function uses the FileReader API to read the file content and returns it as an HTMLImageElement.
46
+ * It is useful for loading images for display or further processing.
47
+ *
48
+ * @param file - The File object to be read and converted into an HTMLImageElement.
49
+ * @returns A promise that resolves to an HTMLImageElement representing the image content of the file.
50
+ *
51
+ * @throws An error if the file could not be read or if the image could not be loaded.
52
+ *
53
+ * @example
54
+ * // Create an image file and read it as an HTMLImageElement
55
+ * const imageFile = new File([ binary data here , 'example.png', { type: 'image/png' });
56
+ * readFileAsImage(imageFile).then((img) => {
57
+ * document.body.appendChild(img); // Display the image on the page
58
+ * });
59
+ */
60
+ export declare function readFileAsImage(file: File): Promise<HTMLImageElement>;
61
+ /**
62
+ * Converts a Base64 or Data URL string into an HTMLImageElement.
63
+ *
64
+ * This function creates an HTMLImageElement from a given Base64 or Data URL string.
65
+ * It is useful for displaying images on the page or performing further image processing.
66
+ *
67
+ * @param dataUrl - The Base64 or Data URL string representing the image.
68
+ * @returns A promise that resolves to an HTMLImageElement when the image is successfully loaded.
69
+ *
70
+ * @throws An error if the image cannot be loaded.
71
+ *
72
+ * @example
73
+ * // Convert a Base64 string to an image element and append it to the document
74
+ * const base64String = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAA...';
75
+ * dataUrlToImage(base64String).then((img) => {
76
+ * document.body.appendChild(img); // Display the image on the page
77
+ * }).catch((error) => {
78
+ * console.error('Failed to load image:', error.message);
79
+ * });
80
+ */
81
+ export declare function dataUrlToImage(dataUrl: string): Promise<HTMLImageElement>;
@@ -0,0 +1,194 @@
1
+ import { readFileAsDataURL } from "./file-service";
2
+ export const ACCEPT_IMAGE_FILES = ".png,.PNG,.jpg,.jpg,.jepg,.JPEG,.webp,.WEBP";
3
+ /**
4
+ * Processes an image file by resizing, reducing file size, and converting it to a specified format based on the provided options.
5
+ * @param file - The original image file.
6
+ * @param options - Options for resizing, compressing, and converting the image.
7
+ * @returns A promise that resolves to a processed File object with the correct filename and extension.
8
+ */
9
+ export async function processImageFile(file, options) {
10
+ // Return the original file if no processing is needed
11
+ if (!options?.maxWidth && !options?.maxHeight && !options?.maxSizeInBytes && !options?.outputFormat) {
12
+ return file;
13
+ }
14
+ // Read the image as a data URL
15
+ const imageDataUrl = await readFileAsDataURL(file);
16
+ const img = new Image();
17
+ return new Promise((resolve, reject) => {
18
+ img.onload = async () => {
19
+ // Create a canvas to resize/compress/convert the image
20
+ const canvas = document.createElement('canvas');
21
+ const context = canvas.getContext('2d');
22
+ // Calculate the new dimensions
23
+ const { width, height } = calculateNewDimensions(img, options.maxWidth, options.maxHeight);
24
+ canvas.width = width;
25
+ canvas.height = height;
26
+ // Draw the image on the canvas
27
+ context?.drawImage(img, 0, 0, width, height);
28
+ // Determine the output format and quality
29
+ const outputFormat = options?.outputFormat || file.type;
30
+ const quality = options?.quality !== undefined ? options.quality : 0.8; // Default quality 80%
31
+ // Convert canvas to Blob (compressed image in specified format)
32
+ canvas.toBlob(async (blob) => {
33
+ if (!blob) {
34
+ reject(new Error('Canvas conversion to Blob failed.'));
35
+ return;
36
+ }
37
+ // Check the file size and reduce quality if necessary
38
+ let compressedBlob = blob;
39
+ if (options.maxSizeInBytes && blob.size > options.maxSizeInBytes) {
40
+ compressedBlob = await compressImage(canvas, options.maxSizeInBytes, outputFormat, quality);
41
+ }
42
+ // Create a new File from the compressed Blob with the correct filename and extension
43
+ const newFileName = generateNewFileName(file.name, outputFormat);
44
+ const processedFile = new File([compressedBlob], newFileName, { type: outputFormat });
45
+ resolve(processedFile);
46
+ }, outputFormat, quality // Use the specified quality
47
+ );
48
+ };
49
+ img.onerror = (error) => reject(error);
50
+ img.src = imageDataUrl; // Set the image source
51
+ });
52
+ }
53
+ /**
54
+ * Generates a new filename based on the original filename and output format.
55
+ * @param originalName - The original filename.
56
+ * @param outputFormat - The desired output format (e.g., 'image/jpeg', 'image/png').
57
+ * @returns A new filename with the correct extension.
58
+ */
59
+ export function generateNewFileName(originalName, outputFormat) {
60
+ // Get the file extension based on the output format
61
+ const formatExtensionMap = {
62
+ 'image/jpeg': '.jpeg',
63
+ 'image/png': '.png',
64
+ 'image/webp': '.webp',
65
+ };
66
+ // Extract the base name without the extension
67
+ const baseName = originalName.replace(/\.[^/.]+$/, ''); // Remove existing extension
68
+ const newExtension = formatExtensionMap[outputFormat] || ''; // Get the new extension
69
+ return `${baseName}${newExtension}`;
70
+ }
71
+ /**
72
+ * Calculates the new dimensions for resizing the image while maintaining aspect ratio.
73
+ * @param img - The original image.
74
+ * @param maxWidth - The maximum width for the new image.
75
+ * @param maxHeight - The maximum height for the new image.
76
+ * @returns An object with the new width and height.
77
+ */
78
+ export function calculateNewDimensions(img, maxWidth, maxHeight) {
79
+ let width = img.width;
80
+ let height = img.height;
81
+ // Maintain aspect ratio while resizing
82
+ if (maxWidth && width > maxWidth) {
83
+ height = (maxWidth / width) * height;
84
+ width = maxWidth;
85
+ }
86
+ if (maxHeight && height > maxHeight) {
87
+ width = (maxHeight / height) * width;
88
+ height = maxHeight;
89
+ }
90
+ return { width, height };
91
+ }
92
+ /**
93
+ * Compresses an image to reduce its file size to be under the specified max size.
94
+ * @param canvas - The canvas element with the image drawn on it.
95
+ * @param maxSizeInBytes - The maximum allowed size in bytes.
96
+ * @param format - The output format of the image (e.g., 'image/webp', 'image/jpeg').
97
+ * @param initialQuality - The initial image quality (0 to 1).
98
+ * @returns A promise that resolves to a compressed Blob object.
99
+ */
100
+ export function compressImage(canvas, maxSizeInBytes, format, initialQuality) {
101
+ return new Promise((resolve) => {
102
+ let quality = initialQuality; // Start with the specified quality
103
+ let compressedBlob = null;
104
+ // Reduce quality iteratively until the Blob size is below the max size
105
+ const compressIteration = () => {
106
+ canvas.toBlob((blob) => {
107
+ if (!blob)
108
+ return;
109
+ if (blob.size <= maxSizeInBytes || quality <= 0.1) {
110
+ resolve(blob);
111
+ }
112
+ else {
113
+ quality -= 0.1; // Reduce quality
114
+ compressIteration(); // Recurse
115
+ }
116
+ }, format, quality);
117
+ };
118
+ compressIteration();
119
+ });
120
+ }
121
+ /**
122
+ * Reads the contents of a given File object as an HTMLImageElement.
123
+ *
124
+ * This function uses the FileReader API to read the file content and returns it as an HTMLImageElement.
125
+ * It is useful for loading images for display or further processing.
126
+ *
127
+ * @param file - The File object to be read and converted into an HTMLImageElement.
128
+ * @returns A promise that resolves to an HTMLImageElement representing the image content of the file.
129
+ *
130
+ * @throws An error if the file could not be read or if the image could not be loaded.
131
+ *
132
+ * @example
133
+ * // Create an image file and read it as an HTMLImageElement
134
+ * const imageFile = new File([ binary data here , 'example.png', { type: 'image/png' });
135
+ * readFileAsImage(imageFile).then((img) => {
136
+ * document.body.appendChild(img); // Display the image on the page
137
+ * });
138
+ */
139
+ export async function readFileAsImage(file) {
140
+ return new Promise((resolve, reject) => {
141
+ const reader = new FileReader();
142
+ // Event handler executed when the file reading operation is completed
143
+ reader.onloadend = () => {
144
+ if (reader.readyState === FileReader.DONE) {
145
+ const img = new Image();
146
+ img.src = reader.result;
147
+ // Resolve the promise when the image is successfully loaded
148
+ img.onload = () => resolve(img);
149
+ // Reject the promise if an error occurs while loading the image
150
+ img.onerror = () => reject(new Error('Failed to load image from file.'));
151
+ }
152
+ else {
153
+ reject(new Error('Failed to read file as Image.'));
154
+ }
155
+ };
156
+ // Event handler executed when an error occurs while reading the file
157
+ reader.onerror = () => {
158
+ reject(new Error(`Error reading file as Image: ${reader.error?.message || 'Unknown error'}`));
159
+ };
160
+ // Read the file content as a data URL for image loading
161
+ reader.readAsDataURL(file);
162
+ });
163
+ }
164
+ /**
165
+ * Converts a Base64 or Data URL string into an HTMLImageElement.
166
+ *
167
+ * This function creates an HTMLImageElement from a given Base64 or Data URL string.
168
+ * It is useful for displaying images on the page or performing further image processing.
169
+ *
170
+ * @param dataUrl - The Base64 or Data URL string representing the image.
171
+ * @returns A promise that resolves to an HTMLImageElement when the image is successfully loaded.
172
+ *
173
+ * @throws An error if the image cannot be loaded.
174
+ *
175
+ * @example
176
+ * // Convert a Base64 string to an image element and append it to the document
177
+ * const base64String = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAA...';
178
+ * dataUrlToImage(base64String).then((img) => {
179
+ * document.body.appendChild(img); // Display the image on the page
180
+ * }).catch((error) => {
181
+ * console.error('Failed to load image:', error.message);
182
+ * });
183
+ */
184
+ export async function dataUrlToImage(dataUrl) {
185
+ return new Promise((resolve, reject) => {
186
+ const img = new Image();
187
+ // Resolve the promise when the image loads successfully
188
+ img.onload = () => resolve(img);
189
+ // Reject the promise if an error occurs while loading the image
190
+ img.onerror = () => reject(new Error('Failed to load image from the provided Data URL or Base64 string.'));
191
+ // Set the source of the image to the provided Data URL
192
+ img.src = dataUrl;
193
+ });
194
+ }
@@ -1,74 +1,276 @@
1
- export declare const FILE_VIEWER_HOST = "https://viewer.cloudparker.com";
2
- export declare const CODE_FILE_EXTENTIONS: string[];
3
- export declare const ACCEPT_IMAGE_FILES: string;
1
+ /**
2
+ * Generates a random number between the specified minimum and maximum values (inclusive of the minimum and exclusive of the maximum).
3
+ *
4
+ * @param min - The minimum value (inclusive) of the random number range.
5
+ * @param max - The maximum value (exclusive) of the random number range.
6
+ * @returns A random number between `min` (inclusive) and `max` (exclusive).
7
+ *
8
+ * @example
9
+ * // Generate a random number between 1 (inclusive) and 5 (exclusive)
10
+ * const randomNumber = random(1, 5); // Possible values: 1.0, 2.4, 3.6, etc.
11
+ *
12
+ * @example
13
+ * // Generate a random number between 10 (inclusive) and 20 (exclusive)
14
+ * const randomNumber = random(10, 20); // Possible values: 10.0, 15.3, 19.8, etc.
15
+ */
4
16
  export declare function random(min: number, max: number): number;
5
- export declare function openFilePicker(opt: {
6
- accept?: string;
7
- multiple?: boolean;
8
- }): Promise<File | File[]>;
9
- /**
10
- * Default quality 1.0
11
- * @param opt
12
- * @returns
13
- */
14
- export declare function resizeImage(opt: {
15
- file: File;
16
- width: number;
17
- height?: number;
18
- fileName?: string;
19
- quality?: number;
20
- type?: string;
21
- }): Promise<File>;
22
- export declare function downloadURI(uri: string, name: string): Promise<void>;
23
- export declare function downloadFile(file: File): Promise<void>;
24
- export declare function downloadBlob(blob: Blob, name: string): Promise<void>;
25
- export declare function fileToDataURL(file: File): Promise<string>;
26
- export declare function fileToText(file: File): Promise<string>;
27
- export declare function fileToBuffer(file: File): Promise<ArrayBuffer>;
28
- export declare function fileToImage(file: File): Promise<HTMLImageElement>;
29
- export declare function dataUrlToImage(base64: string): Promise<any>;
30
- export declare function stripBase64(data: string): string;
17
+ /**
18
+ * Strips the Base64 content from a Data URL string.
19
+ *
20
+ * This function removes the `data:[<mediatype>][;base64],` prefix from a Data URL string,
21
+ * leaving only the Base64 content. If the input is not a valid Data URL, the original input is returned.
22
+ *
23
+ * @param dataUrl - The Data URL string to be stripped.
24
+ * @returns The stripped Base64 content, or the original string if it is not a valid Data URL.
25
+ *
26
+ * @example
27
+ * // Remove the prefix from a Data URL string
28
+ * const dataUrl = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAA...';
29
+ * const base64Content = stripDataUrl(dataUrl);
30
+ * console.log(base64Content); // Output: "iVBORw0KGgoAAAANSUhEUgAA..."
31
+ */
32
+ export declare function stripDataUrl(dataUrl: string): string;
31
33
  /**
32
34
  * Function to download content from a given URL and convert it to a Base64-encoded string.
33
35
  * @param url - The URL to download the content from.
34
36
  * @returns A promise that resolves to the Base64-encoded string of the downloaded content.
35
37
  */
36
- export declare function urlToBase64(url: string): Promise<string>;
37
- export declare function urlToFile(url: string, givenFileName?: string, givenMimeType?: string): Promise<File>;
38
- export declare function dataUrlToFile(url: string, givenFileName?: string, givenMimeType?: string): Promise<File>;
39
- export declare function bufferToFile(buffer: ArrayBuffer, filename: string, mimeType: string): Promise<File>;
40
- export declare function postData(url?: string, data?: {}): Promise<any>;
41
- export declare function fileNameAndExt(filename: string): {
42
- name: string;
43
- ext: string | undefined;
44
- };
45
- export declare function isValidateEmail(email: string): boolean;
46
- export declare function isValidURL(str: string): boolean;
47
- export declare function mailto({ to, body, subject }: {
38
+ export declare function readUrlAsBase64(url: string): Promise<string>;
39
+ /**
40
+ * Validates if a given string is a valid email address.
41
+ *
42
+ * This function uses a regular expression to validate email addresses based on common patterns.
43
+ *
44
+ * @param email - The email address string to validate.
45
+ * @returns A boolean indicating whether the email is valid.
46
+ *
47
+ * @example
48
+ * const isValid = isValidEmailAddress('test@example.com');
49
+ * console.log(isValid); // Output: true
50
+ */
51
+ export declare function isValidEmailAddress(email: string): boolean;
52
+ /**
53
+ * Validates if a given string is a valid URL.
54
+ *
55
+ * This function uses a regular expression to validate URLs based on common URL patterns.
56
+ *
57
+ * @param url - The URL string to validate.
58
+ * @returns A boolean indicating whether the URL is valid.
59
+ *
60
+ * @example
61
+ * const isValid = isValidUrl('https://www.example.com');
62
+ * console.log(isValid); // Output: true
63
+ */
64
+ export declare function isValidUrl(url: string): boolean;
65
+ /**
66
+ * Creates a mailto URI and opens it in the user's default email client.
67
+ *
68
+ * This function constructs a mailto URI based on the provided email details and opens it using `window.open`.
69
+ * It supports specifying the recipient, subject, and body of the email.
70
+ *
71
+ * @param param - An object containing the email details:
72
+ * - `to`: The recipient email address.
73
+ * - `body`: Optional. The body content of the email.
74
+ * - `subject`: Optional. The subject of the email.
75
+ *
76
+ * @example
77
+ * // Create a mailto link with recipient, subject, and body
78
+ * createMailtoLink({
79
+ * to: 'recipient@example.com',
80
+ * subject: 'Hello',
81
+ * body: 'This is a sample email message.'
82
+ * });
83
+ */
84
+ export declare function createMailtoLink({ to, body, subject }: {
48
85
  to: string;
49
- body: string;
50
- subject: string;
86
+ body?: string;
87
+ subject?: string;
51
88
  }): void;
52
- export declare function copyText(str: string): void;
53
- export declare function copyRichText(node: HTMLElement): void;
54
- export declare function download(data: string, filename: string, type: string): void;
89
+ /**
90
+ * Copies the provided text or HTML content to the clipboard.
91
+ *
92
+ * This function handles copying both plain text and rich text (HTML) content.
93
+ * It uses the Clipboard API where available and falls back to older methods for unsupported browsers.
94
+ *
95
+ * @param content - The content to be copied to the clipboard. It can be either a string (plain text) or an HTMLElement (rich text).
96
+ * @returns A promise that resolves to `true` if the copy operation is successful, or `false` otherwise.
97
+ *
98
+ * @example
99
+ * // Copy plain text to clipboard
100
+ * copyToClipboard('Hello, World!').then((success) => {
101
+ * console.log(success ? 'Copied successfully!' : 'Failed to copy.');
102
+ * });
103
+ *
104
+ * @example
105
+ * // Copy rich text (HTML element) to clipboard
106
+ * const element = document.getElementById('myElement');
107
+ * if (element) {
108
+ * copyToClipboard(element).then((success) => {
109
+ * console.log(success ? 'Copied successfully!' : 'Failed to copy.');
110
+ * });
111
+ * }
112
+ */
113
+ export declare function copyToClipboard(content: string | HTMLElement): Promise<boolean>;
114
+ /**
115
+ * Formats a string by replacing placeholders `{index}` with corresponding arguments.
116
+ *
117
+ * This function replaces placeholders in the format `{0}`, `{1}`, etc., in the provided string
118
+ * with the corresponding values from the `args` array.
119
+ *
120
+ * @param str - The string containing placeholders.
121
+ * @param args - The values to replace the placeholders with.
122
+ * @returns A formatted string with the placeholders replaced by the corresponding arguments.
123
+ *
124
+ * @example
125
+ * const formatted = formatString('Hello, {0}!', 'World');
126
+ * console.log(formatted); // Output: "Hello, World!"
127
+ */
55
128
  export declare function formatString(str: string, ...args: any[]): string;
56
- export declare function fileSizeString(size: number): string;
57
- export declare function delay(mills?: number): Promise<unknown>;
129
+ /**
130
+ * Delays the execution of code for a specified number of milliseconds.
131
+ *
132
+ * This function returns a promise that resolves after the specified delay.
133
+ *
134
+ * @param milliseconds - The number of milliseconds to wait before resolving the promise. Default is 0.
135
+ * @returns A promise that resolves after the specified delay.
136
+ *
137
+ * @example
138
+ * delay(1000).then(() => console.log('1 second later'));
139
+ */
140
+ export declare function delay(milliseconds?: number): Promise<void>;
141
+ /**
142
+ * Sorts an array of objects or values based on a specified field or value.
143
+ *
144
+ * This function sorts an array of objects based on a specified field or directly sorts an array of values.
145
+ * It supports both ascending and descending orders and can handle date values.
146
+ *
147
+ * @typeParam T - The type of elements in the array.
148
+ * @param param - An object containing the array to sort, the field to sort by (optional),
149
+ * whether to sort in descending order, and whether to sort as date values.
150
+ * @param param.array - The array of objects or values to sort.
151
+ * @param param.field - Optional. The field of the objects to sort by.
152
+ * @param param.desc - Optional. If true, sorts in descending order. Default is false (ascending).
153
+ * @param param.isDate - Optional. If true, sorts the values as dates.
154
+ * @returns The sorted array.
155
+ *
156
+ * @example
157
+ * const arr = [{ name: 'Alice' }, { name: 'Bob' }];
158
+ * const sortedArr = sort({ array: arr, field: 'name', desc: true });
159
+ * console.log(sortedArr); // Output: [{ name: 'Bob' }, { name: 'Alice' }]
160
+ */
58
161
  export declare function sort<T>({ array, field, desc, isDate }: {
59
162
  array: T[];
60
- field?: string;
163
+ field?: keyof T;
61
164
  desc?: boolean;
62
165
  isDate?: boolean;
63
166
  }): T[];
167
+ /**
168
+ * Triggers a vibration effect on supported devices.
169
+ *
170
+ * This function uses the Vibration API to trigger a vibration effect. If the Vibration API is not
171
+ * supported or if permissions are not granted, the function will have no effect.
172
+ *
173
+ * @param value - A single number representing the duration of the vibration in milliseconds, or
174
+ * an array of numbers representing vibration patterns.
175
+ *
176
+ * @example
177
+ * // Single vibration for 200 milliseconds
178
+ * vibrate(200);
179
+ *
180
+ * @example
181
+ * // Vibration pattern: 200ms on, 100ms off, 200ms on
182
+ * vibrate([200, 100, 200]);
183
+ */
64
184
  export declare function vibrate(value?: number | number[]): void;
185
+ /**
186
+ * Plays a simple click effect using the vibration API (if supported).
187
+ *
188
+ * This function triggers a short vibration effect to simulate a click or feedback action on devices
189
+ * that support the Vibration API.
190
+ *
191
+ * @example
192
+ * playClickEffect(); // Triggers a short vibration effect.
193
+ */
65
194
  export declare function playClickEffect(): void;
66
- export declare function toArrayByKey(key: string, obj?: any): any[];
67
- export declare function convertNumToAlphabates(num: number): string;
68
- export declare function fetchText(url: string): Promise<string>;
195
+ /**
196
+ * Converts an object into an array of its values, attaching a specified key to each value.
197
+ *
198
+ * This function takes an object and converts it into an array of its values, where each value is
199
+ * augmented with a new property specified by the `key` parameter. The property is set to the key
200
+ * of the original object.
201
+ *
202
+ * @param key - The property name to attach to each value.
203
+ * @param obj - The object to be converted to an array.
204
+ * @returns An array of values with the specified key attached.
205
+ *
206
+ * @example
207
+ * const obj = { a: { name: 'Alice' }, b: { name: 'Bob' } };
208
+ * const array = toArrayByKey('id', obj);
209
+ * console.log(array); // Output: [{ name: 'Alice', id: 'a' }, { name: 'Bob', id: 'b' }]
210
+ */
211
+ export declare function toArrayByKey(key: string, obj?: Record<string, any>): any[];
212
+ /**
213
+ * Converts a numeric string into its corresponding alphabets (0-9 => a-j).
214
+ *
215
+ * This function maps each digit in the provided number to its corresponding alphabet:
216
+ * - 0 => a, 1 => b, 2 => c, ... , 9 => j.
217
+ *
218
+ * @param num - The number to be converted to a string of alphabets.
219
+ * @returns A string representing the number converted to alphabets.
220
+ *
221
+ * @example
222
+ * const result = convertNumToAlphabets(123); // "bcd"
223
+ * console.log(result); // Output: "bcd"
224
+ */
225
+ export declare function convertNumToAlphabets(num: number): string;
226
+ /**
227
+ * Converts a number to a currency-formatted string.
228
+ *
229
+ * This function formats a given number as a currency string, using a specified currency symbol
230
+ * (default is '$'). It handles negative values by adding a '-' sign in front of the formatted value.
231
+ *
232
+ * @param value - The numeric value to format as currency.
233
+ * @param symbol - The currency symbol to use. Default is '$'.
234
+ * @returns A formatted string representing the currency value.
235
+ *
236
+ * @example
237
+ * const formattedValue = toCurrency(1234.56, '$');
238
+ * console.log(formattedValue); // Output: "$ 1234.56"
239
+ *
240
+ * @example
241
+ * const formattedNegative = toCurrency(-1234.56, '€');
242
+ * console.log(formattedNegative); // Output: "- € 1234.56"
243
+ */
69
244
  export declare function toCurrency(value?: number, symbol?: string): string;
245
+ /**
246
+ * Converts a length in inches to pixels based on a DPI of 96.
247
+ *
248
+ * This function converts inches to pixels assuming a screen DPI (Dots Per Inch) of 96.
249
+ * It is useful for calculating dimensions in pixels when working with different units of measurement.
250
+ *
251
+ * @param inches - The length in inches to be converted to pixels.
252
+ * @returns The length in pixels corresponding to the provided inches.
253
+ *
254
+ * @throws An error if the input is not a valid number or is negative.
255
+ *
256
+ * @example
257
+ * const pixels = inchToPixel(1); // 1 inch to pixels
258
+ * console.log(pixels); // Output: 96
259
+ */
70
260
  export declare function inchToPixel(inches: number): number;
261
+ /**
262
+ * Converts a length in pixels to inches based on a DPI of 96.
263
+ *
264
+ * This function converts pixels to inches assuming a screen DPI (Dots Per Inch) of 96.
265
+ * It is useful for converting pixel measurements to physical dimensions.
266
+ *
267
+ * @param pixels - The length in pixels to be converted to inches.
268
+ * @returns The length in inches corresponding to the provided pixels.
269
+ *
270
+ * @throws An error if the input is not a valid number or is negative.
271
+ *
272
+ * @example
273
+ * const inches = pixelToInch(96); // 96 pixels to inches
274
+ * console.log(inches); // Output: 1
275
+ */
71
276
  export declare function pixelToInch(pixels: number): number;
72
- export declare function isValidHexColor(hex: string): boolean;
73
- export declare function colorToHex(color: string): string;
74
- export declare function rgbToHex(r: number, g: number, b: number): string;