Add files

This commit is contained in:
jeffvli 2022-12-19 15:59:14 -08:00
commit e87c814068
266 changed files with 63938 additions and 0 deletions

View file

@ -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;
};

View file

@ -0,0 +1,3 @@
export const getHeaderColor = (rgbColor: string, opacity?: number) => {
return rgbColor.replace('rgb', 'rgba').replace(')', `, ${opacity || 0.8})`);
};

View file

@ -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';

View file

@ -0,0 +1,4 @@
export const normalizeServerUrl = (url: string) => {
// Remove trailing slash
return url.endsWith('/') ? url.slice(0, -1) : url;
};

View file

@ -0,0 +1,3 @@
export const parseSearchParams = (searchParams: Record<any, any>) => {
return JSON.parse(JSON.stringify(searchParams));
};

View file

@ -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;
};

View file

@ -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));
};

View file

@ -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();
});
};