Home / File/ shared.ts — astro Source File

shared.ts — astro Source File

Architecture documentation for shared.ts, a typescript file in the astro codebase. 1 imports, 0 dependents.

File typescript CoreAstro RenderingEngine 1 imports 3 functions

Entity Profile

Dependency Diagram

graph LR
  a889965c_1012_004b_402e_d9c7a19cb67b["shared.ts"]
  e16a223b_37f3_6b25_1ee1_2b7bcb9d9415["node:fs"]
  a889965c_1012_004b_402e_d9c7a19cb67b --> e16a223b_37f3_6b25_1ee1_2b7bcb9d9415
  style a889965c_1012_004b_402e_d9c7a19cb67b fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

import fs from 'node:fs';

// Some existing files and directories can be safely ignored when checking if a directory is a valid project directory.
// https://github.com/facebook/create-react-app/blob/d960b9e38c062584ff6cfb1a70e1512509a966e7/packages/create-react-app/createReactApp.js#L907-L934
const VALID_PROJECT_DIRECTORY_SAFE_LIST = [
	'.DS_Store',
	'.git',
	'.gitkeep',
	'.gitattributes',
	'.gitignore',
	'.gitlab-ci.yml',
	'.hg',
	'.hgcheck',
	'.hgignore',
	'.idea',
	'.npmignore',
	'.travis.yml',
	'.yarn',
	'.yarnrc.yml',
	'docs',
	'LICENSE',
	'mkdocs.yml',
	'Thumbs.db',
	/\.iml$/,
	/^npm-debug\.log/,
	/^yarn-debug\.log/,
	/^yarn-error\.log/,
];

export function isEmpty(dirPath: string) {
	if (!fs.existsSync(dirPath)) {
		return true;
	}

	const conflicts = fs.readdirSync(dirPath).filter((content) => {
		return !VALID_PROJECT_DIRECTORY_SAFE_LIST.some((safeContent) => {
			return typeof safeContent === 'string' ? content === safeContent : safeContent.test(content);
		});
	});

	return conflicts.length === 0;
}

function isValidName(projectName: string) {
	return /^(?:@[a-z\d\-*~][a-z\d\-*._~]*\/)?[a-z\d\-~][a-z\d\-._~]*$/.test(projectName);
}

export function toValidName(projectName: string) {
	if (isValidName(projectName)) return projectName;

	return projectName
		.trim()
		.toLowerCase()
		.replace(/\s+/g, '-')
		.replace(/^[._]/, '')
		.replace(/[^a-z\d\-~]+/g, '-')
		.replace(/^-+/, '')
		.replace(/-+$/, '');
}

Domain

Subdomains

Dependencies

  • node:fs

Frequently Asked Questions

What does shared.ts do?
shared.ts is a source file in the astro codebase, written in typescript. It belongs to the CoreAstro domain, RenderingEngine subdomain.
What functions are defined in shared.ts?
shared.ts defines 3 function(s): isEmpty, isValidName, toValidName.
What does shared.ts depend on?
shared.ts imports 1 module(s): node:fs.
Where is shared.ts in the architecture?
shared.ts is located at packages/create-astro/src/actions/shared.ts (domain: CoreAstro, subdomain: RenderingEngine, directory: packages/create-astro/src/actions).

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free