mirror of
https://github.com/LukeHagar/electron-vite.git
synced 2025-12-09 12:27:43 +00:00
feat: support for node worker (#51)
This commit is contained in:
15
src/utils.ts
15
src/utils.ts
@@ -1,3 +1,5 @@
|
||||
import { URL, URLSearchParams } from 'node:url'
|
||||
|
||||
export function isObject(value: unknown): value is Record<string, unknown> {
|
||||
return Object.prototype.toString.call(value) === '[object Object]'
|
||||
}
|
||||
@@ -9,3 +11,16 @@ export const wildcardHosts = new Set(['0.0.0.0', '::', '0000:0000:0000:0000:0000
|
||||
export function resolveHostname(optionsHost: string | boolean | undefined): string {
|
||||
return typeof optionsHost === 'string' && !wildcardHosts.has(optionsHost) ? optionsHost : 'localhost'
|
||||
}
|
||||
|
||||
export const queryRE = /\?.*$/s
|
||||
export const hashRE = /#.*$/s
|
||||
|
||||
export const cleanUrl = (url: string): string => url.replace(hashRE, '').replace(queryRE, '')
|
||||
|
||||
export function parseRequest(id: string): Record<string, string> | null {
|
||||
const { search } = new URL(id, 'file:')
|
||||
if (!search) {
|
||||
return null
|
||||
}
|
||||
return Object.fromEntries(new URLSearchParams(search))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user