Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
quantum-kittens
GitHub Repository: quantum-kittens/platypus
Path: blob/main/frontend/ts/utilities.ts
3855 views
1
const mergeJson = function (target: any, source: any) {
2
for (const key of Object.keys(source)) {
3
if (Array.isArray(target[key])) {
4
const merged = [...target[key], ...source[key]]
5
target[key] = [...new Set(merged)]
6
} else if (target[key] instanceof Object) {
7
const mergedJsons = mergeJson(target[key], source[key])
8
Object.assign(source[key], mergedJsons)
9
} else {
10
Object.assign(target, {
11
[key]: source[key]
12
})
13
}
14
}
15
return target
16
}
17
18
const randomValue = function (min: number, max: number, step: number = 0.000001) {
19
const rnd = Math.random()
20
const rangedRandom = rnd * (max - min) + min
21
22
return Math.round(rangedRandom / step) * step
23
}
24
25
const isExternal = function (url: string): boolean {
26
return !!url && url.startsWith('http')
27
}
28
29
const isMail = function (url: string): boolean {
30
return !!url && url.startsWith('mailto')
31
}
32
33
const isIdAnchor = function (url: string): boolean {
34
return !!url && url.startsWith('#')
35
}
36
37
export {
38
isExternal,
39
isMail,
40
isIdAnchor,
41
mergeJson,
42
randomValue
43
}
44
45