-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
61 lines (47 loc) · 1.18 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
//Import dependencies
var path = require('path');
//Get the ext name sync
function Get(url)
{
//Initialize the output
var out = {"path": "", "file": "", "ext": "", "query": {}, "hashtag": ""};
//Save the file path
out.path = url;
//Find if exists a ? or #
var p1 = out.path.indexOf('?');
var p2 = out.path.indexOf('#');
//Check for hashtag
if(p2 != -1)
{
//Get the hashtag value
out.hashtag = out.path.substring(p2 + 1);
//Reset the file path
out.path = out.path.substring(0, p2);
}
//Check for query
if(p1 != -1)
{
//Get the query value
var query = out.path.substring(p1 + 1);
//Split the query value
query = query.split('&');
//Insert into the output
for(var i = 0; i < query.length; i++)
{
//Get the item
var item = query[i].split('=');
//Save to the output
out.query[item[0]] = item[1];
}
//Reset the file path
out.path = out.path.substring(0, p1);
}
//Get the file name
out.file = out.path.substring(out.path.lastIndexOf('/') + 1);
//Get the extension
out.ext = path.extname(out.file).replace('.', '');
//Return
return out;
}
//Exports to node
module.exports = Get;