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


TypeScript path.extname函數代碼示例

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


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

示例1: getResourceTypeFromUrl

/**
 * Get the default resource type for a file based on its extension.
 */
function getResourceTypeFromUrl(url: string): ResourceType|undefined {
  return extensionToTypeMapping.get(path.extname(url));
}
開發者ID:MehdiRaash,項目名稱:tools,代碼行數:6,代碼來源:push-manifest.ts

示例2: DataSource

var settingsLocation: SettingsLocation = null;
if (serverSettingsFilePath) {
  settingsLocation = {
    location: 'local',
    readOnly: false, // ToDo: this should be true
    uri: serverSettingsFilePath
  };
} else {
  var initAppSettings = AppSettings.BLANK;

  // If a file is specified add it as a dataSource
  var fileToLoad = parsedArgs['file'];
  if (fileToLoad) {
    initAppSettings = initAppSettings.addDataSource(new DataSource({
      name: path.basename(fileToLoad, path.extname(fileToLoad)),
      engine: 'native',
      source: fileToLoad
    }));
  }

  for (var clusterType of CLUSTER_TYPES) {
    var host = parsedArgs[clusterType];
    if (host) {
      initAppSettings = initAppSettings.addCluster(new Cluster({
        name: clusterType,
        type: clusterType,
        host: host,
        sourceListScan: 'auto',
        sourceListRefreshInterval: 15000,
開發者ID:baeeq,項目名稱:pivot,代碼行數:29,代碼來源:config.ts

示例3: setPath

 public setPath(filePath: string)
 {
     super.path = filePath;
     super.name = path.basename(filePath, path.extname(filePath));
 }
開發者ID:legatoproject,項目名稱:legato-af,代碼行數:5,代碼來源:annotatedModel.ts

示例4: processFile

		matches.forEach(file => {
			let resolvedFile = path.resolve(file);
			let contents: string = fs.readFileSync(resolvedFile, 'utf8');
			
			let sourceMapFile: string = null;
			let resolvedSourceMapFile: string = null;
			let sourceMapContent: string = undefined;
			
			let sourceMapMatches = contents.match(/\/\/#\s+sourceMappingURL=(.*)(?:\r?\n|\n|$)/);
			if (sourceMapMatches && sourceMapMatches.length === 2) {
				let sourceMapUrl = url.parse(sourceMapMatches[1]);
				// For now we only support relative pathes
				if (sourceMapUrl.protocol || sourceMapUrl.host) {
					console.error(`${file}: protocol or host based source map URLs are not supported.`);
					hasError = true;
				}
				let pathname = sourceMapUrl.pathname;
				if (path.isAbsolute(pathname)) {
					resolvedSourceMapFile = pathname;
				} else {
					sourceMapFile = pathname;
					resolvedSourceMapFile = path.join(path.dirname(file), sourceMapFile);
				}
				if (fs.existsSync(resolvedSourceMapFile)) {
					sourceMapContent = fs.readFileSync(resolvedSourceMapFile, 'utf8');
				}
			}
			let result = processFile(contents, sourceMapContent);
			if (result.errors && result.errors.length > 0) {
				result.errors.forEach(error => console.error(`${file}${error}`));
				hasError = true;
			} else {
				let outFile = resolvedFile;
				let sourceMapOutFile = resolvedSourceMapFile;
				if (outDir) {
					if (rootDir && resolvedFile.substring(0, rootDir.length) === rootDir) {
						outFile = path.join(outDir, resolvedFile.substring(rootDir.length));
					} else {
						outFile = path.join(outDir, file);
					}
					if (sourceMapFile) {
						sourceMapOutFile = path.join(outDir, sourceMapFile);
					}
				}
				if (result.contents) {
					let dirname = path.dirname(outFile);
					if (!fs.existsSync(dirname)) {
						fs.mkdirSync(path.dirname(outFile));
					}
					fs.writeFileSync(outFile, result.contents, { encoding: 'utf8' });
				}
				if (sourceMapOutFile && result.sourceMap) {
					fs.writeFileSync(sourceMapOutFile, result.sourceMap, { encoding: 'utf8' });
				}
				if (result.bundle) {
					let extension = path.extname(outFile);
					let bundlefile = outFile.substr(0, outFile.length - extension.length) + '.nls.json';
					fs.writeFileSync(bundlefile, JSON.stringify(result.bundle, null, 4), { encoding: 'utf8' });
				}
			}
		});
開發者ID:bjacobs3,項目名稱:vscode-nls-dev,代碼行數:61,代碼來源:vscl.ts

示例5: pasteAndShowMessage

 let disposable = vscode.commands.registerCommand('copy-file-name.copyFileName', () => {
     var fullPath = vscode.window.activeTextEditor.document.fileName;
     var extName = path.extname(fullPath);
     var fileName = path.basename(fullPath, extName);
     pasteAndShowMessage(fileName);
 });
開發者ID:nemesv,項目名稱:vscode-copy-file-name,代碼行數:6,代碼來源:extension.ts

示例6: return

 let filesInDir: String[] = fs.readdirSync(dir).filter((value: string, index: number, array: string[]) =>
 {
     return (path.extname(value).match(extRegex) != undefined);
 });
開發者ID:Tyriar,項目名稱:header-source-switch,代碼行數:4,代碼來源:extension.ts

示例7: constructor

 constructor(path: string) {
   this.path = resolve(path);
   this.relativePath = relative(REPO_ROOT, this.path);
   this.ext = extname(this.path);
 }
開發者ID:Jaaess,項目名稱:kibana,代碼行數:5,代碼來源:file.ts

示例8:

 return needles.some(function (needle) {
     return !_.includes(haystack, path.extname(needle).replace(".", ""));
 });
開發者ID:BrowserSync,項目名稱:browser-sync,代碼行數:3,代碼來源:utils.ts

示例9: convertFileToPackage

    lines.forEach(line => {
        let x = lines;
        let y = x;

        if (line.startsWith('nose.selector: DEBUG: wantModule <module \'')) {
            fileName = line.substring(line.indexOf('\' from \'') + '\' from \''.length);
            fileName = fileName.substring(0, fileName.lastIndexOf('\''));
            moduleName = line.substring(line.indexOf('nose.selector: DEBUG: wantModule <module \'') + 'nose.selector: DEBUG: wantModule <module \''.length);
            moduleName = moduleName.substring(0, moduleName.indexOf('\''));

            // We need to display the path relative to the current directory
            fileName = fileName.substring(rootDirectory.length + 1);
            // we don't care about the compiled file
            if (path.extname(fileName) === '.pyc') {
                fileName = fileName.substring(0, fileName.length - 1);
            }
            currentPackage = convertFileToPackage(fileName);
            const fullyQualifiedName = path.isAbsolute(fileName) ? fileName : path.resolve(rootDirectory, fileName)
            testFile = {
                functions: [], suites: [], name: fileName, nameToRun: fileName,
                xmlName: currentPackage, time: 0, functionsFailed: 0, functionsPassed: 0,
                fullPath: fullyQualifiedName
            };
            testFiles.push(testFile);
            return;
        }

        if (line.startsWith('nose.selector: DEBUG: wantClass <class \'')) {
            let name = extractBetweenDelimiters(line, 'nose.selector: DEBUG: wantClass <class \'', '\'>? True');
            const testSuite: TestSuite = {
                name: path.extname(name).substring(1), nameToRun: fileName + `:${name}`,
                functions: [], suites: [], xmlName: name, time: 0, isUnitTest: false,
                isInstance: false, functionsFailed: 0, functionsPassed: 0
            };
            testFile.suites.push(testSuite);
            return;
        }
        if (line.startsWith('nose.selector: DEBUG: wantClass ')) {
            let name = extractBetweenDelimiters(line, 'nose.selector: DEBUG: wantClass ', '? True');
            const testSuite: TestSuite = {
                name: path.extname(name).substring(1), nameToRun: `${fileName}:.${name}`,
                functions: [], suites: [], xmlName: name, time: 0, isUnitTest: false,
                isInstance: false, functionsFailed: 0, functionsPassed: 0
            };
            testFile.suites.push(testSuite);
            return;
        }
        if (line.startsWith('nose.selector: DEBUG: wantMethod <unbound method ')) {
            const name = extractBetweenDelimiters(line, 'nose.selector: DEBUG: wantMethod <unbound method ', '>? True');
            const fnName = path.extname(name).substring(1);
            const clsName = path.basename(name, path.extname(name));
            const fn: TestFunction = {
                name: fnName, nameToRun: `${fileName}:${clsName}.${fnName}`,
                time: 0, functionsFailed: 0, functionsPassed: 0
            };

            let cls = testFile.suites.find(suite => suite.name === clsName);
            if (!cls) {
                debugger;
            }
            cls.functions.push(fn);
            return;
        }
        if (line.startsWith('nose.selector: DEBUG: wantFunction <function ')) {
            const name = extractBetweenDelimiters(line, 'nose.selector: DEBUG: wantFunction <function ', ' at ');
            const fn: TestFunction = {
                name: name, nameToRun: `${fileName}:${name}`,
                time: 0, functionsFailed: 0, functionsPassed: 0
            };
            if (!testFile) {
                debugger;
            }
            testFile.functions.push(fn);
            return;
        }
    });
開發者ID:Tyriar,項目名稱:pythonVSCode,代碼行數:76,代碼來源:collector.ts

示例10: addVideo

async function addVideo (req: express.Request, res: express.Response) {
  const videoPhysicalFile = req.files['videofile'][0]
  const videoInfo: VideoCreate = req.body

  // Prepare data so we don't block the transaction
  const videoData = {
    name: videoInfo.name,
    remote: false,
    extname: extname(videoPhysicalFile.filename),
    category: videoInfo.category,
    licence: videoInfo.licence,
    language: videoInfo.language,
    commentsEnabled: videoInfo.commentsEnabled || false,
    waitTranscoding: videoInfo.waitTranscoding || false,
    state: CONFIG.TRANSCODING.ENABLED ? VideoState.TO_TRANSCODE : VideoState.PUBLISHED,
    nsfw: videoInfo.nsfw || false,
    description: videoInfo.description,
    support: videoInfo.support,
    privacy: videoInfo.privacy,
    duration: videoPhysicalFile['duration'], // duration was added by a previous middleware
    channelId: res.locals.videoChannel.id
  }
  const video = new VideoModel(videoData)
  video.url = getVideoActivityPubUrl(video) // We use the UUID, so set the URL after building the object

  // Build the file object
  const { videoFileResolution } = await getVideoFileResolution(videoPhysicalFile.path)
  const videoFileData = {
    extname: extname(videoPhysicalFile.filename),
    resolution: videoFileResolution,
    size: videoPhysicalFile.size
  }
  const videoFile = new VideoFileModel(videoFileData)

  // Move physical file
  const videoDir = CONFIG.STORAGE.VIDEOS_DIR
  const destination = join(videoDir, video.getVideoFilename(videoFile))
  await renamePromise(videoPhysicalFile.path, destination)
  // This is important in case if there is another attempt in the retry process
  videoPhysicalFile.filename = video.getVideoFilename(videoFile)
  videoPhysicalFile.path = destination

  // Process thumbnail or create it from the video
  const thumbnailField = req.files['thumbnailfile']
  if (thumbnailField) {
    const thumbnailPhysicalFile = thumbnailField[0]
    await processImage(thumbnailPhysicalFile, join(CONFIG.STORAGE.THUMBNAILS_DIR, video.getThumbnailName()), THUMBNAILS_SIZE)
  } else {
    await video.createThumbnail(videoFile)
  }

  // Process preview or create it from the video
  const previewField = req.files['previewfile']
  if (previewField) {
    const previewPhysicalFile = previewField[0]
    await processImage(previewPhysicalFile, join(CONFIG.STORAGE.PREVIEWS_DIR, video.getPreviewName()), PREVIEWS_SIZE)
  } else {
    await video.createPreview(videoFile)
  }

  // Create the torrent file
  await video.createTorrentAndSetInfoHash(videoFile)

  const videoCreated = await sequelizeTypescript.transaction(async t => {
    const sequelizeOptions = { transaction: t }

    const videoCreated = await video.save(sequelizeOptions)
    // Do not forget to add video channel information to the created video
    videoCreated.VideoChannel = res.locals.videoChannel

    videoFile.videoId = video.id
    await videoFile.save(sequelizeOptions)

    video.VideoFiles = [ videoFile ]

    // Create tags
    if (videoInfo.tags !== undefined) {
      const tagInstances = await TagModel.findOrCreateTags(videoInfo.tags, t)

      await video.$set('Tags', tagInstances, sequelizeOptions)
      video.Tags = tagInstances
    }

    // Schedule an update in the future?
    if (videoInfo.scheduleUpdate) {
      await ScheduleVideoUpdateModel.create({
        videoId: video.id,
        updateAt: videoInfo.scheduleUpdate.updateAt,
        privacy: videoInfo.scheduleUpdate.privacy || null
      }, { transaction: t })
    }

    await federateVideoIfNeeded(video, true, t)

    logger.info('Video with name %s and uuid %s created.', videoInfo.name, videoCreated.uuid)

    return videoCreated
  })

  if (video.state === VideoState.TO_TRANSCODE) {
//.........這裏部分代碼省略.........
開發者ID:jiang263,項目名稱:PeerTube,代碼行數:101,代碼來源:index.ts


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