@filen/utils 0.0.3 → 0.0.5
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.js +1 -0
- package/dist/misc.js +56 -0
- package/dist/notes.js +39 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/misc.d.ts +5 -0
- package/dist/types/notes.d.ts +1 -0
- package/package.json +2 -1
package/dist/index.js
CHANGED
package/dist/misc.js
CHANGED
|
@@ -309,3 +309,59 @@ export function fastLocaleCompare(a, b) {
|
|
|
309
309
|
}
|
|
310
310
|
return caseDiff;
|
|
311
311
|
}
|
|
312
|
+
export const BPS_TO_READABLE_UNITS = ["KiB", "MiB", "GiB", "TiB", "PiB", "EiB", "ZiB", "YiB"];
|
|
313
|
+
export function bpsToReadable(bps) {
|
|
314
|
+
if (!(bps > 0 && bps < 1099511627776)) {
|
|
315
|
+
return "0.1 B/s";
|
|
316
|
+
}
|
|
317
|
+
let i = 0;
|
|
318
|
+
let value = bps;
|
|
319
|
+
if (value >= 1024) {
|
|
320
|
+
value /= 1024;
|
|
321
|
+
i = 1;
|
|
322
|
+
if (value >= 1024) {
|
|
323
|
+
value /= 1024;
|
|
324
|
+
i = 2;
|
|
325
|
+
if (value >= 1024) {
|
|
326
|
+
value /= 1024;
|
|
327
|
+
i = 3;
|
|
328
|
+
if (value >= 1024) {
|
|
329
|
+
value /= 1024;
|
|
330
|
+
i = 4;
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
if (value < 0.1) {
|
|
336
|
+
value = 0.1;
|
|
337
|
+
}
|
|
338
|
+
return value.toFixed(1) + " " + BPS_TO_READABLE_UNITS[i];
|
|
339
|
+
}
|
|
340
|
+
export const FORMAT_BYTES_SIZES = ["B", "KiB", "MiB", "GiB", "TiB", "PiB", "EiB", "ZiB", "YiB"];
|
|
341
|
+
export const POWERS_1024 = [1, 1024, 1048576, 1073741824, 1099511627776, 1125899906842624];
|
|
342
|
+
export function formatBytes(bytes, decimals = 2) {
|
|
343
|
+
if (bytes === 0) {
|
|
344
|
+
return "0 B";
|
|
345
|
+
}
|
|
346
|
+
const dm = decimals < 0 ? 0 : decimals;
|
|
347
|
+
let i = 0;
|
|
348
|
+
if (bytes >= POWERS_1024[5]) {
|
|
349
|
+
i = 5;
|
|
350
|
+
}
|
|
351
|
+
else if (bytes >= POWERS_1024[4]) {
|
|
352
|
+
i = 4;
|
|
353
|
+
}
|
|
354
|
+
else if (bytes >= POWERS_1024[3]) {
|
|
355
|
+
i = 3;
|
|
356
|
+
}
|
|
357
|
+
else if (bytes >= POWERS_1024[2]) {
|
|
358
|
+
i = 2;
|
|
359
|
+
}
|
|
360
|
+
else if (bytes >= POWERS_1024[1]) {
|
|
361
|
+
i = 1;
|
|
362
|
+
}
|
|
363
|
+
const value = bytes / POWERS_1024[i];
|
|
364
|
+
const multiplier = Math.pow(10, dm);
|
|
365
|
+
const rounded = Math.round(value * multiplier) / multiplier;
|
|
366
|
+
return rounded + " " + FORMAT_BYTES_SIZES[i];
|
|
367
|
+
}
|
package/dist/notes.js
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import striptags from "striptags";
|
|
2
|
+
export function createNotePreviewFromContentText(type, content) {
|
|
3
|
+
var _a, _b, _c;
|
|
4
|
+
try {
|
|
5
|
+
if (!content || content.length === 0) {
|
|
6
|
+
return "";
|
|
7
|
+
}
|
|
8
|
+
if (type === "rich") {
|
|
9
|
+
if (content.indexOf("<p><br></p>") === -1) {
|
|
10
|
+
return striptags((_a = content.split("\n")[0]) !== null && _a !== void 0 ? _a : "").slice(0, 128);
|
|
11
|
+
}
|
|
12
|
+
return striptags((_b = content.split("<p><br></p>")[0]) !== null && _b !== void 0 ? _b : "").slice(0, 128);
|
|
13
|
+
}
|
|
14
|
+
if (type === "checklist") {
|
|
15
|
+
const ex = content
|
|
16
|
+
.split('<ul data-checked="false">')
|
|
17
|
+
.join("")
|
|
18
|
+
.split('<ul data-checked="true">')
|
|
19
|
+
.join("")
|
|
20
|
+
.split("\n")
|
|
21
|
+
.join("")
|
|
22
|
+
.split("<li>");
|
|
23
|
+
for (const listPoint of ex) {
|
|
24
|
+
const listPointEx = listPoint.split("</li>");
|
|
25
|
+
if (!listPointEx[0]) {
|
|
26
|
+
continue;
|
|
27
|
+
}
|
|
28
|
+
if (listPointEx[0].trim().length > 0) {
|
|
29
|
+
return striptags(listPointEx[0].trim()).slice(0, 128);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return "";
|
|
33
|
+
}
|
|
34
|
+
return striptags((_c = content.split("\n")[0]) !== null && _c !== void 0 ? _c : "").slice(0, 128);
|
|
35
|
+
}
|
|
36
|
+
catch (_d) {
|
|
37
|
+
return "";
|
|
38
|
+
}
|
|
39
|
+
}
|
package/dist/types/index.d.ts
CHANGED
package/dist/types/misc.d.ts
CHANGED
|
@@ -29,3 +29,8 @@ export declare function createExecutableTimeout(callback: () => void, delay?: nu
|
|
|
29
29
|
cancel: () => void;
|
|
30
30
|
};
|
|
31
31
|
export declare function fastLocaleCompare(a: string, b: string): number;
|
|
32
|
+
export declare const BPS_TO_READABLE_UNITS: string[];
|
|
33
|
+
export declare function bpsToReadable(bps: number): string;
|
|
34
|
+
export declare const FORMAT_BYTES_SIZES: string[];
|
|
35
|
+
export declare const POWERS_1024: readonly [1, 1024, 1048576, 1073741824, 1099511627776, 1125899906842624];
|
|
36
|
+
export declare function formatBytes(bytes: number, decimals?: number): string;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function createNotePreviewFromContentText(type: "rich" | "checklist" | "other", content?: string): string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@filen/utils",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.5",
|
|
4
4
|
"description": "A collection of utils for Filen",
|
|
5
5
|
"private": false,
|
|
6
6
|
"repository": {
|
|
@@ -35,6 +35,7 @@
|
|
|
35
35
|
"dependencies": {
|
|
36
36
|
"clsx": "^2.1.1",
|
|
37
37
|
"node-html-better-parser": "^1.5.8",
|
|
38
|
+
"striptags": "^3.2.0",
|
|
38
39
|
"tailwind-merge": "^3.3.1",
|
|
39
40
|
"uuid": "^13.0.0"
|
|
40
41
|
}
|