-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathutil.ts
More file actions
18 lines (17 loc) · 649 Bytes
/
Copy pathutil.ts
File metadata and controls
18 lines (17 loc) · 649 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
/**
* Utility functions for the Lightscripts Workshop
*/
/**
* Gets a URL parameter by name
* @param name The name of the parameter to get
* @param url Optional URL string (default: window.location.href)
* @returns The parameter value or null if not found
*/
export function getParameterByName(paramName: string, url = window.location.href): string | null {
const safeName = paramName.replace(/[[\]]/g, '\\$&')
const regex = new RegExp(`[?&]${safeName}(=([^&#]*)|&|#|$)`)
const results = regex.exec(url)
if (!results) return null
if (!results[2]) return ''
return decodeURIComponent(results[2].replace(/\+/g, ' '))
}