本文整理匯總了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));
}
示例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,
示例3: setPath
public setPath(filePath: string)
{
super.path = filePath;
super.name = path.basename(filePath, path.extname(filePath));
}
示例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' });
}
}
});
示例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);
});
示例6: return
let filesInDir: String[] = fs.readdirSync(dir).filter((value: string, index: number, array: string[]) =>
{
return (path.extname(value).match(extRegex) != undefined);
});
示例7: constructor
constructor(path: string) {
this.path = resolve(path);
this.relativePath = relative(REPO_ROOT, this.path);
this.ext = extname(this.path);
}
示例8:
return needles.some(function (needle) {
return !_.includes(haystack, path.extname(needle).replace(".", ""));
});
示例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;
}
});
示例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) {
//.........這裏部分代碼省略.........