mirror of
https://github.com/jeffvli/feishin.git
synced 2026-05-07 20:40:15 +02:00
Add files
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
export const constrainSidebarWidth = (num: number) => {
|
||||
if (num < 200) {
|
||||
return 200;
|
||||
}
|
||||
|
||||
if (num > 400) {
|
||||
return 400;
|
||||
}
|
||||
|
||||
return num;
|
||||
};
|
||||
|
||||
export const constrainRightSidebarWidth = (num: number) => {
|
||||
if (num < 250) {
|
||||
return 250;
|
||||
}
|
||||
|
||||
if (num > 960) {
|
||||
return 960;
|
||||
}
|
||||
|
||||
return num;
|
||||
};
|
||||
@@ -0,0 +1,3 @@
|
||||
export const getHeaderColor = (rgbColor: string, opacity?: number) => {
|
||||
return rgbColor.replace('rgb', 'rgba').replace(')', `, ${opacity || 0.8})`);
|
||||
};
|
||||
@@ -0,0 +1,7 @@
|
||||
export * from './random-string';
|
||||
export * from './normalize-server-url';
|
||||
export * from './set-local-storage-setttings';
|
||||
export * from './constrain-sidebar-width';
|
||||
export * from './title-case';
|
||||
export * from './get-header-color';
|
||||
export * from './parse-search-params';
|
||||
@@ -0,0 +1,4 @@
|
||||
export const normalizeServerUrl = (url: string) => {
|
||||
// Remove trailing slash
|
||||
return url.endsWith('/') ? url.slice(0, -1) : url;
|
||||
};
|
||||
@@ -0,0 +1,3 @@
|
||||
export const parseSearchParams = (searchParams: Record<any, any>) => {
|
||||
return JSON.parse(JSON.stringify(searchParams));
|
||||
};
|
||||
@@ -0,0 +1,9 @@
|
||||
export const randomString = (length?: number) => {
|
||||
const charSet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
|
||||
let string = '';
|
||||
for (let i = 0; i < (length || 12); i += 1) {
|
||||
const randomPoz = Math.floor(Math.random() * charSet.length);
|
||||
string += charSet.substring(randomPoz, randomPoz + 1);
|
||||
}
|
||||
return string;
|
||||
};
|
||||
@@ -0,0 +1,10 @@
|
||||
export const setLocalStorageSettings = (type: 'player', object: any) => {
|
||||
const settings = JSON.parse(localStorage.getItem('settings') || '{}');
|
||||
|
||||
const newSettings = {
|
||||
...settings,
|
||||
[type]: { ...object },
|
||||
};
|
||||
|
||||
localStorage.setItem('settings', JSON.stringify(newSettings));
|
||||
};
|
||||
@@ -0,0 +1,5 @@
|
||||
export const titleCase = (str: string) => {
|
||||
return str.replace(/\w\S*/g, (txt) => {
|
||||
return txt.charAt(0).toUpperCase() + txt.slice(1).toLowerCase();
|
||||
});
|
||||
};
|
||||
Reference in New Issue
Block a user