From b479a413c94a8d11af7bed9f95a2f1c3029600e8 Mon Sep 17 00:00:00 2001 From: jmjuanes Date: Wed, 30 Dec 2015 11:57:38 +0100 Subject: [PATCH] Upload script --- index.js | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 index.js diff --git a/index.js b/index.js new file mode 100644 index 0000000..255c79e --- /dev/null +++ b/index.js @@ -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;