-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfeature-flags.js
More file actions
64 lines (51 loc) · 1.38 KB
/
Copy pathfeature-flags.js
File metadata and controls
64 lines (51 loc) · 1.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
const aiFeatureStorageKey = 'knighted:develop:feature:ai-assistant'
const aiFeatureQueryKey = 'feature-ai'
const parseBooleanLikeValue = value => {
if (typeof value !== 'string') {
return null
}
const normalized = value.trim().toLowerCase()
if (['1', 'true', 'on', 'yes', 'enabled'].includes(normalized)) {
return true
}
if (['0', 'false', 'off', 'no', 'disabled'].includes(normalized)) {
return false
}
return null
}
const readBooleanFromLocalStorage = key => {
try {
const storedValue = localStorage.getItem(key)
return parseBooleanLikeValue(storedValue)
} catch {
return null
}
}
const readBooleanFromQueryParam = key => {
if (typeof window === 'undefined') {
return null
}
const params = new URLSearchParams(window.location.search)
if (!params.has(key)) {
return null
}
return parseBooleanLikeValue(params.get(key))
}
export const isAiAssistantFeatureEnabled = () => {
const queryValue = readBooleanFromQueryParam(aiFeatureQueryKey)
if (queryValue !== null) {
return queryValue
}
const localStorageValue = readBooleanFromLocalStorage(aiFeatureStorageKey)
if (localStorageValue !== null) {
return localStorageValue
}
return false
}
export const setAiAssistantFeatureEnabled = isEnabled => {
try {
localStorage.setItem(aiFeatureStorageKey, isEnabled ? 'true' : 'false')
} catch {
/* noop */
}
}