How to use slash - 10 common examples

To help you get started, we’ve selected a few slash 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 skovy / typed-scss-modules / lib / main.ts View on Github external
export const main = async (pattern: string, options: MainOptions) => {
  // When the provided pattern is a directory construct the proper glob to find
  // all .scss files within that directory. Also, add the directory to the
  // included paths so any imported with a path relative to the root of the
  // project still works as expected without adding many include paths.
  if (fs.existsSync(pattern) && fs.lstatSync(pattern).isDirectory()) {
    if (Array.isArray(options.includePaths)) {
      options.includePaths.push(pattern);
    } else {
      options.includePaths = [pattern];
    }

    // When the pattern provide is a directory, assume all .scss files within.
    pattern = slash(path.resolve(pattern, "**/*.scss"));
  }

  if (options.listDifferent) {
    listDifferent(pattern, options);
    return;
  }

  if (options.watch) {
    watch(pattern, options);
  } else {
    await generate(pattern, options);
  }
};
github babel / babel / packages / babel-cli / src / babel / dir.js View on Github external
if (!util.isCompilableExtension(relative, cliOptions.extensions)) {
      return false;
    }

    // remove extension and then append back on .js
    relative = util.adjustRelative(relative, cliOptions.keepFileExtension);

    const dest = getDest(relative, base);

    try {
      const res = await util.compile(
        src,
        defaults(
          {
            sourceFileName: slash(path.relative(dest + "/..", src)),
          },
          babelOptions,
        ),
      );

      if (!res) return false;

      // we've requested explicit sourcemaps to be written to disk
      if (
        res.map &&
        babelOptions.sourceMaps &&
        babelOptions.sourceMaps !== "inline"
      ) {
        const mapLoc = dest + ".map";
        res.code = util.addSourceMappingUrl(res.code, mapLoc);
        res.map.file = path.basename(relative);
github bitrix-tools / cli / src / utils / is-allowed.js View on Github external
export default function isAllowed(fileName) {
	if (typeof fileName !== 'string') {
		return false;
	}

	const normalizedFileName = slash(fileName);

	if (
		(new RegExp('/components/(.*)/style.js')).test(normalizedFileName)
		|| (
			(new RegExp('/components/(.*)/style.css')).test(normalizedFileName)
			&& !(new RegExp('/components/(.*)/src/(.*)style.css')).test(normalizedFileName)
		)
	) {
		return false;
	}

	const ext = path.extname(normalizedFileName);

	switch (ext) {
		case '.js':
		case '.jsx':
github bitrix-tools / cli / src / utils / build-extension-name.js View on Github external
const moduleRes = `${slash(filePath)}`.match(moduleExp);

	if (Array.isArray(moduleRes)) {
		const fragments = `${slash(context)}`.split(`${moduleRes[1]}/install/js/${moduleRes[2]}/`);
		return `${moduleRes[2]}.${fragments[fragments.length - 1].replace(/\/$/, '').split('/').join('.')}`;
	}

	const localExp = new RegExp('/local/js/(.[a-z0-9_-]+)/(.[a-z0-9_-]+)/');
	const localRes = `${slash(filePath)}`.match(localExp);

	if (!Array.isArray(localRes))
	{
		return path.basename(context);
	}

	const fragments = `${slash(context)}`.split(`/local/js/${localRes[1]}/`);
	return `${localRes[1]}.${fragments[fragments.length - 1].replace(/\/$/, '').split('/').join('.')}`;
}
github bitrix-tools / cli / src / utils / build-component-name.js View on Github external
export default function buildComponentName(filePath) {
	const normalizedPath = `${slash(filePath)}`;
	const regExp = new RegExp('/(.[a-z0-9]+)/install/components/(.[a-z0-9]+)/');
	const res = normalizedPath.match(regExp);

	if (res)
	{
		return `${res[2]}:${normalizedPath.split(res[0])[1].split('/')[0]}`;
	}

	const localExp = new RegExp('/local/components/(.[a-z0-9]+)/');
	const localRes = normalizedPath.match(localExp);

	return `${localRes[1]}:${normalizedPath.split(localRes[0])[1].split('/')[0]}`;
}
github bitrix-tools / cli / src / path / parse-site-template-path.js View on Github external
export default function parseSiteTemplatePath(sourcePath: string = ''): ?Result {
	const preparedPath = slash(sourcePath);
	const installTemplatesExp = new RegExp('/(.[a-z0-9_-]+)/modules/.[a-z0-9_-]+/install/templates/(.[a-z0-9_-]+)/');
	const productTemplatesExp = new RegExp('/(local|bitrix)/templates/((.[a-z0-9-_]+))/');
	const templateResult = (
		preparedPath.match(installTemplatesExp)
		|| preparedPath.match(productTemplatesExp)
	);

	if (
		!!templateResult
		&& !!templateResult[1]
		&& !!templateResult[2]
	) {
		const [templatePath, rootDirname, template] = templateResult;
		const root = ['bitrix', 'local'].includes(rootDirname) ? rootDirname : 'bitrix';
		const [, filePath] = preparedPath.split(path.join(templatePath));
github adonisjs / assembler / src / Compiler / index.ts View on Github external
  private getRelativeUnixPath = mem((absPath: string) => slash(relative(this.appRoot, absPath)))
github ecomfe / veui / packages / veui-loader / src / index.js View on Github external
(
      acc,
      {
        package: pack,
        path: packPath = COMPONENTS_DIRNAME,
        transform,
        fileName
      }
    ) => {
      let peerComponent = getPeerFilename(component, {
        transform,
        template: fileName
      })
      let peerPath = slash(path.join(pack, packPath, peerComponent))
      pushPart(acc, { path: peerPath })
      return acc
    },
    {
github bitrix-tools / cli / src / utils / generate-config-php.js View on Github external
function generateConfigPhp(config) {
	if (!!config && typeof config !== 'object') {
		throw new Error('Invalid config');
	}

	const templatePath = path.resolve(appRoot, 'src/templates/config.php');
	const template = fs.readFileSync(templatePath, 'utf-8');
	const outputPath = path.resolve(slash(config.context), slash(config.output.js));


	const data = {
		cssPath: slash(path.relative(slash(config.context), buildConfigBundlePath(outputPath, 'css'))),
		jsPath: slash(path.relative(slash(config.context), buildConfigBundlePath(outputPath, 'js'))),
		rel: renderRel(config.rel),
	};

	return mustache.render(template, data);
}
github guigrpa / mady / src / server / db.js View on Github external
const onFileChange = async (eventType, filePath0) => {
  const filePath = slash(filePath0);
  if (eventType === 'unlink') {
    onSrcFileDeleted(filePath, { save: true });
  } else if (eventType === 'add') {
    onSrcFileAdded(filePath, { save: true });
  } else if (eventType === 'change') {
    await onSrcFileDeleted(filePath, { save: false });
    onSrcFileAdded(filePath, { save: true, forceSave: true });
  }
};

slash

Convert Windows backslash paths to slash paths

MIT
Latest version published 1 year ago

Package Health Score

70 / 100
Full package analysis

Popular slash functions