當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript path.parse函數代碼示例

本文整理匯總了TypeScript中path.parse函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript parse函數的具體用法?TypeScript parse怎麽用?TypeScript parse使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了parse函數的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: dynamicPathParser

export function dynamicPathParser(project: any, entityName: string, appConfig: any) {
  const projectRoot = project.root;
  const sourceDir = appConfig.root;
  const appRoot = path.join(sourceDir, 'app');
  const cwd = process.env.PWD;

  const rootPath = path.join(projectRoot, appRoot);
  let outputPath = path.join(rootPath, entityName);

  if (entityName.indexOf(path.sep) === 0) {
    outputPath = path.join(rootPath, entityName.substr(1));
  } else if (cwd.indexOf(rootPath) >= 0) {
    outputPath = path.join(cwd, entityName);
  }

  if (!fs.existsSync(outputPath)) {
    // Verify the path exists on disk.
    const parsedOutputPath = path.parse(outputPath);
    const parts = parsedOutputPath.dir.split(path.sep).slice(1);
    const newPath = parts.reduce((tempPath: string, part: string) => {
      // if (tempPath === '') {
      //   return part;
      // }

      const withoutPlus = path.join(tempPath, part);
      const withPlus = path.join(tempPath, '+' + part);
      if (fs.existsSync(withoutPlus)) {
        return withoutPlus;
      } else if (fs.existsSync(withPlus)) {
        return withPlus;
      }

      // Folder not found, create it, and return it
      const dasherizedPart = stringUtils.dasherize(part);
      const dasherizedDirName = path.join(tempPath, dasherizedPart);
      fs.mkdirpSync(dasherizedDirName);
      return dasherizedDirName;

    }, parsedOutputPath.root);
    outputPath = path.join(newPath, parsedOutputPath.name);
  }

  if (outputPath.indexOf(rootPath) < 0) {
    throw `Invalid path: "${entityName}" cannot be ` +
        `above the "${appRoot}" directory`;
  }

  const adjustedPath = outputPath.replace(projectRoot, '');

  const parsedPath = path.parse(adjustedPath);

  if (parsedPath.dir.indexOf(path.sep) === 0) {
    parsedPath.dir = parsedPath.dir.substr(1);
  }

  parsedPath.dir = parsedPath.dir === path.sep ? '' : parsedPath.dir;

  return { ...parsedPath, appRoot, sourceDir };
};
開發者ID:olyv,項目名稱:wortschatz,代碼行數:59,代碼來源:dynamic-path-parser.ts

示例2: switch

			this.watcher.on('change', (file: string) => {
				switch (path.parse(file).ext) {
					case '.glsl':
						log.info('Recompiling ' + path.parse(file).name);
						this.compileShader(file, options);
						break;
				}
			});
開發者ID:jefvel,項目名稱:khamake,代碼行數:8,代碼來源:ShaderCompiler.ts

示例3: nodeModulesPaths

export default function nodeModulesPaths(
  basedir: Config.Path,
  options: NodeModulesPathsOptions,
): Array<Config.Path> {
  const modules =
    options && options.moduleDirectory
      ? Array.from(options.moduleDirectory)
      : ['node_modules'];

  // ensure that `basedir` is an absolute path at this point,
  // resolving against the process' current working directory
  const basedirAbs = path.resolve(basedir);

  let prefix = '/';
  if (/^([A-Za-z]:)/.test(basedirAbs)) {
    prefix = '';
  } else if (/^\\\\/.test(basedirAbs)) {
    prefix = '\\\\';
  }

  // The node resolution algorithm (as implemented by NodeJS and TypeScript)
  // traverses parents of the physical path, not the symlinked path
  let physicalBasedir;
  try {
    physicalBasedir = realpath(basedirAbs);
  } catch (err) {
    // realpath can throw, e.g. on mapped drives
    physicalBasedir = basedirAbs;
  }

  const paths: Array<Config.Path> = [physicalBasedir];
  let parsed = path.parse(physicalBasedir);
  while (parsed.dir !== paths[paths.length - 1]) {
    paths.push(parsed.dir);
    parsed = path.parse(parsed.dir);
  }

  const dirs = paths
    .reduce(
      (dirs, aPath) =>
        dirs.concat(
          modules.map(moduleDir =>
            path.isAbsolute(moduleDir)
              ? aPath === basedirAbs
                ? moduleDir
                : ''
              : path.join(prefix, aPath, moduleDir),
          ),
        ),
      [] as Array<Config.Path>,
    )
    .filter(dir => dir !== '');

  return options.paths ? dirs.concat(options.paths) : dirs;
}
開發者ID:Volune,項目名稱:jest,代碼行數:55,代碼來源:nodeModulesPaths.ts

