Spaces:
Running
Running
Download tiled-mcp/src/names.ts from 4math/tiled-map-builder: direct link, hf CLI and curl.
- Browser
- Download file 742 Bytes
-
https://huggingface.co/spaces/4math/tiled-map-builder/resolve/main/tiled-mcp/src/names.ts
- Command line
-
hf download hf://spaces/4math/tiled-map-builder/tiled-mcp/src/names.ts
-
curl -L -o names.ts https://huggingface.co/spaces/4math/tiled-map-builder/resolve/main/tiled-mcp/src/names.ts
742 Bytes
| // File-system friendly names, shared by map files, downloads and building ids. | |
| /** Slug of a display name, e.g. "Crypt under the chapel" -> "crypt-under-the-chapel". */ | |
| export function slugify(name: string): string { | |
| const slug = name | |
| .normalize("NFKD") | |
| .replace(/[̀-ͯ]/g, "") | |
| .toLowerCase() | |
| .replace(/[^a-z0-9]+/g, "-") | |
| .replace(/^-+|-+$/g, "") | |
| .slice(0, 60); | |
| return slug || "map"; | |
| } | |
| /** `base`, or `base-2`, `base-3`... : the first candidate `taken` does not hold. */ | |
| export function uniqueName(base: string, taken: (candidate: string) => boolean): string { | |
| if (!taken(base)) return base; | |
| for (let i = 2; ; i++) { | |
| const candidate = `${base}-${i}`; | |
| if (!taken(candidate)) return candidate; | |
| } | |
| } | |