10 examples of 'typescript filename extensions' in JavaScript

Every line of 'typescript filename extensions' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your JavaScript code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
this disclaimer
64function ensureExtension(filename, ext) {
65 return (filename.lastIndexOf('.') == -1) ? `${filename}.${ext}` : filename
66}
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

51function getExtension (fileName: string): string {
52 const extension = fileName.split('.');
53 if (extension.length === 1) {
54 return fileName;
55 }
56
57 return '.' + extension.pop();
58}
71private replaceExtension(fileName: string, oldExtension: string, newExtension: string): string {
72 const baseName = fileName.substr(0, fileName.length - oldExtension.length);
73 return baseName + newExtension;
74}
45function getExtension(fileName) {
46 const ext = fileName ? fileName.split('.').pop() : undefined;
47 return ext ? ext.toLowerCase() : undefined;
48}
79function getFilenameNoExt(filename) {
80 if (!filenameNoExtCache) {
81 assertFilenameRequired(filename);
82 filenameNoExtCache = removeExtensions(filename);
83 }
84 return filenameNoExtCache;
85}
263function getFilenameExtension(fileName) {
264 var extension = '';
265 if(fileName.indexOf('.') !== -1) {
266 extension = last(fileName.split('.'));
267 }
268 return extension;
269}
110function getExtension(fileName) {
111 var components = fileName.split('.');
112 return components[components.length-1];
113}
186export function getFileExtension(fileName: string) {
187 return path.extname(fileName);
188}
189function getFileExtension(filename) {
190 return (/[.]/.exec(filename)) ? /[^.]+$/.exec(filename)[0] : undefined;
191}
258function normalizeName (fileName, ext) {
259 if(fileName.endsWith('.json')){
260 return fileName;
261 }
262 var extension = ext || '.js';
263 if (fileName.endsWith(extension)) {
264 return fileName;
265 }
266 return fileName + extension;
267}

Related snippets