usemods-nuxt 0.0.21 → 1.0.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.
- package/dist/module.json +2 -2
- package/dist/module.mjs +1 -1
- package/dist/runtime/utils/README.txt +2 -0
- package/dist/runtime/utils/actions.d.ts +2 -1
- package/dist/runtime/utils/actions.mjs +15 -7
- package/dist/runtime/utils/animations.mjs +2 -2
- package/dist/runtime/utils/data.d.ts +9 -13
- package/dist/runtime/utils/data.mjs +13 -40
- package/dist/runtime/utils/detections.d.ts +5 -4
- package/dist/runtime/utils/detections.mjs +0 -26
- package/dist/runtime/utils/formatters.d.ts +4 -5
- package/dist/runtime/utils/formatters.mjs +20 -20
- package/dist/runtime/utils/generators.mjs +11 -3
- package/dist/runtime/utils/goodies.d.ts +11 -5
- package/dist/runtime/utils/goodies.mjs +12 -11
- package/dist/runtime/utils/modifiers.d.ts +2 -0
- package/dist/runtime/utils/modifiers.mjs +4 -4
- package/dist/runtime/utils/numbers.d.ts +2 -3
- package/dist/runtime/utils/numbers.mjs +1 -1
- package/dist/runtime/utils/validators.d.ts +25 -24
- package/dist/runtime/utils/validators.mjs +3 -3
- package/package.json +1 -1
package/dist/module.json
CHANGED
package/dist/module.mjs
CHANGED
|
@@ -4,8 +4,9 @@
|
|
|
4
4
|
export declare function scrollToAnchor(id: string): Promise<void>;
|
|
5
5
|
/**
|
|
6
6
|
* Toggles the body scroll with specified class names and returns a promise
|
|
7
|
+
* @info Use your own class names, or ensure fixed is within your Tailwindcss JIT
|
|
7
8
|
*/
|
|
8
|
-
export declare function toggleBodyScroll(className?: string): Promise<void>;
|
|
9
|
+
export declare function toggleBodyScroll(className?: string, action?: 'add' | 'remove' | 'toggle'): Promise<void>;
|
|
9
10
|
/**
|
|
10
11
|
* Toggles the element scroll with specified class names and returns a promise
|
|
11
12
|
*/
|
|
@@ -15,14 +15,20 @@ export function scrollToAnchor(id) {
|
|
|
15
15
|
}, 180);
|
|
16
16
|
});
|
|
17
17
|
}
|
|
18
|
-
export function toggleBodyScroll(className = "fixed") {
|
|
18
|
+
export function toggleBodyScroll(className = "fixed", action = "toggle") {
|
|
19
19
|
return new Promise((resolve, reject) => {
|
|
20
20
|
try {
|
|
21
21
|
const body = document.body;
|
|
22
22
|
const isFixed = body.classList.contains(className);
|
|
23
23
|
const scrollY = isFixed ? parseInt(body.style.top, 10) : window.scrollY;
|
|
24
24
|
body.style.top = isFixed ? "" : `-${scrollY}px`;
|
|
25
|
-
|
|
25
|
+
if (action === "add") {
|
|
26
|
+
body.classList.add(className);
|
|
27
|
+
} else if (action === "remove") {
|
|
28
|
+
body.classList.remove(className);
|
|
29
|
+
} else {
|
|
30
|
+
body.classList.toggle(className);
|
|
31
|
+
}
|
|
26
32
|
if (isFixed)
|
|
27
33
|
window.scrollTo(0, -scrollY);
|
|
28
34
|
resolve();
|
|
@@ -32,7 +38,7 @@ export function toggleBodyScroll(className = "fixed") {
|
|
|
32
38
|
});
|
|
33
39
|
}
|
|
34
40
|
export function toggleElementScroll(element) {
|
|
35
|
-
return new Promise((resolve
|
|
41
|
+
return new Promise((resolve) => {
|
|
36
42
|
if (element.dataset.isScrollLocked === "true") {
|
|
37
43
|
element.style.overflow = "";
|
|
38
44
|
delete element.dataset.isScrollLocked;
|
|
@@ -43,14 +49,16 @@ export function toggleElementScroll(element) {
|
|
|
43
49
|
resolve();
|
|
44
50
|
});
|
|
45
51
|
}
|
|
46
|
-
export function copyToClipboard(value) {
|
|
52
|
+
export async function copyToClipboard(value) {
|
|
47
53
|
if (!navigator.clipboard || !navigator.clipboard.writeText) {
|
|
48
|
-
|
|
54
|
+
throw new Error("Clipboard API is not available");
|
|
49
55
|
}
|
|
50
|
-
|
|
56
|
+
try {
|
|
57
|
+
await navigator.clipboard.writeText(String(value));
|
|
58
|
+
} catch (error) {
|
|
51
59
|
console.error("Failed to copy text: ", error);
|
|
52
60
|
throw error;
|
|
53
|
-
}
|
|
61
|
+
}
|
|
54
62
|
}
|
|
55
63
|
export function toggleFullScreen() {
|
|
56
64
|
return new Promise((resolve, reject) => {
|
|
@@ -6,10 +6,10 @@ export function animateText(text, options = {}) {
|
|
|
6
6
|
const elements = text.split(delimiter);
|
|
7
7
|
const result = elements.map((element, index) => {
|
|
8
8
|
const delay = `${index * time}${unit}`;
|
|
9
|
-
const spanStyle =
|
|
9
|
+
const spanStyle = "display: inline-block; position: relative;";
|
|
10
10
|
const translateStyle = `position: absolute; top: 0; left: 0; animation-delay: ${delay};`;
|
|
11
11
|
if (element === " " && splitBy === "character") {
|
|
12
|
-
return
|
|
12
|
+
return '<span class="space" style="white-space: pre;"> </span>';
|
|
13
13
|
} else {
|
|
14
14
|
return `<span class="relative overflow-clip" style="${spanStyle}">
|
|
15
15
|
<span class="ghost" style="visibility: hidden;">${element}</span>
|
|
@@ -1,27 +1,23 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Shuffles your data in a random order.
|
|
3
|
-
*/
|
|
4
|
-
export declare function dataShuffle(items: object | any[]): any;
|
|
5
|
-
/**
|
|
6
|
-
* Reverse an array.
|
|
7
|
-
*/
|
|
8
|
-
export declare function dataReverse(items: object | any[]): any;
|
|
9
1
|
/**
|
|
10
2
|
* Sort an array or object by a property.
|
|
11
3
|
*/
|
|
12
|
-
export declare function dataSortBy(items: object |
|
|
4
|
+
export declare function dataSortBy(items: object | string[] | number[], options?: {
|
|
13
5
|
property?: string;
|
|
14
6
|
order?: 'asc' | 'desc';
|
|
15
|
-
}):
|
|
7
|
+
}): object | string[] | number[];
|
|
8
|
+
/**
|
|
9
|
+
* Reverse an array.
|
|
10
|
+
*/
|
|
11
|
+
export declare function dataReverse(items: object | string[] | number[]): object | string[] | number[];
|
|
16
12
|
/**
|
|
17
13
|
* Returns single unique values within an array or object
|
|
18
14
|
*/
|
|
19
|
-
export declare function dataRemoveDuplicates(...arrays:
|
|
15
|
+
export declare function dataRemoveDuplicates<T extends string | number>(...arrays: T[][]): T[];
|
|
20
16
|
/**
|
|
21
17
|
* Flatten an array of arrays or an object of objects into a single array or object. That was hard to say.
|
|
22
18
|
*/
|
|
23
|
-
export declare function dataFlatten(items: object |
|
|
19
|
+
export declare function dataFlatten(items: object | string[] | number[]): object | string[] | number[];
|
|
24
20
|
/**
|
|
25
21
|
* Returns an array without a property or properties.
|
|
26
22
|
*/
|
|
27
|
-
export declare function dataWithout(items: object |
|
|
23
|
+
export declare function dataWithout(items: object | string[] | number[], properties: string | number | string[] | number[]): object | string[] | number[];
|
|
@@ -1,43 +1,4 @@
|
|
|
1
|
-
import { isObject
|
|
2
|
-
export function dataShuffle(items) {
|
|
3
|
-
if (!items || !(isObject(items) || isArray(items))) {
|
|
4
|
-
console.warn("[MODS] Warning: dataShuffle() expects an object or array as the first argument.");
|
|
5
|
-
return items;
|
|
6
|
-
}
|
|
7
|
-
const shuffleArray = (array) => {
|
|
8
|
-
let shuffled = false;
|
|
9
|
-
while (!shuffled) {
|
|
10
|
-
for (let i = array.length - 1; i > 0; i--) {
|
|
11
|
-
const j = Math.floor(Math.random() * (i + 1));
|
|
12
|
-
[array[i], array[j]] = [array[j], array[i]];
|
|
13
|
-
}
|
|
14
|
-
shuffled = !array.every((element, index) => {
|
|
15
|
-
if (Array.isArray(items))
|
|
16
|
-
return element === items[index];
|
|
17
|
-
return false;
|
|
18
|
-
});
|
|
19
|
-
}
|
|
20
|
-
return array;
|
|
21
|
-
};
|
|
22
|
-
if (isObject(items)) {
|
|
23
|
-
const entries = Object.entries(items);
|
|
24
|
-
return Object.fromEntries(shuffleArray(entries));
|
|
25
|
-
} else {
|
|
26
|
-
return shuffleArray([...items]);
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
export function dataReverse(items) {
|
|
30
|
-
if (!items || !(isObject(items) || isArray(items))) {
|
|
31
|
-
console.warn("[MODS] Warning: dataReverse() expects an object or array as the first argument.");
|
|
32
|
-
return items;
|
|
33
|
-
}
|
|
34
|
-
if (isObject(items)) {
|
|
35
|
-
const entries = Object.entries(items);
|
|
36
|
-
return Object.fromEntries(entries.reverse());
|
|
37
|
-
} else {
|
|
38
|
-
return items.reverse();
|
|
39
|
-
}
|
|
40
|
-
}
|
|
1
|
+
import { isObject } from "./validators.mjs";
|
|
41
2
|
export function dataSortBy(items, options) {
|
|
42
3
|
const comparator = (a, b) => {
|
|
43
4
|
const property = options?.property;
|
|
@@ -57,6 +18,18 @@ export function dataSortBy(items, options) {
|
|
|
57
18
|
return items.sort(comparator);
|
|
58
19
|
}
|
|
59
20
|
}
|
|
21
|
+
export function dataReverse(items) {
|
|
22
|
+
if (!items) {
|
|
23
|
+
console.warn("[MODS] Warning: dataReverse() expects an object or array as the first argument.");
|
|
24
|
+
return items;
|
|
25
|
+
}
|
|
26
|
+
if (isObject(items)) {
|
|
27
|
+
const entries = Object.entries(items);
|
|
28
|
+
return Object.fromEntries(entries.reverse());
|
|
29
|
+
} else {
|
|
30
|
+
return items.reverse();
|
|
31
|
+
}
|
|
32
|
+
}
|
|
60
33
|
export function dataRemoveDuplicates(...arrays) {
|
|
61
34
|
const mergedArray = arrays.flat();
|
|
62
35
|
return mergedArray.filter((item, index) => mergedArray.indexOf(item) === index);
|
|
@@ -7,6 +7,7 @@ export declare function detectScrollPosition(): {
|
|
|
7
7
|
};
|
|
8
8
|
/**
|
|
9
9
|
* Detect the absolute mouse position with the page
|
|
10
|
+
* @info Don't forget to add a mousemove event listener to the window
|
|
10
11
|
*/
|
|
11
12
|
export declare function detectMousePosition(event: MouseEvent): {
|
|
12
13
|
x: number;
|
|
@@ -14,6 +15,7 @@ export declare function detectMousePosition(event: MouseEvent): {
|
|
|
14
15
|
};
|
|
15
16
|
/**
|
|
16
17
|
* Detect the relative mouse position with the window size and returns a percentage value
|
|
18
|
+
* @info Don't forget to add a mousemove event listener to the window
|
|
17
19
|
*/
|
|
18
20
|
export declare function detectRelativeMousePosition(event: MouseEvent): {
|
|
19
21
|
x: number;
|
|
@@ -64,10 +66,6 @@ export declare function detectDeviceOrientation(): string;
|
|
|
64
66
|
* Detect the current breakpoint based on Tailwind CSS breakpoints
|
|
65
67
|
*/
|
|
66
68
|
export declare function detectBreakpoint(): string;
|
|
67
|
-
/**
|
|
68
|
-
* Detect any container breakpoint based on Tailwind CSS breakpoints
|
|
69
|
-
*/
|
|
70
|
-
export declare function detectContainerBreakpoint(element: HTMLElement): string;
|
|
71
69
|
/**
|
|
72
70
|
* Detect the current network status of the user (Online or Offline)
|
|
73
71
|
*/
|
|
@@ -108,3 +106,6 @@ export declare function detectPort(): string;
|
|
|
108
106
|
/**
|
|
109
107
|
* Detects if the element is currently in the container via ID
|
|
110
108
|
*/
|
|
109
|
+
/**
|
|
110
|
+
* Detect any container breakpoint based on Tailwind CSS breakpoints
|
|
111
|
+
*/
|
|
@@ -74,32 +74,6 @@ export function detectBreakpoint() {
|
|
|
74
74
|
return "xl";
|
|
75
75
|
return "2xl";
|
|
76
76
|
}
|
|
77
|
-
export function detectContainerBreakpoint(element) {
|
|
78
|
-
const width = element.getBoundingClientRect().width;
|
|
79
|
-
if (width < 320)
|
|
80
|
-
return "@xs";
|
|
81
|
-
if (width < 384)
|
|
82
|
-
return "@sm";
|
|
83
|
-
if (width < 448)
|
|
84
|
-
return "@md";
|
|
85
|
-
if (width < 512)
|
|
86
|
-
return "@lg";
|
|
87
|
-
if (width < 576)
|
|
88
|
-
return "@xl";
|
|
89
|
-
if (width < 672)
|
|
90
|
-
return "@2xl";
|
|
91
|
-
if (width < 768)
|
|
92
|
-
return "@3xl";
|
|
93
|
-
if (width < 896)
|
|
94
|
-
return "@4xl";
|
|
95
|
-
if (width < 1024)
|
|
96
|
-
return "@5xl";
|
|
97
|
-
if (width < 1152)
|
|
98
|
-
return "@6xl";
|
|
99
|
-
if (width < 1280)
|
|
100
|
-
return "@7xl";
|
|
101
|
-
return "@7xl";
|
|
102
|
-
}
|
|
103
77
|
export function detectNetworkStatus() {
|
|
104
78
|
return navigator.onLine ? "Online" : "Offline";
|
|
105
79
|
}
|
|
@@ -40,7 +40,7 @@ export declare function formatDurationNumbers(seconds: number): string;
|
|
|
40
40
|
/**
|
|
41
41
|
* Format numbers into words
|
|
42
42
|
*/
|
|
43
|
-
export declare function formatNumberToWords(
|
|
43
|
+
export declare function formatNumberToWords(number: number): string;
|
|
44
44
|
/**
|
|
45
45
|
* Generate initials from any string while ignoring common titles
|
|
46
46
|
*/
|
|
@@ -52,16 +52,14 @@ export declare function formatInitials(text: string, options?: {
|
|
|
52
52
|
*/
|
|
53
53
|
export declare function formatUnixTime(timestamp: number): string;
|
|
54
54
|
/**
|
|
55
|
-
* Create a string of comma-separated values from an array, object or string with an optional limit and conjunction
|
|
55
|
+
* Create a string of comma-separated values from an array, object, or string with an optional limit and conjunction
|
|
56
56
|
*/
|
|
57
|
-
export declare function formatList(items: string | object |
|
|
57
|
+
export declare function formatList(items: string | object | string[], options?: {
|
|
58
58
|
limit?: number;
|
|
59
59
|
conjunction?: string;
|
|
60
60
|
}): string;
|
|
61
61
|
/**
|
|
62
62
|
* Converts a string to title case following the Chicago Manual of Style rules.
|
|
63
|
-
* @reference https://www.chicagomanualofstyle.org/book/ed17/frontmatter/toc.html
|
|
64
|
-
|
|
65
63
|
*/
|
|
66
64
|
export declare function formatTitle(text: string): string;
|
|
67
65
|
/**
|
|
@@ -70,6 +68,7 @@ export declare function formatTitle(text: string): string;
|
|
|
70
68
|
export declare function formatSentenceCase(text: string): string;
|
|
71
69
|
/**
|
|
72
70
|
* Adds a space between the last two words in a string to prevent lonely words.
|
|
71
|
+
* @info Remember `text-wrap: pretty` and `text-wrap: balance` are available for most browsers.
|
|
73
72
|
*/
|
|
74
73
|
export declare function formatTextWrap(value: string): string;
|
|
75
74
|
/**
|
|
@@ -39,7 +39,7 @@ const currencySymbols = /* @__PURE__ */ new Map([
|
|
|
39
39
|
]);
|
|
40
40
|
export function formatNumber(number, options) {
|
|
41
41
|
const safeDecimals = Math.max(0, Math.min(options?.decimals ?? 2, 20));
|
|
42
|
-
|
|
42
|
+
const config = {
|
|
43
43
|
style: "decimal",
|
|
44
44
|
minimumFractionDigits: safeDecimals === 0 ? 0 : safeDecimals === 1 ? 1 : 2,
|
|
45
45
|
maximumFractionDigits: safeDecimals
|
|
@@ -48,7 +48,7 @@ export function formatNumber(number, options) {
|
|
|
48
48
|
}
|
|
49
49
|
export function formatCurrency(number, options) {
|
|
50
50
|
const safeDecimals = Math.max(0, Math.min(options?.decimals ?? 2, 20));
|
|
51
|
-
|
|
51
|
+
const config = {
|
|
52
52
|
style: "currency",
|
|
53
53
|
currencyDisplay: "narrowSymbol",
|
|
54
54
|
minimumFractionDigits: safeDecimals === 0 ? 0 : safeDecimals === 1 ? 1 : 2,
|
|
@@ -59,7 +59,7 @@ export function formatCurrency(number, options) {
|
|
|
59
59
|
}
|
|
60
60
|
export function formatValuation(number, options) {
|
|
61
61
|
const safeDecimals = Math.max(0, Math.min(options?.decimals ?? 2, 20));
|
|
62
|
-
|
|
62
|
+
const config = {
|
|
63
63
|
style: "currency",
|
|
64
64
|
currencyDisplay: "narrowSymbol",
|
|
65
65
|
notation: "compact",
|
|
@@ -72,7 +72,7 @@ export function formatValuation(number, options) {
|
|
|
72
72
|
}
|
|
73
73
|
export function formatPercentage(value, options) {
|
|
74
74
|
const safeDecimals = Math.max(0, Math.min(options?.decimals ?? 2, 20));
|
|
75
|
-
|
|
75
|
+
const config = {
|
|
76
76
|
style: "percent",
|
|
77
77
|
minimumFractionDigits: safeDecimals === 0 ? 0 : safeDecimals === 1 ? 1 : 2,
|
|
78
78
|
maximumFractionDigits: safeDecimals
|
|
@@ -116,7 +116,7 @@ export function formatDurationNumbers(seconds) {
|
|
|
116
116
|
const remainingSeconds = seconds - hours * 3600 - minutes * 60;
|
|
117
117
|
return [hours, minutes, remainingSeconds].map((value) => value.toString().padStart(2, "0")).join(":");
|
|
118
118
|
}
|
|
119
|
-
export function formatNumberToWords(
|
|
119
|
+
export function formatNumberToWords(number) {
|
|
120
120
|
const underTwenty = [
|
|
121
121
|
"zero",
|
|
122
122
|
"one",
|
|
@@ -140,29 +140,29 @@ export function formatNumberToWords(value) {
|
|
|
140
140
|
"nineteen"
|
|
141
141
|
];
|
|
142
142
|
const tens = ["twenty", "thirty", "forty", "fifty", "sixty", "seventy", "eighty", "ninety"];
|
|
143
|
-
if (
|
|
144
|
-
return underTwenty[
|
|
145
|
-
if (
|
|
146
|
-
return `${tens[Math.floor(
|
|
147
|
-
const formatGroup = (
|
|
148
|
-
if (
|
|
149
|
-
const remainder =
|
|
150
|
-
return `${underTwenty[Math.floor(
|
|
151
|
-
} else if (
|
|
152
|
-
return `${tens[Math.floor(
|
|
143
|
+
if (number < 20)
|
|
144
|
+
return underTwenty[number];
|
|
145
|
+
if (number < 100)
|
|
146
|
+
return `${tens[Math.floor(number / 10) - 2]}${number % 10 ? "-" + underTwenty[number % 10] : ""}`;
|
|
147
|
+
const formatGroup = (number2) => {
|
|
148
|
+
if (number2 >= 100) {
|
|
149
|
+
const remainder = number2 % 100;
|
|
150
|
+
return `${underTwenty[Math.floor(number2 / 100)]} hundred${remainder ? ` and ${formatGroup(remainder)}` : ""}`;
|
|
151
|
+
} else if (number2 >= 20) {
|
|
152
|
+
return `${tens[Math.floor(number2 / 10) - 2]}${number2 % 10 ? "-" + underTwenty[number2 % 10] : ""}`;
|
|
153
153
|
} else {
|
|
154
|
-
return underTwenty[
|
|
154
|
+
return underTwenty[number2];
|
|
155
155
|
}
|
|
156
156
|
};
|
|
157
157
|
const scales = ["", " thousand", " million", " billion", " trillion", " quadrillion", " quintillion"];
|
|
158
158
|
let scaleIndex = 0;
|
|
159
159
|
let result = "";
|
|
160
|
-
while (
|
|
161
|
-
const groupValue =
|
|
160
|
+
while (number > 0) {
|
|
161
|
+
const groupValue = number % 1e3;
|
|
162
162
|
if (groupValue > 0) {
|
|
163
163
|
result = formatGroup(groupValue) + scales[scaleIndex] + (result ? ", " + result : "");
|
|
164
164
|
}
|
|
165
|
-
|
|
165
|
+
number = Math.floor(number / 1e3);
|
|
166
166
|
scaleIndex++;
|
|
167
167
|
}
|
|
168
168
|
return result.trim();
|
|
@@ -170,7 +170,7 @@ export function formatNumberToWords(value) {
|
|
|
170
170
|
export function formatInitials(text, options) {
|
|
171
171
|
if (!text)
|
|
172
172
|
return "";
|
|
173
|
-
text = text.replace(
|
|
173
|
+
text = text.replace(/\b(Mrs|Mr|Ms|Dr|Jr|Sr|Prof|Hon|Snr|Jnr|St)\b\.?/g, " ").trim();
|
|
174
174
|
return text.split(" ").filter((word) => !["the", "third"].includes(word.toLowerCase())).map((word) => word.charAt(0).toUpperCase()).join("").substring(0, options?.length ?? 2);
|
|
175
175
|
}
|
|
176
176
|
export function formatUnixTime(timestamp) {
|
|
@@ -28,16 +28,24 @@ export function generatePassword(length = 8) {
|
|
|
28
28
|
const allChars = uppercase + lowercase + numbers + symbols;
|
|
29
29
|
const passwordArray = [];
|
|
30
30
|
const types = [uppercase, lowercase, numbers, symbols];
|
|
31
|
+
const getRandomIndex = (max) => {
|
|
32
|
+
const range = 256 - 256 % max;
|
|
33
|
+
let randomValue;
|
|
34
|
+
do {
|
|
35
|
+
randomValue = window.crypto.getRandomValues(new Uint8Array(1))[0];
|
|
36
|
+
} while (randomValue >= range);
|
|
37
|
+
return randomValue % max;
|
|
38
|
+
};
|
|
31
39
|
types.forEach((type) => {
|
|
32
|
-
const randomIndex =
|
|
40
|
+
const randomIndex = getRandomIndex(type.length);
|
|
33
41
|
passwordArray.push(type[randomIndex]);
|
|
34
42
|
});
|
|
35
43
|
for (let i = passwordArray.length; i < length; i++) {
|
|
36
|
-
const randomIndex =
|
|
44
|
+
const randomIndex = getRandomIndex(allChars.length);
|
|
37
45
|
passwordArray.push(allChars[randomIndex]);
|
|
38
46
|
}
|
|
39
47
|
for (let i = passwordArray.length - 1; i > 0; i--) {
|
|
40
|
-
const j =
|
|
48
|
+
const j = getRandomIndex(i + 1);
|
|
41
49
|
[passwordArray[i], passwordArray[j]] = [passwordArray[j], passwordArray[i]];
|
|
42
50
|
}
|
|
43
51
|
return passwordArray.join("");
|
|
@@ -1,16 +1,22 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Wraps each word, sentence or paragraph in a string with a tag.
|
|
3
|
+
* @info Don't forget to render the HTML safely.
|
|
3
4
|
*/
|
|
4
5
|
export declare function splitByWords(text: string): string;
|
|
5
6
|
/**
|
|
6
7
|
* Check the strength of a password against a given policy.
|
|
7
8
|
*/
|
|
8
|
-
export declare function checkPasswordStrength(value: string,
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
9
|
+
export declare function checkPasswordStrength(value: string, options?: {
|
|
10
|
+
length?: number;
|
|
11
|
+
uppercase?: number;
|
|
12
|
+
number?: number;
|
|
13
|
+
special?: number;
|
|
14
|
+
}): object;
|
|
13
15
|
/**
|
|
14
16
|
* Replaces placeholders in a string with values from an object.
|
|
15
17
|
*/
|
|
16
18
|
export declare function mergeFields(text: string, fields: Record<string | number, string | number>): string;
|
|
19
|
+
/**
|
|
20
|
+
* Returns the reading time of a string in Hours, Minutes, and Seconds.
|
|
21
|
+
*/
|
|
22
|
+
export declare function readingTime(text: string, wordsPerMinute?: number): string;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { formatDurationLabels } from "./formatters.mjs";
|
|
2
2
|
export function splitByWords(text) {
|
|
3
|
-
const sentences = text.split(/([
|
|
3
|
+
const sentences = text.split(/([.?!]\s*)/);
|
|
4
4
|
let wordIndex = 0;
|
|
5
|
-
|
|
5
|
+
const combinedSentences = [];
|
|
6
6
|
for (let i = 0; i < sentences.length; i += 2) {
|
|
7
7
|
const sentence = sentences[i] + (sentences[i + 1] || "");
|
|
8
8
|
if (sentence.trim() === "")
|
|
@@ -15,7 +15,8 @@ export function splitByWords(text) {
|
|
|
15
15
|
}
|
|
16
16
|
return combinedSentences.join(" ");
|
|
17
17
|
}
|
|
18
|
-
export function checkPasswordStrength(value,
|
|
18
|
+
export function checkPasswordStrength(value, options) {
|
|
19
|
+
const { length = 8, uppercase = 1, number = 1, special = 1 } = options || {};
|
|
19
20
|
let strength = 0;
|
|
20
21
|
const counts = {
|
|
21
22
|
uppercase: (value.match(/[A-Z]/g) || []).length,
|
|
@@ -26,15 +27,15 @@ export function checkPasswordStrength(value, length, uppercase, numbers, special
|
|
|
26
27
|
return { score: 1, label: `Password must be at least ${length} characters long` };
|
|
27
28
|
if (counts.uppercase < uppercase)
|
|
28
29
|
return { score: 1, label: `Password must contain ${uppercase} uppercase letter` };
|
|
29
|
-
if (counts.numbers <
|
|
30
|
-
return { score: 1, label: `Password must contain ${
|
|
30
|
+
if (counts.numbers < number)
|
|
31
|
+
return { score: 1, label: `Password must contain ${number} number` };
|
|
31
32
|
if (counts.special < special)
|
|
32
33
|
return { score: 1, label: `Password must contain ${special} special character` };
|
|
33
34
|
if (value.length >= length)
|
|
34
35
|
strength++;
|
|
35
36
|
if (counts.uppercase >= uppercase)
|
|
36
37
|
strength++;
|
|
37
|
-
if (counts.numbers >=
|
|
38
|
+
if (counts.numbers >= number)
|
|
38
39
|
strength++;
|
|
39
40
|
if (counts.special >= special)
|
|
40
41
|
strength++;
|
|
@@ -48,11 +49,6 @@ export function checkPasswordStrength(value, length, uppercase, numbers, special
|
|
|
48
49
|
return { score: 1, label: "Weak" };
|
|
49
50
|
return { score: 0, label: "Very Weak" };
|
|
50
51
|
}
|
|
51
|
-
export function readingTime(text, wordsPerMinute = 200) {
|
|
52
|
-
const words = text.split(" ").length;
|
|
53
|
-
const minutes = Math.ceil(words / wordsPerMinute);
|
|
54
|
-
return formatDurationLabels(minutes * 60);
|
|
55
|
-
}
|
|
56
52
|
export function mergeFields(text, fields) {
|
|
57
53
|
const pattern = /\{\{\s*(\w+)\s*\}\}/g;
|
|
58
54
|
return text.replace(pattern, (match, key) => {
|
|
@@ -64,3 +60,8 @@ export function mergeFields(text, fields) {
|
|
|
64
60
|
}
|
|
65
61
|
});
|
|
66
62
|
}
|
|
63
|
+
export function readingTime(text, wordsPerMinute = 200) {
|
|
64
|
+
const words = text.split(" ").length;
|
|
65
|
+
const minutes = Math.ceil(words / wordsPerMinute);
|
|
66
|
+
return formatDurationLabels(minutes * 60);
|
|
67
|
+
}
|
|
@@ -20,10 +20,12 @@ export declare function endWithout(text: string, end: string): string;
|
|
|
20
20
|
export declare function surroundWith(text: string, start: string, end: string): string;
|
|
21
21
|
/**
|
|
22
22
|
* Adds plurals to a string except for excluded words.
|
|
23
|
+
* @info This handles most english pluralisation rules, but there are exceptions.
|
|
23
24
|
*/
|
|
24
25
|
export declare function pluralize(value: string, count: number): string;
|
|
25
26
|
/**
|
|
26
27
|
* Removes plurals from a string.
|
|
28
|
+
* @info This handles most english pluralisation rules, but there are exceptions.
|
|
27
29
|
*/
|
|
28
30
|
export declare function singularize(value: string): string;
|
|
29
31
|
/**
|
|
@@ -139,7 +139,7 @@ export function ordinalize(value) {
|
|
|
139
139
|
return value + (suffixes[(remainder - 20) % 10] || suffixes[remainder] || suffixes[0]);
|
|
140
140
|
}
|
|
141
141
|
export function stripHtml(text) {
|
|
142
|
-
return text.replace(
|
|
142
|
+
return text.replace(/<\/?[^>]+(>|$)/g, "");
|
|
143
143
|
}
|
|
144
144
|
export function stripWhitespace(text) {
|
|
145
145
|
return text.replace(/\s+/g, "");
|
|
@@ -148,13 +148,13 @@ export function stripNumbers(text) {
|
|
|
148
148
|
return text.replace(/[0-9]/g, "");
|
|
149
149
|
}
|
|
150
150
|
export function stripPunctuation(text) {
|
|
151
|
-
return text.replace(/[
|
|
151
|
+
return text.replace(/[.,/#!$%^&*;:{}=\-_`~()]/g, "");
|
|
152
152
|
}
|
|
153
153
|
export function stripSymbols(text) {
|
|
154
154
|
return text.replace(/[^\w\s]|_/g, "");
|
|
155
155
|
}
|
|
156
156
|
export function stripEmojis(text) {
|
|
157
|
-
return text.replace(/[\
|
|
157
|
+
return text.replace(/[\u{1F600}-\u{1F64F}]/gu, "").replace(/[\u{1F300}-\u{1F5FF}]/gu, "").replace(/[\u{1F680}-\u{1F6FF}]/gu, "").replace(/[\u{1F700}-\u{1F77F}]/gu, "").replace(/[\u{1F780}-\u{1F7FF}]/gu, "").replace(/[\u{1F800}-\u{1F8FF}]/gu, "").replace(/[\u{1F900}-\u{1F9FF}]/gu, "").replace(/[\u{1FA00}-\u{1FA6F}]/gu, "").replace(/[\u{1FA70}-\u{1FAFF}]/gu, "").replace(/[\u{2600}-\u{26FF}]/gu, "").replace(/[\u{2700}-\u{27BF}]/gu, "");
|
|
158
158
|
}
|
|
159
159
|
export function slugify(text) {
|
|
160
160
|
return text.toLowerCase().replace(/[^\w ]+/g, "").replace(/ +/g, "-");
|
|
@@ -181,7 +181,7 @@ export function kebabCase(text) {
|
|
|
181
181
|
}).replace(/\s+/g, "");
|
|
182
182
|
}
|
|
183
183
|
export function titleCase(text) {
|
|
184
|
-
return text.replace(/(?:^\w|[A-Z]|\b\w)/g, (word
|
|
184
|
+
return text.replace(/(?:^\w|[A-Z]|\b\w)/g, (word) => {
|
|
185
185
|
return word.toUpperCase();
|
|
186
186
|
}).replace(/\s+/g, " ");
|
|
187
187
|
}
|
|
@@ -59,7 +59,6 @@ export declare function range(numbers: number[]): number;
|
|
|
59
59
|
*/
|
|
60
60
|
export declare function standardDeviation(numbers: number[]): number;
|
|
61
61
|
/**
|
|
62
|
-
* Returns the measure of asymmetry of the probability distribution of an array of numbers.
|
|
63
|
-
* The skewness value can be positive, zero, negative, or undefined.
|
|
62
|
+
* Returns the measure of asymmetry of the probability distribution of an array of numbers. The skewness value can be positive, zero, negative, or undefined.
|
|
64
63
|
*/
|
|
65
|
-
export declare function skewness(numbers: number[]): number
|
|
64
|
+
export declare function skewness(numbers: number[]): number;
|
|
@@ -1,67 +1,68 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Check if any given value is a valid email address.
|
|
3
3
|
*/
|
|
4
|
-
export declare function isEmail(value:
|
|
4
|
+
export declare function isEmail(value: string): boolean;
|
|
5
5
|
/**
|
|
6
6
|
* Check if any given value is a valid number.
|
|
7
7
|
*/
|
|
8
|
-
export declare function isNumber(value:
|
|
8
|
+
export declare function isNumber(value: string | number): boolean;
|
|
9
9
|
/**
|
|
10
10
|
* Check if any given value is a valid URL.
|
|
11
11
|
*/
|
|
12
|
-
export declare function isUrl(value:
|
|
12
|
+
export declare function isUrl(value: string): boolean;
|
|
13
|
+
/**
|
|
13
14
|
/**
|
|
14
15
|
* Check if any given string, array or object is empty.
|
|
15
16
|
*/
|
|
16
|
-
export declare function isEmpty(value:
|
|
17
|
+
export declare function isEmpty(value: string | string[] | number[] | object | null | undefined): boolean;
|
|
17
18
|
/**
|
|
18
19
|
* Check if any given value is a valid UUID.
|
|
19
20
|
*/
|
|
20
|
-
export declare function isUuid(value:
|
|
21
|
+
export declare function isUuid(value: string): boolean;
|
|
21
22
|
/**
|
|
22
23
|
* Check if any given value is a valid JSON string.
|
|
23
24
|
*/
|
|
24
|
-
export declare function isJson(value:
|
|
25
|
+
export declare function isJson(value: string): boolean;
|
|
25
26
|
/**
|
|
26
27
|
* Check if any given value is an object.
|
|
27
28
|
*/
|
|
28
|
-
export declare function isObject(value:
|
|
29
|
+
export declare function isObject(value: object): boolean;
|
|
29
30
|
/**
|
|
30
31
|
* Check if any given value is an array.
|
|
31
32
|
*/
|
|
32
|
-
export declare function isArray(value:
|
|
33
|
+
export declare function isArray(value: string[] | number[]): boolean;
|
|
33
34
|
/**
|
|
34
35
|
* Check if any given value is a valid hexadecimal color code.
|
|
35
36
|
*/
|
|
36
|
-
export declare function isHex(value:
|
|
37
|
+
export declare function isHex(value: string): boolean;
|
|
37
38
|
/**
|
|
38
39
|
* Check if any given value contains only alphabetic characters.
|
|
39
40
|
*/
|
|
40
|
-
export declare function isAlphabetic(value:
|
|
41
|
+
export declare function isAlphabetic(value: string): boolean;
|
|
41
42
|
/**
|
|
42
43
|
* Check if any given value contains only alphanumeric characters.
|
|
43
44
|
*/
|
|
44
|
-
export declare function isAlphanumeric(value:
|
|
45
|
+
export declare function isAlphanumeric(value: string): boolean;
|
|
45
46
|
/**
|
|
46
47
|
* Check if any given value is a boolean value.
|
|
47
48
|
*/
|
|
48
|
-
export declare function isBoolean(value:
|
|
49
|
+
export declare function isBoolean(value: boolean): boolean;
|
|
49
50
|
/**
|
|
50
51
|
* Check if any given value is undefined.
|
|
51
52
|
*/
|
|
52
|
-
export declare function isUndefined(value:
|
|
53
|
+
export declare function isUndefined(value: undefined): boolean;
|
|
53
54
|
/**
|
|
54
55
|
* Check if any given value is null.
|
|
55
56
|
*/
|
|
56
|
-
export declare function isNull(value:
|
|
57
|
+
export declare function isNull(value: null): boolean;
|
|
57
58
|
/**
|
|
58
59
|
* Check if any given value is a valid Date object.
|
|
59
60
|
*/
|
|
60
|
-
export declare function isDate(value:
|
|
61
|
+
export declare function isDate(value: Date): boolean;
|
|
61
62
|
/**
|
|
62
63
|
* Check if any given value is a valid time in HH:mm format.
|
|
63
64
|
*/
|
|
64
|
-
export declare function isTime(value:
|
|
65
|
+
export declare function isTime(value: string): boolean;
|
|
65
66
|
/**
|
|
66
67
|
* Check if any given value year is a leap year.
|
|
67
68
|
*/
|
|
@@ -97,11 +98,11 @@ export declare function isPrime(value: number): boolean;
|
|
|
97
98
|
/**
|
|
98
99
|
* Check if the number is an integer.
|
|
99
100
|
*/
|
|
100
|
-
export declare function isInteger(value:
|
|
101
|
+
export declare function isInteger(value: number): boolean;
|
|
101
102
|
/**
|
|
102
103
|
* Check if the number is a float.
|
|
103
104
|
*/
|
|
104
|
-
export declare function isFloat(value:
|
|
105
|
+
export declare function isFloat(value: number): boolean;
|
|
105
106
|
/**
|
|
106
107
|
* Check if the number is between the specified range.
|
|
107
108
|
*/
|
|
@@ -113,23 +114,23 @@ export declare function isDivisibleBy(value: number, divisor: number): boolean;
|
|
|
113
114
|
/**
|
|
114
115
|
* Check if any given value is a valid credit card number.
|
|
115
116
|
*/
|
|
116
|
-
export declare function isCreditCard(value:
|
|
117
|
+
export declare function isCreditCard(value: string): boolean;
|
|
117
118
|
/**
|
|
118
119
|
* Check if any given value is a valid latitude-longitude coordinate in the format lat,lng or lat,lng.
|
|
119
120
|
*/
|
|
120
|
-
export declare function isLatLng(value:
|
|
121
|
+
export declare function isLatLng(value: string): boolean;
|
|
121
122
|
/**
|
|
122
123
|
* Check if any given value is a valid latitude coordinate.
|
|
123
124
|
*/
|
|
124
|
-
export declare function isLatitude(value:
|
|
125
|
+
export declare function isLatitude(value: string): boolean;
|
|
125
126
|
/**
|
|
126
127
|
* Check if any given value is a valid longitude coordinate.
|
|
127
128
|
*/
|
|
128
|
-
export declare function isLongitude(value:
|
|
129
|
+
export declare function isLongitude(value: string): boolean;
|
|
129
130
|
/**
|
|
130
131
|
* Check if any given value is a valid IP address.
|
|
131
132
|
*/
|
|
132
|
-
export declare function isIpAddress(value:
|
|
133
|
+
export declare function isIpAddress(value: string): boolean;
|
|
133
134
|
/**
|
|
134
135
|
* Check if any given value is a valid port number.
|
|
135
136
|
*/
|
|
@@ -137,7 +138,7 @@ export declare function isPort(value: number): boolean;
|
|
|
137
138
|
/**
|
|
138
139
|
* Check if any given value is a valid MAC address.
|
|
139
140
|
*/
|
|
140
|
-
export declare function isMacAddress(value:
|
|
141
|
+
export declare function isMacAddress(value: string): boolean;
|
|
141
142
|
/**
|
|
142
143
|
* Check if you're a passionate iPhone fan.
|
|
143
144
|
*/
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export function isEmail(value) {
|
|
2
|
-
const regex = /^[a-zA-Z0-9._
|
|
2
|
+
const regex = /^(?!.*[._+-]{2})(?!.*[._+-]$)[a-zA-Z0-9._+-]+(?<!\.)@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/;
|
|
3
3
|
return regex.test(value);
|
|
4
4
|
}
|
|
5
5
|
export function isNumber(value) {
|
|
@@ -9,7 +9,7 @@ export function isNumber(value) {
|
|
|
9
9
|
return false;
|
|
10
10
|
}
|
|
11
11
|
export function isUrl(value) {
|
|
12
|
-
const regex = /^(?:\w+:)?\/\/([^\s
|
|
12
|
+
const regex = /^(?:\w+:)?\/\/([^\s.]+\.\S{2,}|localhost[:?\d]*(?:[^:?\d]\S*)?)$/;
|
|
13
13
|
return regex.test(value);
|
|
14
14
|
}
|
|
15
15
|
export function isEmpty(value) {
|
|
@@ -21,7 +21,7 @@ export function isEmpty(value) {
|
|
|
21
21
|
return value.length === 0;
|
|
22
22
|
if (typeof value === "object")
|
|
23
23
|
return Object.keys(value).length === 0;
|
|
24
|
-
return
|
|
24
|
+
return false;
|
|
25
25
|
}
|
|
26
26
|
export function isUuid(value) {
|
|
27
27
|
const regex = /^[a-f\d]{8}(-[a-f\d]{4}){4}[a-f\d]{8}$/i;
|