How to use the path-type.isDirectorySync 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 sindresorhus / make-dir / test / helpers / util.js View on Github external
export const assertDirectory = (t, directory, mode = 0o777 & (~process.umask())) => {
	// Setting `mode` on `fs.mkdir` on Windows doesn't seem to work
	if (process.platform === 'win32') {
		mode = 0o666;
	}

	t.true(pathType.isDirectorySync(directory));
	t.is(fs.statSync(directory).mode & 0o777, mode);
};
github danielcardoso / html-pages / lib / server.js View on Github external
} else if (!relatedExists) { // If not exists return an error 404
    return httpRequest.micro({
      req,
      res,
      code: 404
    });
  }

  const streamOptions = {};

  if (flags.cache) {
    streamOptions.maxAge = flags.cache;
  }

  // Check if directory
  if (pathType.isDirectorySync(related)) {
    const url = parse(req.url);

    // If the url doesn't end with a slash, add it and redirect the page
    if (url.pathname.substr(-1) !== '/') {
      url.pathname += '/';
      const newPath = format(url);

      httpRequest.logRequests({
        req,
        res,
        code: 301
      }, 301);

      res.writeHead(301, {
        Location: newPath
      });
github danielcardoso / html-pages / lib / listening.js View on Github external
server.close();
    global.utils.logger.log(chalk.red(pkg.name + ' stopped.'));
    process.exit(0);
  };

  process.on('SIGINT', () => {
    stopServer();
  });
  process.on('kill', () => {
    stopServer();
  });

  let isDir;

  try {
    isDir = pathType.isDirectorySync(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);
  }

  let message = '\n' + chalk.blue(pkg.title + ' is Online!') + ' 🚀';
  let notificationTxt = 'The server is running.';
github danielcardoso / html-pages / lib / render.js View on Github external
if (!fs.existsSync(dir)) {
      return false;
    }

    filesRaw = yield fs.readdir(dir);

    let files = [];

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

      details.title = details.base;
      details.stats = {};

      if (pathType.isDirectorySync(filePath)) {
        details.base += '/';
        details.type = 'dir';
        details.stats.size = '—';
      } else {
        details.ext = details.ext.split('.')[1] || '';
        details.type = 'file';
      }

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

      if (fu.isNotIgnoredPath(details.relative)) {
        const fileStats = yield fs.stat(filePath);

        if (!_.isString(details.stats.size)) {
          details.stats.sizeRaw = fileStats.size;
          details.stats.size = filesize(fileStats.size, {
github davidtheclark / cosmiconfig / src / getDirectory.ts View on Github external
function getDirectorySync(filepath: string): string {
  const filePathIsDirectory = isDirectorySync(filepath);

  if (filePathIsDirectory === true) {
    return filepath;
  }

  const directory = path.dirname(filepath);

  return directory;
}
github kevva / dir-glob / index.js View on Github external
	const globs = [].concat(input).map(x => pathType.isDirectorySync(getPath(x, options.cwd)) ? getGlob(x, options) : x);

path-type

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

MIT
Latest version published 4 months ago

Package Health Score

77 / 100
Full package analysis