-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathutils.ts
More file actions
40 lines (33 loc) · 870 Bytes
/
utils.ts
File metadata and controls
40 lines (33 loc) · 870 Bytes
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
// Import Internal Dependencies
import type { Severity } from "./formats/standard/index.ts";
export function fromMaybeStringToArray(
value: undefined | null | string | string[]
): string[] {
if (Array.isArray(value)) {
return value;
}
return value ? [value] : [];
}
export function standardizeNpmSeverity(
severity: string
): Severity {
if (severity === "moderate") {
return "medium";
}
return severity as Severity;
}
export function parseNpmSpec(
spec: string
) {
const parts = spec.split("@");
return spec.startsWith("@") ?
{ name: `@${parts[1]}`, version: parts[2] ?? void 0 } :
{ name: parts[0], version: parts[1] ?? void 0 };
}
export function* chunkArray<T = any>(
arr: T[], chunkSize: number
): IterableIterator<T[]> {
for (let i = 0; i < arr.length; i += chunkSize) {
yield arr.slice(i, i + chunkSize);
}
}