@cloudparker/moldex.js 0.0.7 → 0.0.9
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/actions/ripple.d.ts +0 -1
- package/dist/actions/ripple.js +1 -3
- package/dist/button/components/button/button.svelte +22 -16
- package/dist/date/index.d.ts +1 -0
- package/dist/date/index.js +1 -0
- package/dist/date/services/date-service.d.ts +51 -0
- package/dist/date/services/date-service.js +205 -0
- package/dist/dialog/components/dialog/dialog.svelte +6 -5
- package/dist/dialog/components/dialog/dialog.svelte.d.ts +3 -3
- package/dist/drawer/index.d.ts +2 -0
- package/dist/drawer/index.js +2 -0
- package/dist/icon/components/icon/icon.svelte +2 -2
- package/dist/icon/services/icon-path-service.d.ts +8 -5
- package/dist/icon/services/icon-path-service.js +8 -5
- package/dist/index.d.ts +9 -1
- package/dist/index.js +9 -1
- package/dist/navbar/index.d.ts +2 -0
- package/dist/navbar/index.js +2 -0
- package/dist/progressbar/components/progressbar/progressbar.svelte +46 -0
- package/dist/progressbar/components/progressbar/progressbar.svelte.d.ts +25 -0
- package/dist/progressbar/index.d.ts +2 -0
- package/dist/progressbar/index.js +2 -0
- package/dist/{common/components/vertical-rule/verticcal-rule.svelte.d.ts → ruler/components/vertical-ruler/verticcal-ruler.svelte.d.ts} +3 -3
- package/dist/ruler/index.d.ts +2 -0
- package/dist/ruler/index.js +2 -0
- package/dist/spinner/index.d.ts +2 -0
- package/dist/spinner/index.js +2 -0
- package/dist/tailwind.css +1 -1
- package/dist/text/components/text-await/text-await.svelte +9 -0
- package/dist/text/components/text-await/text-await.svelte.d.ts +22 -0
- package/dist/text/components/text-copy/text-copy.svelte +30 -0
- package/dist/text/components/text-copy/text-copy.svelte.d.ts +24 -0
- package/dist/text/components/text-country/text-country.svelte +37 -0
- package/dist/text/components/text-country/text-country.svelte.d.ts +20 -0
- package/dist/text/components/text-country-state/text-country-state.svelte +39 -0
- package/dist/text/components/text-country-state/text-country-state.svelte.d.ts +20 -0
- package/dist/text/components/text-currency/text-currency.svelte +20 -0
- package/dist/text/components/text-currency/text-currency.svelte.d.ts +22 -0
- package/dist/text/components/text-date/text-date.svelte +25 -0
- package/dist/text/components/text-date/text-date.svelte.d.ts +24 -0
- package/dist/text/components/text-email/text-email.svelte +14 -0
- package/dist/text/components/text-email/text-email.svelte.d.ts +23 -0
- package/dist/text/components/text-html/text-html.svelte +6 -0
- package/dist/text/components/text-html/text-html.svelte.d.ts +20 -0
- package/dist/text/components/text-phone/text-phone.svelte +13 -0
- package/dist/text/components/text-phone/text-phone.svelte.d.ts +23 -0
- package/dist/text/index.d.ts +10 -0
- package/dist/text/index.js +10 -0
- package/dist/toast/components/toast/toast.svelte +42 -0
- package/dist/toast/components/toast/toast.svelte.d.ts +29 -0
- package/dist/toast/index.d.ts +3 -0
- package/dist/toast/index.js +2 -0
- package/dist/toast/services/toast-service.d.ts +5 -0
- package/dist/toast/services/toast-service.js +26 -0
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.js +1 -0
- package/dist/utils/services/utils-service.d.ts +72 -0
- package/dist/utils/services/utils-service.js +370 -0
- package/package.json +4 -2
- package/dist/common/index.d.ts +0 -5
- package/dist/common/index.js +0 -5
- /package/dist/{common → drawer}/components/drawer/drawer.svelte +0 -0
- /package/dist/{common → drawer}/components/drawer/drawer.svelte.d.ts +0 -0
- /package/dist/{common → navbar}/components/navbar/navbar.svelte +0 -0
- /package/dist/{common → navbar}/components/navbar/navbar.svelte.d.ts +0 -0
- /package/dist/{common/components/vertical-rule/verticcal-rule.svelte → ruler/components/vertical-ruler/verticcal-ruler.svelte} +0 -0
- /package/dist/{common → spinner}/components/spinner/spinner.svelte +0 -0
- /package/dist/{common → spinner}/components/spinner/spinner.svelte.d.ts +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './services/utils-service.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './services/utils-service.js';
|
|
@@ -0,0 +1,72 @@
|
|
|
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;
|
|
4
|
+
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;
|
|
31
|
+
/**
|
|
32
|
+
* Function to download content from a given URL and convert it to a Base64-encoded string.
|
|
33
|
+
* @param url - The URL to download the content from.
|
|
34
|
+
* @returns A promise that resolves to the Base64-encoded string of the downloaded content.
|
|
35
|
+
*/
|
|
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 }: {
|
|
48
|
+
to: string;
|
|
49
|
+
body: string;
|
|
50
|
+
subject: string;
|
|
51
|
+
}): 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;
|
|
55
|
+
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>;
|
|
58
|
+
export declare function sort<T>({ array, field, desc, isDate }: {
|
|
59
|
+
array: T[];
|
|
60
|
+
field?: string;
|
|
61
|
+
desc?: boolean;
|
|
62
|
+
isDate?: boolean;
|
|
63
|
+
}): T[];
|
|
64
|
+
export declare function vibrate(value?: number | number[]): void;
|
|
65
|
+
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>;
|
|
69
|
+
export declare function isTouchDevice(): any;
|
|
70
|
+
export declare function toCurrency(value?: number, symbol?: string): string;
|
|
71
|
+
export declare function inchToPixel(inches: number): number;
|
|
72
|
+
export declare function pixelToInch(pixels: number): number;
|
|
@@ -0,0 +1,370 @@
|
|
|
1
|
+
import { BROWSER } from 'esm-env';
|
|
2
|
+
import { toDate } from '../../date/services/date-service.js';
|
|
3
|
+
const KEY_GEO_INFO = 'geo.info';
|
|
4
|
+
export const FILE_VIEWER_HOST = 'https://viewer.cloudparker.com';
|
|
5
|
+
export const CODE_FILE_EXTENTIONS = [
|
|
6
|
+
"java", "js", "ts", "json", "c", "cpp", "cs", "py", "ts", "php", "rb", "swift", "go",
|
|
7
|
+
"rs", "kt", "scala", "pl", "lua", "hs", "sh", "ps1", "dart", "jl", "m", "f90", "txt",
|
|
8
|
+
"r", "groovy", "asm", "pas", "ada", "sql", "md", "html", "css", "xml", "yaml", "xml",
|
|
9
|
+
"bat",
|
|
10
|
+
];
|
|
11
|
+
export const ACCEPT_IMAGE_FILES = ".png,.PNG,.jpg,.jpg,.jepg,.JPEG,.webp,.WEBP";
|
|
12
|
+
export function random(min, max) {
|
|
13
|
+
return min + Math.random() * (max - min);
|
|
14
|
+
}
|
|
15
|
+
export function openFilePicker(opt) {
|
|
16
|
+
return new Promise(resolve => {
|
|
17
|
+
let input = document.createElement('input');
|
|
18
|
+
input.type = 'file';
|
|
19
|
+
input.multiple = opt.multiple || false;
|
|
20
|
+
input.accept = opt.accept || ACCEPT_IMAGE_FILES;
|
|
21
|
+
input.onchange = _ => {
|
|
22
|
+
let files = Array.from(input.files);
|
|
23
|
+
if (opt.multiple) {
|
|
24
|
+
resolve(files);
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
resolve(files[0]);
|
|
28
|
+
}
|
|
29
|
+
document.body.removeChild(input);
|
|
30
|
+
};
|
|
31
|
+
input.style.display = 'none';
|
|
32
|
+
document.body.appendChild(input);
|
|
33
|
+
input.click();
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Default quality 1.0
|
|
38
|
+
* @param opt
|
|
39
|
+
* @returns
|
|
40
|
+
*/
|
|
41
|
+
export function resizeImage(opt) {
|
|
42
|
+
return new Promise((resolve, reject) => {
|
|
43
|
+
const reader = new FileReader();
|
|
44
|
+
reader.readAsDataURL(opt.file);
|
|
45
|
+
reader.onload = (event) => {
|
|
46
|
+
const img = new Image();
|
|
47
|
+
img.src = event.target.result;
|
|
48
|
+
img.onload = () => {
|
|
49
|
+
const elem = document.createElement('canvas');
|
|
50
|
+
let width = opt.width;
|
|
51
|
+
let height = opt.height || opt.width;
|
|
52
|
+
elem.width = width;
|
|
53
|
+
elem.height = height;
|
|
54
|
+
const ctx = elem.getContext('2d');
|
|
55
|
+
if (ctx) {
|
|
56
|
+
ctx.drawImage(img, 0, 0, width, height);
|
|
57
|
+
ctx.canvas.toBlob((blob) => {
|
|
58
|
+
const f = new File([blob], opt.fileName || opt.file
|
|
59
|
+
.name, {
|
|
60
|
+
type: opt.type || 'image/webp',
|
|
61
|
+
lastModified: Date.now()
|
|
62
|
+
});
|
|
63
|
+
resolve(f);
|
|
64
|
+
}, opt.type || 'image/webp', opt.quality ? (opt.quality / 100) : 0.8);
|
|
65
|
+
}
|
|
66
|
+
},
|
|
67
|
+
reader.onerror = error => console.log(error);
|
|
68
|
+
};
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
export async function downloadURI(uri, name) {
|
|
72
|
+
const res = await fetch(uri);
|
|
73
|
+
const link = document.createElement("a");
|
|
74
|
+
link.download = name;
|
|
75
|
+
link.href = URL.createObjectURL(await res.blob());
|
|
76
|
+
document.body.appendChild(link);
|
|
77
|
+
link.click();
|
|
78
|
+
document.body.removeChild(link);
|
|
79
|
+
}
|
|
80
|
+
export async function downloadFile(file) {
|
|
81
|
+
const link = document.createElement("a");
|
|
82
|
+
link.download = file.name;
|
|
83
|
+
link.href = URL.createObjectURL(file);
|
|
84
|
+
document.body.appendChild(link);
|
|
85
|
+
link.click();
|
|
86
|
+
document.body.removeChild(link);
|
|
87
|
+
}
|
|
88
|
+
export function downloadBlob(blob, name) {
|
|
89
|
+
return downloadFile(new File([blob], name));
|
|
90
|
+
}
|
|
91
|
+
export async function fileToDataURL(file) {
|
|
92
|
+
return new Promise((resolve, reject) => {
|
|
93
|
+
const reader = new FileReader();
|
|
94
|
+
reader.onloadend = function () {
|
|
95
|
+
const base64data = reader.result;
|
|
96
|
+
//console.log(base64data);
|
|
97
|
+
resolve(base64data);
|
|
98
|
+
};
|
|
99
|
+
reader.readAsDataURL(file);
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
export async function fileToText(file) {
|
|
103
|
+
return new Promise((resolve, reject) => {
|
|
104
|
+
const reader = new FileReader();
|
|
105
|
+
reader.onloadend = function () {
|
|
106
|
+
const text = reader.result;
|
|
107
|
+
//console.log(base64data);
|
|
108
|
+
resolve(text);
|
|
109
|
+
};
|
|
110
|
+
reader.readAsText(file);
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
export async function fileToBuffer(file) {
|
|
114
|
+
return new Promise((resolve, reject) => {
|
|
115
|
+
const reader = new FileReader();
|
|
116
|
+
reader.onloadend = function () {
|
|
117
|
+
resolve(reader.result);
|
|
118
|
+
};
|
|
119
|
+
reader.readAsArrayBuffer(file);
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
export async function fileToImage(file) {
|
|
123
|
+
return new Promise((resolve, reject) => {
|
|
124
|
+
const reader = new FileReader();
|
|
125
|
+
reader.onloadend = () => {
|
|
126
|
+
var imgObj = new Image();
|
|
127
|
+
imgObj.src = reader.result;
|
|
128
|
+
imgObj.onload = () => {
|
|
129
|
+
resolve(imgObj);
|
|
130
|
+
};
|
|
131
|
+
};
|
|
132
|
+
reader.readAsDataURL(file);
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
export async function dataUrlToImage(base64) {
|
|
136
|
+
return new Promise((resolve, reject) => {
|
|
137
|
+
var imgObj = new Image();
|
|
138
|
+
imgObj.src = base64;
|
|
139
|
+
imgObj.onload = () => {
|
|
140
|
+
resolve(imgObj);
|
|
141
|
+
};
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
export function stripBase64(data) {
|
|
145
|
+
if (data) {
|
|
146
|
+
return data.split(',')[1];
|
|
147
|
+
}
|
|
148
|
+
return data;
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Function to download content from a given URL and convert it to a Base64-encoded string.
|
|
152
|
+
* @param url - The URL to download the content from.
|
|
153
|
+
* @returns A promise that resolves to the Base64-encoded string of the downloaded content.
|
|
154
|
+
*/
|
|
155
|
+
export async function urlToBase64(url) {
|
|
156
|
+
try {
|
|
157
|
+
const response = await fetch(url);
|
|
158
|
+
if (!response.ok) {
|
|
159
|
+
throw new Error(`Failed to fetch: ${response.statusText}`);
|
|
160
|
+
}
|
|
161
|
+
const arrayBuffer = await response.arrayBuffer();
|
|
162
|
+
const base64Content = btoa(new Uint8Array(arrayBuffer)
|
|
163
|
+
.reduce((data, byte) => data + String.fromCharCode(byte), ''));
|
|
164
|
+
return base64Content;
|
|
165
|
+
}
|
|
166
|
+
catch (error) {
|
|
167
|
+
console.error('Error downloading or converting content:', error);
|
|
168
|
+
throw error;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
export function urlToFile(url, givenFileName, givenMimeType) {
|
|
172
|
+
return dataUrlToFile(url, givenFileName, givenMimeType);
|
|
173
|
+
}
|
|
174
|
+
export function dataUrlToFile(url, givenFileName, givenMimeType) {
|
|
175
|
+
return (fetch(url)
|
|
176
|
+
.then(async (res) => {
|
|
177
|
+
// Get Content-Disposition header and extract filename
|
|
178
|
+
const contentDisposition = res.headers.get('Content-Disposition');
|
|
179
|
+
let fileName = "";
|
|
180
|
+
if (contentDisposition) {
|
|
181
|
+
const filenameMatch = contentDisposition.match(/filename[^;=\n]*=((['"]).*?\2|[^;\n]*)/);
|
|
182
|
+
if (filenameMatch && filenameMatch[1]) {
|
|
183
|
+
fileName = filenameMatch[1].replace(/['"]/g, '');
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
// Get Content-Type header (MIME type)
|
|
187
|
+
const mimeType = res.headers.get('Content-Type') || '';
|
|
188
|
+
const buffer = await res.arrayBuffer();
|
|
189
|
+
return { buffer, fileName, mimeType };
|
|
190
|
+
})
|
|
191
|
+
.then(({ buffer, fileName, mimeType }) => {
|
|
192
|
+
return new File([buffer], givenFileName || fileName, {
|
|
193
|
+
type: givenMimeType || mimeType
|
|
194
|
+
});
|
|
195
|
+
}));
|
|
196
|
+
}
|
|
197
|
+
export async function bufferToFile(buffer, filename, mimeType) {
|
|
198
|
+
return new File([buffer], filename, {
|
|
199
|
+
type: mimeType
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
export async function postData(url = '', data = {}) {
|
|
203
|
+
// Default options are marked with *
|
|
204
|
+
const response = await fetch(url, {
|
|
205
|
+
method: 'POST', // *GET, POST, PUT, DELETE, etc.
|
|
206
|
+
mode: 'cors', // no-cors, *cors, same-origin
|
|
207
|
+
cache: 'no-cache', // *default, no-cache, reload, force-cache, only-if-cached
|
|
208
|
+
credentials: 'same-origin', // include, *same-origin, omit
|
|
209
|
+
headers: {
|
|
210
|
+
'Content-Type': 'application/json'
|
|
211
|
+
// 'Content-Type': 'application/x-www-form-urlencoded',
|
|
212
|
+
},
|
|
213
|
+
redirect: 'follow', // manual, *follow, error
|
|
214
|
+
referrerPolicy: 'no-referrer', // no-referrer, *no-referrer-when-downgrade, origin, origin-when-cross-origin, same-origin, strict-origin, strict-origin-when-cross-origin, unsafe-url
|
|
215
|
+
body: JSON.stringify(data) // body data type must match "Content-Type" header
|
|
216
|
+
});
|
|
217
|
+
return response.json(); // parses JSON response into native JavaScript objects
|
|
218
|
+
}
|
|
219
|
+
export function fileNameAndExt(filename) {
|
|
220
|
+
let arr = (filename || '').split('.');
|
|
221
|
+
let ext = arr.pop();
|
|
222
|
+
let name = arr.join('.');
|
|
223
|
+
return { name, ext };
|
|
224
|
+
}
|
|
225
|
+
export function isValidateEmail(email) {
|
|
226
|
+
const reg = /^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
|
|
227
|
+
return reg.test(String(email).toLowerCase());
|
|
228
|
+
}
|
|
229
|
+
export function isValidURL(str) {
|
|
230
|
+
var pattern = new RegExp('^(https?:\\/\\/)?' + // protocol
|
|
231
|
+
'((([a-z\\d]([a-z\\d-]*[a-z\\d])*)\\.)+[a-z]{2,}|' + // domain name
|
|
232
|
+
'((\\d{1,3}\\.){3}\\d{1,3}))' + // OR ip (v4) address
|
|
233
|
+
'(\\:\\d+)?(\\/[-a-z\\d%_.~+]*)*' + // port and path
|
|
234
|
+
'(\\?[;&a-z\\d%_.~+=-]*)?' + // query string
|
|
235
|
+
'(\\#[-a-z\\d_]*)?$', 'i'); // fragment locator
|
|
236
|
+
return !!pattern.test(str);
|
|
237
|
+
}
|
|
238
|
+
export function mailto({ to, body = '', subject = '' }) {
|
|
239
|
+
var uri = `mailto:${to || ''}?subject=${encodeURIComponent(subject || '')}&body=${encodeURIComponent(body || '')}`;
|
|
240
|
+
window.open(uri);
|
|
241
|
+
}
|
|
242
|
+
export function copyText(str) {
|
|
243
|
+
const el = document.createElement('textarea');
|
|
244
|
+
el.value = str;
|
|
245
|
+
el.setAttribute('readonly', '');
|
|
246
|
+
el.style.position = 'absolute';
|
|
247
|
+
el.style.left = '-9999px';
|
|
248
|
+
document.body.appendChild(el);
|
|
249
|
+
el.select();
|
|
250
|
+
el.setSelectionRange(0, 99999); /* For mobile devices */
|
|
251
|
+
if (navigator.clipboard) {
|
|
252
|
+
navigator.clipboard.writeText(str);
|
|
253
|
+
}
|
|
254
|
+
else {
|
|
255
|
+
document.execCommand('copy', false);
|
|
256
|
+
}
|
|
257
|
+
document.body.removeChild(el);
|
|
258
|
+
}
|
|
259
|
+
;
|
|
260
|
+
export function copyRichText(node) {
|
|
261
|
+
if (BROWSER) {
|
|
262
|
+
let r = document.createRange();
|
|
263
|
+
r.selectNode(node);
|
|
264
|
+
window.getSelection().removeAllRanges();
|
|
265
|
+
window.getSelection().addRange(r);
|
|
266
|
+
document.execCommand("copy");
|
|
267
|
+
window.getSelection().removeAllRanges();
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
export function download(data, filename, type) {
|
|
271
|
+
const blob = new Blob([data], { type: type || 'application/octet-stream' });
|
|
272
|
+
const elem = window.document.createElement('a');
|
|
273
|
+
elem.href = window.URL.createObjectURL(blob);
|
|
274
|
+
elem.download = filename;
|
|
275
|
+
document.body.appendChild(elem);
|
|
276
|
+
elem.click();
|
|
277
|
+
document.body.removeChild(elem);
|
|
278
|
+
}
|
|
279
|
+
export function formatString(str, ...args) {
|
|
280
|
+
var formatted = str;
|
|
281
|
+
for (var i = 0; i < args.length; i++) {
|
|
282
|
+
var regexp = new RegExp('\\{' + i + '\\}', 'gi');
|
|
283
|
+
formatted = formatted.replace(regexp, args[i]);
|
|
284
|
+
}
|
|
285
|
+
return formatted;
|
|
286
|
+
}
|
|
287
|
+
export function fileSizeString(size) {
|
|
288
|
+
var i = size == 0 ? 0 : Math.floor(Math.log(size) / Math.log(1024));
|
|
289
|
+
return parseInt((size / Math.pow(1024, i)).toFixed(2)) * 1 + ' ' + ['B', 'kB', 'MB', 'GB', 'TB'][i];
|
|
290
|
+
}
|
|
291
|
+
export function delay(mills = 0) {
|
|
292
|
+
return new Promise((resolve) => {
|
|
293
|
+
setTimeout(() => {
|
|
294
|
+
resolve();
|
|
295
|
+
}, mills);
|
|
296
|
+
});
|
|
297
|
+
}
|
|
298
|
+
export function sort({ array, field, desc, isDate }) {
|
|
299
|
+
return array.sort((a, b) => {
|
|
300
|
+
let valA = typeof a === 'object' && field ? a[field] : a;
|
|
301
|
+
let valB = typeof b === 'object' && field ? b[field] : b;
|
|
302
|
+
if (isDate) {
|
|
303
|
+
valA = toDate(valA);
|
|
304
|
+
valB = toDate(valB);
|
|
305
|
+
}
|
|
306
|
+
else {
|
|
307
|
+
// Case-insensitive string comparison
|
|
308
|
+
if (typeof valA === 'string')
|
|
309
|
+
valA = valA.toLowerCase();
|
|
310
|
+
if (typeof valB === 'string')
|
|
311
|
+
valB = valB.toLowerCase();
|
|
312
|
+
}
|
|
313
|
+
if (valA < valB) {
|
|
314
|
+
return desc ? 1 : -1;
|
|
315
|
+
}
|
|
316
|
+
else if (valA > valB) {
|
|
317
|
+
return desc ? -1 : 1;
|
|
318
|
+
}
|
|
319
|
+
return 0;
|
|
320
|
+
});
|
|
321
|
+
}
|
|
322
|
+
export function vibrate(value = 20) {
|
|
323
|
+
if (window?.navigator?.vibrate) {
|
|
324
|
+
window.navigator.vibrate(value);
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
export function playClickEffect() {
|
|
328
|
+
vibrate();
|
|
329
|
+
}
|
|
330
|
+
export function toArrayByKey(key, obj = {}) {
|
|
331
|
+
return Object.keys(obj).map((k) => {
|
|
332
|
+
let data = obj[k];
|
|
333
|
+
if (data) {
|
|
334
|
+
data[key] = k;
|
|
335
|
+
}
|
|
336
|
+
return data;
|
|
337
|
+
}).filter(o => o) || [];
|
|
338
|
+
}
|
|
339
|
+
export function convertNumToAlphabates(num) {
|
|
340
|
+
let alphabates = 'abcdefghij'.split('');
|
|
341
|
+
let numArray = num.toString().split('').map((o) => parseInt(o));
|
|
342
|
+
return numArray.map((i) => alphabates[i]).join('');
|
|
343
|
+
}
|
|
344
|
+
export async function fetchText(url) {
|
|
345
|
+
const response = await fetch(url);
|
|
346
|
+
let text = await response.text();
|
|
347
|
+
// console.log(text)
|
|
348
|
+
return text;
|
|
349
|
+
}
|
|
350
|
+
export function isTouchDevice() {
|
|
351
|
+
return 'ontouchstart' in window || navigator.maxTouchPoints > 0 || navigator.msMaxTouchPoints > 0 || window.matchMedia("(pointer: coarse)").matches;
|
|
352
|
+
}
|
|
353
|
+
export function toCurrency(value = 0, symbol = '$') {
|
|
354
|
+
let currency = Math.abs(value);
|
|
355
|
+
let result = '';
|
|
356
|
+
if (value < 0) {
|
|
357
|
+
result += '- ';
|
|
358
|
+
}
|
|
359
|
+
if (symbol) {
|
|
360
|
+
result += `${symbol} `;
|
|
361
|
+
}
|
|
362
|
+
result += currency.toFixed(2);
|
|
363
|
+
return result;
|
|
364
|
+
}
|
|
365
|
+
export function inchToPixel(inches) {
|
|
366
|
+
return inches * 96; // DPI
|
|
367
|
+
}
|
|
368
|
+
export function pixelToInch(pixels) {
|
|
369
|
+
return pixels / 96; // DPI
|
|
370
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cloudparker/moldex.js",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.9",
|
|
4
4
|
"author": "cloudparker.com",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"keywords": [
|
|
@@ -27,6 +27,8 @@
|
|
|
27
27
|
"repository": "https://github.com/paramanandapradhan/moldex.js",
|
|
28
28
|
"homepage": "https://cloudparker.com",
|
|
29
29
|
"devDependencies": {
|
|
30
|
-
"@
|
|
30
|
+
"@cloudparker/easy-script-loader-svelte": "^3.0.3",
|
|
31
|
+
"esm-env": "^1.0.0",
|
|
32
|
+
"moment": "^2.30.1"
|
|
31
33
|
}
|
|
32
34
|
}
|
package/dist/common/index.d.ts
DELETED
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import Drawer from './components/drawer/drawer.svelte';
|
|
2
|
-
import Navbar from './components/navbar/navbar.svelte';
|
|
3
|
-
import Spinner from './components/spinner/spinner.svelte';
|
|
4
|
-
import VerticalRule from './components/vertical-rule/verticcal-rule.svelte';
|
|
5
|
-
export { Drawer, Navbar, Spinner, VerticalRule };
|
package/dist/common/index.js
DELETED
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import Drawer from './components/drawer/drawer.svelte';
|
|
2
|
-
import Navbar from './components/navbar/navbar.svelte';
|
|
3
|
-
import Spinner from './components/spinner/spinner.svelte';
|
|
4
|
-
import VerticalRule from './components/vertical-rule/verticcal-rule.svelte';
|
|
5
|
-
export { Drawer, Navbar, Spinner, VerticalRule };
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|