示例4: comparePngs

export async function comparePngs(
  sessionPath: string,
  baselinePath: string,
  diffPath: string,
  sessionDirectory: string,
  log: ToolingLog
) {
  log.debug(`comparePngs: ${sessionPath} vs ${baselinePath}`);
  const session = (await Jimp.read(sessionPath)).clone();
  const baseline = (await Jimp.read(baselinePath)).clone();

  if (
    session.bitmap.width !== baseline.bitmap.width ||
    session.bitmap.height !== baseline.bitmap.height
  ) {
    // eslint-disable-next-line no-console
    console.log(
      'expected height ' + baseline.bitmap.height + ' and width ' + baseline.bitmap.width
    );
    // eslint-disable-next-line no-console
    console.log('actual height ' + session.bitmap.height + ' and width ' + session.bitmap.width);

    const width = Math.min(session.bitmap.width, baseline.bitmap.width);
    const height = Math.min(session.bitmap.height, baseline.bitmap.height);
    session.resize(width, height); // , Jimp.HORIZONTAL_ALIGN_LEFT | Jimp.VERTICAL_ALIGN_TOP);
    baseline.resize(width, height); // , Jimp.HORIZONTAL_ALIGN_LEFT | Jimp.VERTICAL_ALIGN_TOP);
  }

  session.quality(60);
  baseline.quality(60);

  log.debug(`calculating diff pixels...`);
  // Note that this threshold value only affects color comparison from pixel to pixel. It won't have
  // any affect when comparing neighboring pixels - so slight shifts, font variations, or "blurry-ness"
  // will still show up as diffs, but upping this will not help that.  Instead we keep the threshold low, and expect
  // some the diffCount to be lower than our own threshold value.
  const THRESHOLD = 0.1;
  const { image, percent } = Jimp.diff(session, baseline, THRESHOLD);
  log.debug(`percent different: ${percent}`);
  if (percent > 0) {
    image.write(diffPath);

    // For debugging purposes it'll help to see the resized images and how they compare.
    session.write(join(sessionDirectory, `${parse(sessionPath).name}-session-resized.png`));
    baseline.write(join(sessionDirectory, `${parse(baselinePath).name}-baseline-resized.png`));
  }
  return percent;
}
開發者ID:elastic,項目名稱:kibana,代碼行數:48,代碼來源:compare_pngs.ts

示例5: compile

				async function compile(shader: any, index: number) {
					let parsed = path.parse(shader);
					log.info('Compiling shader ' + (index + 1) + ' of ' + shaders.length + ' (' + parsed.base + ').');
					let compiledShader: CompiledShader = null;
					try {
						compiledShader = await self.compileShader(shader, options, recompileAll);
					}
					catch (error) {
						log.error('Compiling shader ' + (index + 1) + ' of ' + shaders.length + ' (' + parsed.base + ') failed:');
						log.error(error);
						return Promise.reject(error);
					}
					if (compiledShader === null) {
						compiledShader = new CompiledShader();
						compiledShader.noembed = options.noembed;
						// mark variables as invalid, so they are loaded from previous compilation
						compiledShader.files = null;
						compiledShader.inputs = null;
						compiledShader.outputs = null;
						compiledShader.uniforms = null;
						compiledShader.types = null;
					}
					if (compiledShader.files != null && compiledShader.files.length === 0) {
						// TODO: Remove when krafix has been recompiled everywhere
						compiledShader.files.push(parsed.name + '.' + self.type);
					}
					compiledShader.name = AssetConverter.createExportInfo(parsed, false, options, self.exporter.options.from).name;
					compiledShaders.push(compiledShader);
					++index;
					return Promise.resolve();
				}
開發者ID:KTXSoftware,項目名稱:khamake,代碼行數:31,代碼來源:ShaderCompiler.ts

示例6: async

			this.watcher.on('ready', async () => {
				ready = true;
				let compiledShaders: CompiledShader[] = [];
				let index = 0;
				for (let shader of shaders) {
					let parsed = path.parse(shader);
					log.info('Compiling shader ' + (index + 1) + ' of ' + shaders.length + ' (' + parsed.base + ').');
					let compiledShader: CompiledShader = null;
					try {
						compiledShader = await this.compileShader(shader, options);
					}
					catch (error) {
						reject(error);
						return;
					}
					if (compiledShader === null) {
						compiledShader = new CompiledShader();
						// mark variables as invalid, so they are loaded from previous compilation
						compiledShader.inputs = null;
						compiledShader.outputs = null;
						compiledShader.uniforms = null;
					}
					if (compiledShader.files.length === 0) {
						// TODO: Remove when krafix has been recompiled everywhere
						compiledShader.files.push(parsed.name + '.' + this.type);
					}
					compiledShader.name = AssetConverter.createExportInfo(parsed, false, options, this.exporter.options.from).name;
					compiledShaders.push(compiledShader);
					++index;
				}
				resolve(compiledShaders);
				return;
			});
