MCPcopy Index your code
hub / github.com/node-formidable/formidable / _getExtension

Method _getExtension

src/Formidable.js:571–596  ·  view source on GitHub ↗
(str)

Source from the content-addressed store, hash-verified

569 // "a.b.c" -> ".b.c"
570 // as opposed to path.extname -> ".c"
571 _getExtension(str) {
572 if (!str) {
573 return '';
574 }
575
576 const basename = path.basename(str);
577 const firstDot = basename.indexOf('.');
578 const lastDot = basename.lastIndexOf('.');
579 let rawExtname = path.extname(basename);
580
581 if (firstDot !== lastDot) {
582 rawExtname = basename.slice(firstDot);
583 }
584
585 let filtered;
586 const firstInvalidIndex = Array.from(rawExtname).findIndex(invalidExtensionChar);
587 if (firstInvalidIndex === -1) {
588 filtered = rawExtname;
589 } else {
590 filtered = rawExtname.substring(0, firstInvalidIndex);
591 }
592 if (filtered === '.') {
593 return '';
594 }
595 return filtered;
596 }
597
598 _joinDirectoryName(name) {
599 const newPath = path.join(this.uploadDir, name);

Callers 1

_setUpRenameMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected