Angular service to get simple methods to manipulate url parts
Demo: http://yllieth.github.io/angular-url-parser/app/index.html
Rails gem: https://github.com/yllieth/angular_url_parser_rails
bower install yllieth/angular-url-parser --save
Once the lib is downloaded, add a reference in your index.html
<script type="application/javascript" src="../bower_components/angular-url-parser/angular-url-parser.js"></script>
In your Gemfile, add the following line:
gem'angular_url_parser_rails'In your application.js, add the following line:
//= require angular-url-parser
angular.module('YOUR-ANGULAR-APP-NAME',['ngUrlParser']).controller('demoCtrl',function(urlParser){this.parts=urlParser.parse();this.protocol=urlParser.getProtocol();this.host=urlParser.getHost();this.hostname=urlParser.getHostname();this.port=urlParser.getPort();this.route=urlParser.getRoute();this.routeAttributes=urlParser.getRouteAttributes();this.queryString=urlParser.getQuerystring();this.option=urlParser.getOption();this.hash=urlParser.getHash();})getProtocol([string] url): string: Return the protocol of the given url - Example: "http:", "https:", ...getHost([string] url): string: Return the host of the given url (without port) - Example: "github.com", "localhost", ...getHostname([string] url): string: Return the hostname of the given url (with port) - Example: "github.com", "localhost:3000", ...getPort([string] url): string: Return the port of the given url - Example: "", "3000", ...getRoute([string] url): string: Return the main parts of the given urlgetRouteAttributes([string] url): array: Return the list of parts of the given urlgetQuerystring([string] url): string: Return the part of the given url with optionsgetOption([string] param, [string] url): object|string: Return a specific option in the url's options, or all options in an objectgetHash([string] url): string: Return the hash of the given urlparse([string] url): object: Return parsed url in an object:// urlParser.parse('http://localhost:3000/models?sort=asc#quantiles') { "protocol": "http:", "host": "localhost:3000", "hostname": "localhost", "port": "3000", "pathname": "/models", "search": "?sort=asc", "searchObject": { "sort": "asc" }, "hash": "quantiles" }
- Fork it
- Create your feature branch (
git checkout -b my-new-feature) - Commit your changes (
git commit -am 'Add some feature') - Push to the branch (
git push origin my-new-feature) - Create new Pull Request