UNPKG

angular-state-router

Version:

An AngularJS state-based router designed for flexibility and ease of use.

50 lines (40 loc) 1.11 kB
'use strict'; function Url(url) { url = url || ''; // Instance var _self = { /** * Get the path of a URL * * @return {String} A querystring from URL */ path: function() { return url.indexOf('?') === -1 ? url : url.substring(0, url.indexOf('?')); }, /** * Get the querystring of a URL * * @return {String} A querystring from URL */ querystring: function() { return url.indexOf('?') === -1 ? '' : url.substring(url.indexOf('?')+1); }, /** * Get the querystring of a URL parameters as a hash * * @return {String} A querystring from URL */ queryparams: function() { var pairs = _self.querystring().split('&'); var params = {}; for(var i=0; i<pairs.length; i++) { if(pairs[i] === '') continue; var nameValue = pairs[i].split('='); params[nameValue[0]] = (typeof nameValue[1] === 'undefined' || nameValue[1] === '') ? true : decodeURIComponent(nameValue[1]); } return params; } }; return _self; } module.exports = Url;