first commit
Some checks failed
Build / run (push) Has been cancelled

This commit is contained in:
maher
2025-10-29 11:42:25 +01:00
commit 703f50a09d
4595 changed files with 385164 additions and 0 deletions

View File

@@ -0,0 +1,8 @@
const matcher =
/^[a-zA-Z0-9.!#$%&'*+\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/;
export function isEmail(string?: string): boolean {
if (!string) return false;
if (string.length > 320) return false;
return matcher.test(string);
}

View File

@@ -0,0 +1,4 @@
export function lowerFirst(string: string): string {
if (!string) return '';
return string.charAt(0).toLowerCase() + string.slice(1);
}

View File

@@ -0,0 +1,11 @@
export function randomNumber(min: number = 1, max: number = 10000) {
const randomBuffer = new Uint32Array(1);
window.crypto.getRandomValues(randomBuffer);
const number = randomBuffer[0] / (0xffffffff + 1);
min = Math.ceil(min);
max = Math.floor(max);
return Math.floor(number * (max - min + 1)) + min;
}

View File

@@ -0,0 +1,11 @@
export function randomString(length: number = 36) {
let random = '';
const possible =
'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
for (let i = 0; i < length; i += 1) {
random += possible.charAt(Math.floor(Math.random() * possible.length));
}
return random;
}

View File

@@ -0,0 +1,21 @@
import slugify from 'slugify';
export function slugifyString(
text: string,
replacement = '-',
strict = false,
): string {
if (!text) return text;
let slugified = slugify(text, {
lower: true,
replacement,
strict,
remove: /[*+~.()'"!:@?\|/\\#]/g,
});
// some chinese text might not get slugified properly,
// just replace whitespace with dash in that case
if (!slugified) {
slugified = text.replace(/\s+/g, '-').toLowerCase();
}
return slugified;
}

View File

@@ -0,0 +1,3 @@
export function stripTags(str: string) {
return str.replace(/<\/?[^>]+(>|$)/g, '');
}

View File

@@ -0,0 +1,6 @@
export function truncateString(str: string, length: number, end = '...') {
if (length == null || length >= str.length) {
return str;
}
return str.slice(0, Math.max(0, length - end.length)) + end;
}

View File

@@ -0,0 +1,4 @@
export function ucFirst<T extends string>(string: T): T {
if (!string) return string;
return (string.charAt(0).toUpperCase() + string.slice(1)) as T;
}