Last active
August 29, 2015 14:18
-
-
Save ninjasort/a14184b136ca2374ef83 to your computer and use it in GitHub Desktop.
utils
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Parses query string and returns object | |
* @param {string} string ?a=b&c=d | |
* @return {object} {a: b, c: d} | |
*/ | |
function parseQueryString(string) { | |
var obj = {}; | |
var keyValues = string.slice(string.indexOf('?') + 1).split('&'); | |
for(var i = 0; i < keyValues.length; i++) { | |
var parts = keyValues[i].split('='); | |
obj[parts[0]] = parts[1]; | |
} | |
return obj; | |
} | |
/** | |
* Selects files based on a regex against desired name searches | |
* @param {array} files array | |
* @param {array} search array (filenames) ['index', 'all'] | |
* @return {array} selection array | |
*/ | |
function selectFiles(files, searches) { | |
var hasFiles = new RegExp('(' + searches.join('|') + ')$', 'gi'); | |
return files.filter(function (file) { | |
return !(hasFiles.test( file )); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment