Skip to content

Commit

Permalink
Upload script
Browse files Browse the repository at this point in the history
  • Loading branch information
jmjuanes committed Dec 30, 2015
1 parent 76ba5f0 commit b479a41
Showing 1 changed file with 61 additions and 0 deletions.
61 changes: 61 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,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;

0 comments on commit b479a41

Please sign in to comment.