source: imaps-frontend/node_modules/rechoir/lib/extension.js@ 79a0317

main
Last change on this file since 79a0317 was 79a0317, checked in by stefan toskovski <stefantoska84@…>, 3 days ago

F4 Finalna Verzija

  • Property mode set to 100644
File size: 922 bytes
RevLine 
[79a0317]1'use strict';
2
3var path = require('path');
4
5function getLongExtension(basename) {
6 if (basename[basename.length - 1] === '.') {
7 return null;
8 }
9
10 var startIndex = basename[0] === '.' ? 1 : 0;
11
12 var dotIndex = basename.indexOf('.', startIndex);
13 if (dotIndex <= startIndex) {
14 return null;
15 }
16
17 return basename.slice(dotIndex);
18}
19
20function getPossibleExtensions(longExtension) {
21 var arr = [longExtension];
22 var len = longExtension.length;
23 var startIndex = 1;
24
25 while (startIndex < len) {
26 var dotIndex = longExtension.indexOf('.', startIndex);
27 if (dotIndex < 0) {
28 break;
29 }
30 arr.push(longExtension.slice(dotIndex));
31 startIndex = dotIndex + 1;
32 }
33
34 return arr;
35}
36
37module.exports = function (input) {
38 var basename = path.basename(input);
39 var longExtension = getLongExtension(basename);
40 if (!longExtension) {
41 return;
42 }
43 return getPossibleExtensions(longExtension);
44};
Note: See TracBrowser for help on using the repository browser.