This repository was archived by the owner on Feb 27, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutil.ts
More file actions
80 lines (73 loc) · 1.88 KB
/
util.ts
File metadata and controls
80 lines (73 loc) · 1.88 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import { Vercel } from '@vercel/sdk'
import constants from './constants.json' with { type: 'json' }
const { teamId } = constants
export const getBenchmarkProjects = async (
vercel: Vercel,
{
limit = '100',
filters = [],
}: {
limit?: string
filters?: string[]
},
) => {
const projects = await vercel.projects.getProjects({
teamId,
search: 'benchmark-',
limit,
})
return (
projects.projects
?.filter(
(project) =>
project.name.startsWith('benchmark-') &&
// benchmark-deploy is the project that deploys the benchmark projects
project.name !== 'benchmark-deploy',
)
.filter((project) => {
return (
filters.length === 0 ||
filters.some((filter) =>
project.name.replace(/^benchmark-/, '').startsWith(filter),
)
)
}) ?? []
)
}
export const errorResponse = (error: string, code = 500) => {
return new Response(JSON.stringify({ error }, null, 2), { status: code })
}
export const successResponse = (data: any) => {
return new Response(JSON.stringify(data, null, 2), { status: 200 })
}
export const createCombinations = <T>(arrays: T[][]): T[][] => {
return arrays.reduce(
(acc, array) => {
return acc.flatMap((combination) =>
array.map((item) => [...combination, item]),
)
},
[[]] as T[][],
)
}
export const shortestCommonPrefix = (strings: string[]) => {
if (strings.length === 0) {
return ''
}
let prefix = strings[0]!
for (const string of strings) {
while (!string.startsWith(prefix)) {
prefix = prefix.slice(0, -1)
if (prefix === '') {
return ''
}
}
}
return prefix
}
export const uniqBy = <T>(array: T[], key: (item: T) => string): T[] => {
return array.filter(
(item, index, self) =>
index === self.findIndex((t) => key(t) === key(item)),
)
}