@creopse/utils 0.0.15 → 0.0.16
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 +21 -0
- package/dist/enums/index.d.ts +3 -0
- package/dist/enums/index.js +3 -0
- package/dist/enums/notification-type.d.ts +1 -1
- package/dist/enums/notification-type.js +1 -1
- package/dist/enums/permission.d.ts +28 -0
- package/dist/enums/permission.js +38 -0
- package/dist/enums/profile-type.d.ts +1 -0
- package/dist/enums/profile-type.js +1 -0
- package/dist/{utils → helpers}/chronos.d.ts +1 -1
- package/dist/{utils → helpers}/chronos.js +1 -1
- package/dist/helpers/constants/constants.d.ts +2 -0
- package/dist/helpers/constants/constants.js +3 -0
- package/dist/helpers/constants/index.d.ts +1 -0
- package/dist/helpers/constants/index.js +1 -0
- package/dist/helpers/constants.d.ts +2 -0
- package/dist/helpers/constants.js +3 -0
- package/dist/helpers/functions/array.d.ts +22 -0
- package/dist/helpers/functions/array.js +42 -0
- package/dist/helpers/functions/browser.d.ts +40 -0
- package/dist/helpers/functions/browser.js +72 -0
- package/dist/helpers/functions/color.d.ts +14 -0
- package/dist/helpers/functions/color.js +26 -0
- package/dist/helpers/functions/file.d.ts +64 -0
- package/dist/helpers/functions/file.js +210 -0
- package/dist/helpers/functions/geo.d.ts +17 -0
- package/dist/helpers/functions/geo.js +31 -0
- package/dist/helpers/functions/image.d.ts +20 -0
- package/dist/helpers/functions/image.js +44 -0
- package/dist/helpers/functions/index.d.ts +13 -0
- package/dist/helpers/functions/index.js +13 -0
- package/dist/helpers/functions/misc.d.ts +55 -0
- package/dist/helpers/functions/misc.js +125 -0
- package/dist/helpers/functions/number.d.ts +15 -0
- package/dist/helpers/functions/number.js +26 -0
- package/dist/helpers/functions/object.d.ts +79 -0
- package/dist/helpers/functions/object.js +141 -0
- package/dist/helpers/functions/string.d.ts +110 -0
- package/dist/helpers/functions/string.js +211 -0
- package/dist/helpers/functions/svg.d.ts +7 -0
- package/dist/helpers/functions/svg.js +25 -0
- package/dist/helpers/functions/time.d.ts +97 -0
- package/dist/helpers/functions/time.js +97 -0
- package/dist/helpers/functions/url.d.ts +46 -0
- package/dist/helpers/functions/url.js +120 -0
- package/dist/{utils → helpers}/functions.d.ts +14 -0
- package/dist/{utils → helpers}/functions.js +26 -1
- package/dist/{utils → helpers}/index.d.ts +1 -1
- package/dist/{utils → helpers}/index.js +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/models/page-section.d.ts +2 -1
- package/dist/models/page-section.js +2 -1
- package/dist/types/core-bridge/api.d.ts +31 -0
- package/dist/types/core-bridge/api.js +1 -0
- package/dist/types/core-bridge/i18n.d.ts +6 -0
- package/dist/types/core-bridge/i18n.js +1 -0
- package/dist/types/core-bridge/index.d.ts +4 -0
- package/dist/types/core-bridge/index.js +4 -0
- package/dist/types/core-bridge/shared-data.d.ts +22 -0
- package/dist/types/core-bridge/shared-data.js +1 -0
- package/dist/types/core-bridge/stores.d.ts +31 -0
- package/dist/types/core-bridge/stores.js +1 -0
- package/dist/types/index.d.ts +2 -0
- package/dist/types/index.js +2 -0
- package/dist/types/plugin.d.ts +30 -0
- package/dist/types/plugin.js +1 -0
- package/package.json +23 -5
- package/dist/tsconfig.tsbuildinfo +0 -1
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023 Noé Gnanih
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/dist/enums/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export * from './content-model/item-creator-type';
|
|
2
2
|
export * from './content-model/access-scope';
|
|
3
3
|
export * from './content-model/intent';
|
|
4
|
+
export * from './access-guard';
|
|
4
5
|
export * from './account-status';
|
|
5
6
|
export * from './ad-content-type';
|
|
6
7
|
export * from './auth-type';
|
|
@@ -14,7 +15,9 @@ export * from './notification-source';
|
|
|
14
15
|
export * from './notification-type';
|
|
15
16
|
export * from './permalink-content-type';
|
|
16
17
|
export * from './profile-type';
|
|
18
|
+
export * from './permission';
|
|
17
19
|
export * from './response-error-code';
|
|
20
|
+
export * from './response-status-code';
|
|
18
21
|
export * from './user-role';
|
|
19
22
|
export * from './video-display-type';
|
|
20
23
|
export * from './video-item-source';
|
package/dist/enums/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export * from './content-model/item-creator-type';
|
|
2
2
|
export * from './content-model/access-scope';
|
|
3
3
|
export * from './content-model/intent';
|
|
4
|
+
export * from './access-guard';
|
|
4
5
|
export * from './account-status';
|
|
5
6
|
export * from './ad-content-type';
|
|
6
7
|
export * from './auth-type';
|
|
@@ -14,7 +15,9 @@ export * from './notification-source';
|
|
|
14
15
|
export * from './notification-type';
|
|
15
16
|
export * from './permalink-content-type';
|
|
16
17
|
export * from './profile-type';
|
|
18
|
+
export * from './permission';
|
|
17
19
|
export * from './response-error-code';
|
|
20
|
+
export * from './response-status-code';
|
|
18
21
|
export * from './user-role';
|
|
19
22
|
export * from './video-display-type';
|
|
20
23
|
export * from './video-item-source';
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export declare enum Permission {
|
|
2
|
+
VIEW_DASHBOARD = "view-dashboard",
|
|
3
|
+
VIEW_ACCOUNT = "view-account",
|
|
4
|
+
EDIT_ACCOUNT = "edit-account",
|
|
5
|
+
VIEW_NOTIFICATIONS = "view-notifications",
|
|
6
|
+
MANAGE_NOTIFICATIONS = "manage-notifications",
|
|
7
|
+
VIEW_ABOUT = "view-about",
|
|
8
|
+
MANAGE_PLUGINS = "manage-plugins",
|
|
9
|
+
MANAGE_APP_SETTINGS = "manage-app-settings",
|
|
10
|
+
VIEW_USERS = "view-users",
|
|
11
|
+
CREATE_USER = "create-user",
|
|
12
|
+
EDIT_USER = "edit-user",
|
|
13
|
+
DELETE_USER = "delete-user",
|
|
14
|
+
VIEW_ROLES = "view-roles",
|
|
15
|
+
MANAGE_ROLES = "manage-roles",
|
|
16
|
+
VIEW_PERMISSIONS = "view-permissions",
|
|
17
|
+
MANAGE_PERMISSIONS = "manage-permissions",
|
|
18
|
+
CREATE_ARTICLE = "create-article",
|
|
19
|
+
EDIT_ARTICLE = "edit-article",
|
|
20
|
+
DELETE_ARTICLE = "delete-article",
|
|
21
|
+
MANAGE_NEWS = "manage-news",
|
|
22
|
+
VIEW_MEDIA = "view-media",
|
|
23
|
+
UPLOAD_MEDIA = "upload-media",
|
|
24
|
+
DELETE_MEDIA = "delete-media",
|
|
25
|
+
VIEW_CONTENT = "view-content",
|
|
26
|
+
MANAGE_CONTENT = "manage-content",
|
|
27
|
+
USE_VISUAL_EDITOR = "use-visual-editor"
|
|
28
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
export var Permission;
|
|
2
|
+
(function (Permission) {
|
|
3
|
+
// Dashboard Module
|
|
4
|
+
Permission["VIEW_DASHBOARD"] = "view-dashboard";
|
|
5
|
+
// Account Module
|
|
6
|
+
Permission["VIEW_ACCOUNT"] = "view-account";
|
|
7
|
+
Permission["EDIT_ACCOUNT"] = "edit-account";
|
|
8
|
+
// Notifications Module
|
|
9
|
+
Permission["VIEW_NOTIFICATIONS"] = "view-notifications";
|
|
10
|
+
Permission["MANAGE_NOTIFICATIONS"] = "manage-notifications";
|
|
11
|
+
// Settings Module
|
|
12
|
+
Permission["VIEW_ABOUT"] = "view-about";
|
|
13
|
+
Permission["MANAGE_PLUGINS"] = "manage-plugins";
|
|
14
|
+
Permission["MANAGE_APP_SETTINGS"] = "manage-app-settings";
|
|
15
|
+
// Users Module
|
|
16
|
+
Permission["VIEW_USERS"] = "view-users";
|
|
17
|
+
Permission["CREATE_USER"] = "create-user";
|
|
18
|
+
Permission["EDIT_USER"] = "edit-user";
|
|
19
|
+
Permission["DELETE_USER"] = "delete-user";
|
|
20
|
+
// Access Module
|
|
21
|
+
Permission["VIEW_ROLES"] = "view-roles";
|
|
22
|
+
Permission["MANAGE_ROLES"] = "manage-roles";
|
|
23
|
+
Permission["VIEW_PERMISSIONS"] = "view-permissions";
|
|
24
|
+
Permission["MANAGE_PERMISSIONS"] = "manage-permissions";
|
|
25
|
+
// News Module
|
|
26
|
+
Permission["CREATE_ARTICLE"] = "create-article";
|
|
27
|
+
Permission["EDIT_ARTICLE"] = "edit-article";
|
|
28
|
+
Permission["DELETE_ARTICLE"] = "delete-article";
|
|
29
|
+
Permission["MANAGE_NEWS"] = "manage-news";
|
|
30
|
+
// Media Module
|
|
31
|
+
Permission["VIEW_MEDIA"] = "view-media";
|
|
32
|
+
Permission["UPLOAD_MEDIA"] = "upload-media";
|
|
33
|
+
Permission["DELETE_MEDIA"] = "delete-media";
|
|
34
|
+
// Content Module
|
|
35
|
+
Permission["VIEW_CONTENT"] = "view-content";
|
|
36
|
+
Permission["MANAGE_CONTENT"] = "manage-content";
|
|
37
|
+
Permission["USE_VISUAL_EDITOR"] = "use-visual-editor";
|
|
38
|
+
})(Permission || (Permission = {}));
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './constants';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './constants';
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Removes duplicate elements from an array based on a specified property.
|
|
3
|
+
*
|
|
4
|
+
* @param {T[]} arr - The array from which duplicate elements will be removed.
|
|
5
|
+
* @param {keyof T} property - The property used to determine duplicates.
|
|
6
|
+
* @returns {T[]} The array with duplicate elements removed.
|
|
7
|
+
*/
|
|
8
|
+
export declare function removeDuplicates<T>(arr: T[], property: keyof T): T[];
|
|
9
|
+
/**
|
|
10
|
+
* Creates a new array of pure JavaScript objects by making a shallow copy of each object in the input array.
|
|
11
|
+
*
|
|
12
|
+
* @param {Array<object>} array - The input array containing objects to be copied.
|
|
13
|
+
* @return {Array<object>} A new array containing the copied objects.
|
|
14
|
+
*/
|
|
15
|
+
export declare function toArrayOfPureJsObjects(array: Array<object>): Array<object>;
|
|
16
|
+
/**
|
|
17
|
+
* Shuffles the elements in an array in place using the Fisher-Yates algorithm.
|
|
18
|
+
*
|
|
19
|
+
* @param {T[]} array - The array to be shuffled.
|
|
20
|
+
* @return {T[]} The shuffled array.
|
|
21
|
+
*/
|
|
22
|
+
export declare function shuffleArray<T>(array: T[]): T[];
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Removes duplicate elements from an array based on a specified property.
|
|
3
|
+
*
|
|
4
|
+
* @param {T[]} arr - The array from which duplicate elements will be removed.
|
|
5
|
+
* @param {keyof T} property - The property used to determine duplicates.
|
|
6
|
+
* @returns {T[]} The array with duplicate elements removed.
|
|
7
|
+
*/
|
|
8
|
+
export function removeDuplicates(arr, property) {
|
|
9
|
+
const uniqueValues = new Set();
|
|
10
|
+
return arr.filter((obj) => {
|
|
11
|
+
const value = obj[property];
|
|
12
|
+
if (!uniqueValues.has(value)) {
|
|
13
|
+
uniqueValues.add(value);
|
|
14
|
+
return true;
|
|
15
|
+
}
|
|
16
|
+
return false;
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Creates a new array of pure JavaScript objects by making a shallow copy of each object in the input array.
|
|
21
|
+
*
|
|
22
|
+
* @param {Array<object>} array - The input array containing objects to be copied.
|
|
23
|
+
* @return {Array<object>} A new array containing the copied objects.
|
|
24
|
+
*/
|
|
25
|
+
export function toArrayOfPureJsObjects(array) {
|
|
26
|
+
return array.map((obj) => {
|
|
27
|
+
return Object.assign({}, obj);
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Shuffles the elements in an array in place using the Fisher-Yates algorithm.
|
|
32
|
+
*
|
|
33
|
+
* @param {T[]} array - The array to be shuffled.
|
|
34
|
+
* @return {T[]} The shuffled array.
|
|
35
|
+
*/
|
|
36
|
+
export function shuffleArray(array) {
|
|
37
|
+
for (let i = array.length - 1; i > 0; i--) {
|
|
38
|
+
const j = Math.floor(Math.random() * (i + 1));
|
|
39
|
+
[array[i], array[j]] = [array[j], array[i]]; // Swap elements
|
|
40
|
+
}
|
|
41
|
+
return array;
|
|
42
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generates a function comment for the given function body in a markdown code block with the correct language syntax.
|
|
3
|
+
*
|
|
4
|
+
* @param {string} url - the URL to open in the new window
|
|
5
|
+
* @param {Record<string, string>} data - the data to send in the form
|
|
6
|
+
* @param {Object} options - an optional object containing target and method properties
|
|
7
|
+
* @param {string} options.target - the target attribute for the form submission (default: '_self')
|
|
8
|
+
* @param {string} options.method - the method attribute for the form submission (default: 'POST')
|
|
9
|
+
* @return {void} This function does not return anything
|
|
10
|
+
*/
|
|
11
|
+
export declare function openWindowWithJS(url: string, data: Record<string, string>, { target, method, }?: {
|
|
12
|
+
target?: string;
|
|
13
|
+
method?: string;
|
|
14
|
+
}): void;
|
|
15
|
+
/**
|
|
16
|
+
* Downloads a file by URL.
|
|
17
|
+
*
|
|
18
|
+
* @param {string} url - The URL of the file to be downloaded.
|
|
19
|
+
*/
|
|
20
|
+
export declare function downloadByUrl(url: string): void;
|
|
21
|
+
/**
|
|
22
|
+
* Converts a data URL to a Blob object.
|
|
23
|
+
*
|
|
24
|
+
* @param {string} dataUrl - The data URL to be converted.
|
|
25
|
+
* @return {Blob} The resulting Blob object.
|
|
26
|
+
*/
|
|
27
|
+
export declare function dataUrlToBlob(dataUrl: string): Blob;
|
|
28
|
+
/**
|
|
29
|
+
* Converts a data URL to a File object.
|
|
30
|
+
*
|
|
31
|
+
* @param {string} dataUrl - The data URL to convert.
|
|
32
|
+
* @param {Object} options - Optional parameters.
|
|
33
|
+
* @param {string} options.fileName - The name of the file. Default is 'file.png'.
|
|
34
|
+
* @param {string} options.type - The MIME type of the file. Default is 'image/png'.
|
|
35
|
+
* @returns {File} The converted File object.
|
|
36
|
+
*/
|
|
37
|
+
export declare function dataUrlToFile(dataUrl: string, { fileName, type, }?: {
|
|
38
|
+
fileName?: string;
|
|
39
|
+
type?: string;
|
|
40
|
+
}): File;
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generates a function comment for the given function body in a markdown code block with the correct language syntax.
|
|
3
|
+
*
|
|
4
|
+
* @param {string} url - the URL to open in the new window
|
|
5
|
+
* @param {Record<string, string>} data - the data to send in the form
|
|
6
|
+
* @param {Object} options - an optional object containing target and method properties
|
|
7
|
+
* @param {string} options.target - the target attribute for the form submission (default: '_self')
|
|
8
|
+
* @param {string} options.method - the method attribute for the form submission (default: 'POST')
|
|
9
|
+
* @return {void} This function does not return anything
|
|
10
|
+
*/
|
|
11
|
+
export function openWindowWithJS(url, data, { target = '_self', method = 'POST', } = {}) {
|
|
12
|
+
var form = document.createElement('form');
|
|
13
|
+
form.target = target;
|
|
14
|
+
form.method = method;
|
|
15
|
+
form.action = url;
|
|
16
|
+
form.style.display = 'none';
|
|
17
|
+
for (var key in data) {
|
|
18
|
+
var input = document.createElement('input');
|
|
19
|
+
input.type = 'hidden';
|
|
20
|
+
input.name = key;
|
|
21
|
+
input.value = data[key];
|
|
22
|
+
form.appendChild(input);
|
|
23
|
+
}
|
|
24
|
+
document.body.appendChild(form);
|
|
25
|
+
form.submit();
|
|
26
|
+
document.body.removeChild(form);
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Downloads a file by URL.
|
|
30
|
+
*
|
|
31
|
+
* @param {string} url - The URL of the file to be downloaded.
|
|
32
|
+
*/
|
|
33
|
+
export function downloadByUrl(url) {
|
|
34
|
+
var element = document.createElement('a');
|
|
35
|
+
element.setAttribute('href', url);
|
|
36
|
+
element.style.display = 'none';
|
|
37
|
+
document.body.appendChild(element);
|
|
38
|
+
element.click();
|
|
39
|
+
document.body.removeChild(element);
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Converts a data URL to a Blob object.
|
|
43
|
+
*
|
|
44
|
+
* @param {string} dataUrl - The data URL to be converted.
|
|
45
|
+
* @return {Blob} The resulting Blob object.
|
|
46
|
+
*/
|
|
47
|
+
export function dataUrlToBlob(dataUrl) {
|
|
48
|
+
const [header, body] = dataUrl.split(',');
|
|
49
|
+
const [type] = header.split(';');
|
|
50
|
+
const decodedBody = atob(body);
|
|
51
|
+
const byteArray = new Uint8Array(decodedBody.length);
|
|
52
|
+
for (let i = 0; i < decodedBody.length; i++) {
|
|
53
|
+
byteArray[i] = decodedBody.charCodeAt(i);
|
|
54
|
+
}
|
|
55
|
+
return new Blob([byteArray], { type });
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Converts a data URL to a File object.
|
|
59
|
+
*
|
|
60
|
+
* @param {string} dataUrl - The data URL to convert.
|
|
61
|
+
* @param {Object} options - Optional parameters.
|
|
62
|
+
* @param {string} options.fileName - The name of the file. Default is 'file.png'.
|
|
63
|
+
* @param {string} options.type - The MIME type of the file. Default is 'image/png'.
|
|
64
|
+
* @returns {File} The converted File object.
|
|
65
|
+
*/
|
|
66
|
+
export function dataUrlToFile(dataUrl, { fileName = 'file.png', type = 'image/png', } = {}) {
|
|
67
|
+
const blob = dataUrlToBlob(dataUrl);
|
|
68
|
+
return new File([blob], fileName, {
|
|
69
|
+
type: type || blob.type,
|
|
70
|
+
lastModified: new Date().getTime(),
|
|
71
|
+
});
|
|
72
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generates a random color code in hexadecimal format.
|
|
3
|
+
*
|
|
4
|
+
* @return {string} The randomly generated color code.
|
|
5
|
+
*/
|
|
6
|
+
export declare function genRandomColor(): string;
|
|
7
|
+
/**
|
|
8
|
+
* Converts a hexadecimal color code to an RGBA color with the specified alpha value.
|
|
9
|
+
*
|
|
10
|
+
* @param {string} hex - the hexadecimal color code
|
|
11
|
+
* @param {number} alpha - the alpha value for the RGBA color
|
|
12
|
+
* @return {string} the RGBA color code
|
|
13
|
+
*/
|
|
14
|
+
export declare function hexToRgba(hex: string, alpha: number): string;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generates a random color code in hexadecimal format.
|
|
3
|
+
*
|
|
4
|
+
* @return {string} The randomly generated color code.
|
|
5
|
+
*/
|
|
6
|
+
export function genRandomColor() {
|
|
7
|
+
const letters = '0123456789ABCDEF';
|
|
8
|
+
let color = '#';
|
|
9
|
+
for (let i = 0; i < 6; i++) {
|
|
10
|
+
color += letters[Math.floor(Math.random() * 16)];
|
|
11
|
+
}
|
|
12
|
+
return color;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Converts a hexadecimal color code to an RGBA color with the specified alpha value.
|
|
16
|
+
*
|
|
17
|
+
* @param {string} hex - the hexadecimal color code
|
|
18
|
+
* @param {number} alpha - the alpha value for the RGBA color
|
|
19
|
+
* @return {string} the RGBA color code
|
|
20
|
+
*/
|
|
21
|
+
export function hexToRgba(hex, alpha) {
|
|
22
|
+
const r = parseInt(hex.slice(1, 3), 16);
|
|
23
|
+
const g = parseInt(hex.slice(3, 5), 16);
|
|
24
|
+
const b = parseInt(hex.slice(5, 7), 16);
|
|
25
|
+
return `rgba(${r}, ${g}, ${b}, ${alpha})`;
|
|
26
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { MediaFileType } from '../../enums/media-file-type';
|
|
2
|
+
/**
|
|
3
|
+
* Converts a number of bytes to a human-readable file size.
|
|
4
|
+
*
|
|
5
|
+
* @param {number} bytes - The number of bytes to convert.
|
|
6
|
+
* @param {boolean} si - Whether to use the SI units (1000) or binary units (1024).
|
|
7
|
+
* @param {number} dp - The number of decimal places to round the result to.
|
|
8
|
+
* @return {string} The human-readable file size.
|
|
9
|
+
*/
|
|
10
|
+
export declare function humanFileSize(bytes: number, si?: boolean, dp?: number): string;
|
|
11
|
+
/**
|
|
12
|
+
* Returns the filename from a given URL.
|
|
13
|
+
*
|
|
14
|
+
* @param {string} url - The URL from which to extract the filename.
|
|
15
|
+
* @return {string} The filename extracted from the URL.
|
|
16
|
+
*/
|
|
17
|
+
export declare function filenameFromUrl(url: string): string;
|
|
18
|
+
/**
|
|
19
|
+
* Convert binary string content to a JavaScript File object and optionally trigger a download.
|
|
20
|
+
*
|
|
21
|
+
* @param {string} binaryContent - The binary string content of the file.
|
|
22
|
+
* @param {string} fileName - The name for the generated file.
|
|
23
|
+
* @param {string} mimeType - The MIME type of the file.
|
|
24
|
+
* @param {boolean} download - Whether to trigger a download of the file.
|
|
25
|
+
* @returns {File} - The generated File object.
|
|
26
|
+
*/
|
|
27
|
+
export declare function binaryContentToFile(binaryContent: string, fileName?: string, mimeType?: string, download?: boolean): File;
|
|
28
|
+
/**
|
|
29
|
+
* Convert binary string content to a Data URL.
|
|
30
|
+
*
|
|
31
|
+
* @param {string} binaryContent - The binary string content of the file.
|
|
32
|
+
* @param {string} mimeType - The MIME type of the file.
|
|
33
|
+
* @returns {Promise<string>} - The Data URL representation of the file.
|
|
34
|
+
*/
|
|
35
|
+
export declare function binaryContentToDataURL(binaryContent: string, mimeType: string): any;
|
|
36
|
+
/**
|
|
37
|
+
* Convert a Blob to a Data URL.
|
|
38
|
+
*
|
|
39
|
+
* @param {Blob} blob - The Blob to convert.
|
|
40
|
+
* @returns {Promise<string>} - A promise that resolves to the Data URL.
|
|
41
|
+
*/
|
|
42
|
+
export declare function blobToDataURL(blob: Blob): any;
|
|
43
|
+
/**
|
|
44
|
+
* Determines the media file type based on the MIME type of the provided file.
|
|
45
|
+
*
|
|
46
|
+
* @param {File} file - The file whose type is to be determined.
|
|
47
|
+
* @returns {MediaFileType} - The determined media file type, which can be IMAGE, VIDEO, AUDIO, DOCUMENT, or OTHER.
|
|
48
|
+
*/
|
|
49
|
+
export declare function determineFileType(file: File): MediaFileType;
|
|
50
|
+
/**
|
|
51
|
+
* Gets the file extension from a given path.
|
|
52
|
+
*
|
|
53
|
+
* @param {string} path - The path of the file.
|
|
54
|
+
* @returns {string} The file extension, or an empty string if none is found.
|
|
55
|
+
*/
|
|
56
|
+
export declare const getFileExtension: (path: string) => string;
|
|
57
|
+
/**
|
|
58
|
+
* Downloads the given object as a JSON file with the specified name.
|
|
59
|
+
*
|
|
60
|
+
* @param {object} exportObj - The object to be exported as JSON.
|
|
61
|
+
* @param {string} exportName - The name of the exported file.
|
|
62
|
+
* @return {void} This function does not return a value.
|
|
63
|
+
*/
|
|
64
|
+
export declare function downloadObjectAsJson(exportObj: object, exportName: string): void;
|