mirror of
https://github.com/antebudimir/feishin.git
synced 2026-01-01 10:23:33 +00:00
Add files
This commit is contained in:
commit
e87c814068
266 changed files with 63938 additions and 0 deletions
23
src/renderer/utils/constrain-sidebar-width.ts
Normal file
23
src/renderer/utils/constrain-sidebar-width.ts
Normal 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;
|
||||
};
|
||||
3
src/renderer/utils/get-header-color.ts
Normal file
3
src/renderer/utils/get-header-color.ts
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
export const getHeaderColor = (rgbColor: string, opacity?: number) => {
|
||||
return rgbColor.replace('rgb', 'rgba').replace(')', `, ${opacity || 0.8})`);
|
||||
};
|
||||
7
src/renderer/utils/index.ts
Normal file
7
src/renderer/utils/index.ts
Normal 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';
|
||||
4
src/renderer/utils/normalize-server-url.ts
Normal file
4
src/renderer/utils/normalize-server-url.ts
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
export const normalizeServerUrl = (url: string) => {
|
||||
// Remove trailing slash
|
||||
return url.endsWith('/') ? url.slice(0, -1) : url;
|
||||
};
|
||||
3
src/renderer/utils/parse-search-params.ts
Normal file
3
src/renderer/utils/parse-search-params.ts
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
export const parseSearchParams = (searchParams: Record<any, any>) => {
|
||||
return JSON.parse(JSON.stringify(searchParams));
|
||||
};
|
||||
9
src/renderer/utils/random-string.ts
Normal file
9
src/renderer/utils/random-string.ts
Normal 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;
|
||||
};
|
||||
10
src/renderer/utils/set-local-storage-setttings.ts
Normal file
10
src/renderer/utils/set-local-storage-setttings.ts
Normal 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));
|
||||
};
|
||||
5
src/renderer/utils/title-case.ts
Normal file
5
src/renderer/utils/title-case.ts
Normal 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();
|
||||
});
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue