mirror of
https://github.com/Kuingsmile/PicList.git
synced 2025-02-08 21:38:13 -05:00
🔨 Refactor: refactor some util func
This commit is contained in:
parent
80057c8561
commit
12be9d5802
@ -11,14 +11,6 @@ export const handleTalkingDataEvent = (data: ITalkingDataOptions) => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export const trimValues = (obj: IStringKeyMap) => {
|
|
||||||
const newObj = {} as IStringKeyMap
|
|
||||||
Object.keys(obj).forEach(key => {
|
|
||||||
newObj[key] = typeof obj[key] === 'string' ? obj[key].trim() : obj[key]
|
|
||||||
})
|
|
||||||
return newObj
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* get raw data from reactive or ref
|
* get raw data from reactive or ref
|
||||||
*/
|
*/
|
||||||
|
@ -4,16 +4,9 @@ import { v4 as uuid } from 'uuid'
|
|||||||
import { IRPCActionType } from '~/universal/types/enum'
|
import { IRPCActionType } from '~/universal/types/enum'
|
||||||
import { getRawData } from './common'
|
import { getRawData } from './common'
|
||||||
|
|
||||||
export function saveConfig (_config: IObj | string, value?: any) {
|
export function saveConfig (config: IObj | string, value?: any) {
|
||||||
let config
|
const configObject = typeof config === 'string' ? { [config]: value } : getRawData(config)
|
||||||
if (typeof _config === 'string') {
|
ipcRenderer.send(PICGO_SAVE_CONFIG, configObject)
|
||||||
config = {
|
|
||||||
[_config]: value
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
config = getRawData(_config)
|
|
||||||
}
|
|
||||||
ipcRenderer.send(PICGO_SAVE_CONFIG, config)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getConfig<T> (key?: string): Promise<T | undefined> {
|
export function getConfig<T> (key?: string): Promise<T | undefined> {
|
||||||
|
@ -20,12 +20,7 @@ export const isUrlEncode = (url: string): boolean => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export const handleUrlEncode = (url: string): string => {
|
export const handleUrlEncode = (url: string): string => isUrlEncode(url) ? url : encodeURI(url)
|
||||||
if (!isUrlEncode(url)) {
|
|
||||||
url = encodeURI(url)
|
|
||||||
}
|
|
||||||
return url
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* streamline the full plugin name to a simple one
|
* streamline the full plugin name to a simple one
|
||||||
@ -47,17 +42,13 @@ export const simpleClone = (obj: any) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const enforceNumber = (num: number | string) => {
|
export const enforceNumber = (num: number | string) => {
|
||||||
return isNaN(Number(num)) ? 0 : Number(num)
|
return isNaN(+num) ? 0 : +num
|
||||||
}
|
}
|
||||||
|
|
||||||
export const isDev = process.env.NODE_ENV === 'development'
|
export const isDev = process.env.NODE_ENV === 'development'
|
||||||
|
|
||||||
export const trimValues = (obj: IStringKeyMap) => {
|
export const trimValues = <T extends IStringKeyMap>(obj: T): {[K in keyof T]: T[K] extends string ? string : T[K]} => {
|
||||||
const newObj = {} as IStringKeyMap
|
return Object.fromEntries(Object.entries(obj).map(([key, value]) => [key, typeof value === 'string' ? value.trim() : value])) as {[K in keyof T]: T[K] extends string ? string : T[K]}
|
||||||
Object.keys(obj).forEach(key => {
|
|
||||||
newObj[key] = typeof obj[key] === 'string' ? obj[key].trim() : obj[key]
|
|
||||||
})
|
|
||||||
return newObj
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const c1nApi = 'https://c1n.cn/link/short'
|
const c1nApi = 'https://c1n.cn/link/short'
|
||||||
|
Loading…
Reference in New Issue
Block a user