2023-02-19 21:25:59 -05:00
|
|
|
export const isUrl = (url: string): boolean => (/^https?:\/\//.test(url))
|
2020-06-28 03:30:58 -04:00
|
|
|
export const isUrlEncode = (url: string): boolean => {
|
|
|
|
url = url || ''
|
|
|
|
try {
|
2022-10-24 05:14:39 -04:00
|
|
|
return url !== decodeURI(url)
|
2020-06-28 03:30:58 -04:00
|
|
|
} catch (e) {
|
|
|
|
// if some error caught, try to let it go
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export const handleUrlEncode = (url: string): string => {
|
|
|
|
if (!isUrlEncode(url)) {
|
2022-10-24 05:14:39 -04:00
|
|
|
url = encodeURI(url)
|
2020-06-28 03:30:58 -04:00
|
|
|
}
|
|
|
|
return url
|
|
|
|
}
|
2020-12-26 10:39:48 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
* streamline the full plugin name to a simple one
|
|
|
|
* for example:
|
|
|
|
* 1. picgo-plugin-xxx -> xxx
|
|
|
|
* 2. @xxx/picgo-plugin-yyy -> yyy
|
|
|
|
* @param name pluginFullName
|
|
|
|
*/
|
|
|
|
export const handleStreamlinePluginName = (name: string) => {
|
|
|
|
if (/^@[^/]+\/picgo-plugin-/.test(name)) {
|
|
|
|
return name.replace(/^@[^/]+\/picgo-plugin-/, '')
|
|
|
|
} else {
|
|
|
|
return name.replace(/picgo-plugin-/, '')
|
|
|
|
}
|
|
|
|
}
|
2022-06-12 08:20:08 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* for just simple clone an object
|
|
|
|
*/
|
|
|
|
export const simpleClone = (obj: any) => {
|
|
|
|
return JSON.parse(JSON.stringify(obj))
|
|
|
|
}
|
2022-07-31 05:47:15 -04:00
|
|
|
|
|
|
|
export const enforceNumber = (num: number | string) => {
|
|
|
|
return isNaN(Number(num)) ? 0 : Number(num)
|
|
|
|
}
|
2022-10-30 04:08:29 -04:00
|
|
|
|
|
|
|
export const isDev = process.env.NODE_ENV === 'development'
|
2022-12-31 07:44:19 -05:00
|
|
|
|
|
|
|
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
|
|
|
|
}
|