CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
sagemathinc

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

GitHub Repository: sagemathinc/cocalc
Path: blob/master/src/packages/util/licenses/check-disk-name-basics.ts
Views: 687
1
/*
2
* This file is part of CoCalc: Copyright © 2022 Sagemath, Inc.
3
* License: MS-RSL – see LICENSE.md for details
4
*/
5
6
// this is the first set of tests -- the second test is uniqueness
7
export function testDedicatedDiskNameBasic(name: any) {
8
const minLength = 6;
9
const maxLength = 20;
10
11
if (name == null) {
12
throw new Error("Please enter a name.");
13
} else if (name.length < minLength) {
14
throw new Error(`Name must have at least ${minLength} characters.`);
15
} else if (name.length > maxLength) {
16
throw new Error(`Name must have at most ${maxLength} characters.`);
17
} else if (!/^[a-z0-9-]+$/.test(name)) {
18
throw new Error(
19
"Name must consist of lowercase letters, numbers, and hyphens only."
20
);
21
}
22
}
23
24