How to use the path-type.dir function in path-type

To help you get started, we’ve selected a few path-type examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github zeit / serve / lib / server.js View on Github external
if (cacheValue > 0) {
		streamOptions.maxAge = flags.cache;
	} else if (cacheValue === 0) {
		// Disable the cache control by `send`, as there's no support for `no-cache`.
		// Set header manually.
		streamOptions.cacheControl = false;
		res.setHeader('Cache-Control', 'no-cache, no-store, must-revalidate');
	} else if (flags.single) {
		// Cache assets of single page applications for a day.
		// Later in the code, we'll define that `index.html` never
		// gets cached!
		streamOptions.maxAge = 86400000;
	}

	// Check if directory
	if (relatedExists && (yield pathType.dir(related))) {
		// Normalize path to trailing slash
		// Otherwise problems like #70 will occur
		const url = parse(req.url);

		if (url.pathname.substr(-1) !== '/') {
			url.pathname += '/';
			const newPath = format(url);

			res.writeHead(302, {
				Location: newPath
			});

			res.end();
			return;
		}
github alan-ai / alan-sdk-reactnative / testtools / node_modules / read-pkg / index.js View on Github external
module.exports = (fp, opts) => {
	if (typeof fp !== 'string') {
		opts = fp;
		fp = '.';
	}

	opts = opts || {};

	return pathType.dir(fp)
		.then(isDir => {
			if (isDir) {
				fp = path.join(fp, 'package.json');
			}

			return loadJsonFile(fp);
		})
		.then(x => {
			if (opts.normalize !== false) {
				require('normalize-package-data')(x);
			}

			return x;
		});
};
github zeit / serve / lib / listening.js View on Github external
) {
	const details = server.address();
	const {isTTY} = process.stdout;

	const shutdown = () => {
		server.close();
		process.exit(0);
	};

	process.on('SIGINT', shutdown);
	process.on('SIGTERM', shutdown);

	let isDir;

	try {
		isDir = yield pathType.dir(current);
	} catch (err) {
		isDir = false;
	}

	if (!isDir) {
		const base = basename(current);

		console.error(
			chalk.red(`Specified directory ${chalk.bold(`"${base}"`)} doesn't exist!`)
		);

		process.exit(1);
	}

	if (process.env.NODE_ENV !== 'production') {
		let message = chalk.green('Serving!');
github zeit / serve / lib / render.js View on Github external
}

	try {
		files = yield fs.readdir(dir);
	} catch (err) {
		throw err;
	}

	for (const file of files) {
		const filePath = path.resolve(dir, file);
		const index = files.indexOf(file);
		const details = path.parse(filePath);

		details.relative = path.join(subPath, details.base);

		if (yield pathType.dir(filePath)) {
			details.base += '/';
		} else {
			details.ext = details.ext.split('.')[1] || 'txt';

			let fileStats;

			try {
				fileStats = yield fs.stat(filePath);
			} catch (err) {
				throw err;
			}

			details.size = filesize(fileStats.size, {round: 0});
		}

		details.title = details.base;
github xiaoqiang-zhao / cellar / web / articles / gulp / demo / node_modules / gulp-amd-optimizer / node_modules / gulp-util / node_modules / dateformat / node_modules / meow / node_modules / read-pkg-up / node_modules / read-pkg / index.js View on Github external
module.exports = function (fp, opts) {
	if (typeof fp !== 'string') {
		opts = fp;
		fp = '.';
	}

	opts = opts || {};

	return pathType.dir(fp)
		.then(function (isDir) {
			if (isDir) {
				fp = path.join(fp, 'package.json');
			}

			return loadJsonFile(fp);
		})
		.then(function (x) {
			if (opts.normalize !== false) {
				normalizePackageData(x);
			}

			return x;
		});
};
github sx1989827 / DOClever / Desktop / node_modules / webpack / node_modules / read-pkg / index.js View on Github external
module.exports = (fp, opts) => {
	if (typeof fp !== 'string') {
		opts = fp;
		fp = '.';
	}

	opts = opts || {};

	return pathType.dir(fp)
		.then(isDir => {
			if (isDir) {
				fp = path.join(fp, 'package.json');
			}

			return loadJsonFile(fp);
		})
		.then(x => {
			if (opts.normalize !== false) {
				require('normalize-package-data')(x);
			}

			return x;
		});
};
github hongmaoxiao / now / node_modules / read-pkg / index.js View on Github external
module.exports = function (fp, opts) {
	if (typeof fp !== 'string') {
		opts = fp;
		fp = '.';
	}

	opts = opts || {};

	return pathType.dir(fp)
		.then(function (isDir) {
			if (isDir) {
				fp = path.join(fp, 'package.json');
			}

			return loadJsonFile(fp);
		})
		.then(function (x) {
			if (opts.normalize !== false) {
				normalizePackageData(x);
			}

			return x;
		});
};
github GoogleContainerTools / kpt / docsy / node_modules / dir-glob / index.js View on Github external
	return Promise.all(arrify(input).map(x => pathType.dir(getPath(x))
		.then(isDir => isDir ? getGlob(x, opts) : x)))
		.then(globs => [].concat.apply([], globs));
github flaviuse / mern-authentication / client / node_modules / dir-glob / index.js View on Github external
	return Promise.all(arrify(input).map(x => pathType.dir(getPath(x))
		.then(isDir => isDir ? getGlob(x, opts) : x)))
		.then(globs => [].concat.apply([], globs));

path-type

Check if a path is a file, directory, or symlink

MIT
Latest version published 3 years ago

Package Health Score

70 / 100
Full package analysis