開發者ID:jefvel,項目名稱:khamake,代碼行數:33,代碼來源:ShaderCompiler.ts

示例7: copyGoldImagesToDatabase

export function copyGoldImagesToDatabase(name: string, resourceState: string, fileBucket: any) {
  // The name should always look like "goldens/xxx.png"
  let parsedPath = path.parse(name);
  // Get the file name.
  if (parsedPath.root != '' ||
    parsedPath.dir != 'goldens' ||
    parsedPath.ext.toLowerCase() != '.png') {
    return;
  }

  let filenameKey = path.basename(parsedPath.name, '.screenshot');
  let databaseRef = firebaseAdmin.database().ref(FIREBASE_DATA_GOLDENS).child(filenameKey);

  // When a gold image is deleted, also delete the corresponding record in the firebase database.
  if (resourceState === 'not_exists') {
    return databaseRef.set(null);
  }

  let tempFilePath = `/tmp/${parsedPath.base}`;
  let bucket = gcs.bucket(fileBucket);
  // Download file from bucket.
  return bucket.file(name).download({destination: tempFilePath})
    .then(() => {
      let data = readFileSync(tempFilePath);
      return databaseRef.set(data);
    }).catch((error: any) => console.error(`${filenameKey} ${error}`));
}
開發者ID:Chintuz,項目名稱:material2,代碼行數:27,代碼來源:image-data.ts

示例8: function

    return function (path: string) {
        const nmIndex = path.lastIndexOf('node_modules');

        if (nmIndex !== -1) {
            const subPath = path.substr(nmIndex + 'node_modules'.length).replace(/\\/g, '/');
            const shouldResolve = explicitResolve.length && explicitResolve.some(packageName => subPath.indexOf(packageName) !== -1);
            const pathParts = subPath.split(/[/\-_]/);

            if (!shouldResolve && pathParts.every(p => nsPackageFilters.every(f => f !== p))) {
                return path;
            }
        }

        const { dir, name, ext } = parse(path);

        if (platformSpecificExt.indexOf(ext) === -1) {
            return path;
        }

        for (const platform of platforms) {
            const platformFileName = `${name}.${platform}${ext}`;
            const platformPath = toSystemPath(join(dir, platformFileName));

            try {
                if (statSync(platformPath)) {
                    return platformPath;
                }
            } catch (_e) {
                // continue checking the other platforms
            }
        }

        return path;
    }
開發者ID:NativeScript,項目名稱:nativescript-dev-webpack,代碼行數:34,代碼來源:resolver.ts

示例9: trueCasePathSync

export function trueCasePathSync(fsPath: string): string {
	// Normalize the path so as to resolve . and .. components.
	// !! As of Node v4.1.1, a path starting with ../ is NOT resolved relative
	// !! to the current dir, and glob.sync() below then fails.
	// !! When in doubt, resolve with fs.realPathSync() *beforehand*.
	let fsPathNormalized = path.normalize(fsPath);

	// OSX: HFS+ stores filenames in NFD (decomposed normal form) Unicode format,
	// so we must ensure that the input path is in that format first.
	if (process.platform === "darwin")
		fsPathNormalized = fsPathNormalized.normalize("NFD");

	// !! Windows: Curiously, the drive component mustn't be part of a glob,
	// !! otherwise glob.sync() will invariably match nothing.
	// !! Thus, we remove the drive component and instead pass it in as the 'cwd'
	// !! (working dir.) property below.
	const pathRoot = path.parse(fsPathNormalized).root;
	const noDrivePath = fsPathNormalized.slice(Math.max(pathRoot.length - 1, 0));

	// Perform case-insensitive globbing (on Windows, relative to the drive /
	// network share) and return the 1st match, if any.
	// Fortunately, glob() with nocase case-corrects the input even if it is
	// a *literal* path.
	return glob.sync(noDrivePath, { nocase: true, cwd: pathRoot })[0];
}
開發者ID:DanTup,項目名稱:Dart-Code,代碼行數:25,代碼來源:utils.ts


注:本文中的path.parse函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。