Skip to content

yllieth/angular_url_parser_rails

Repository files navigation

Angular URL parser

Angular service to get simple methods to manipulate url parts

Demo: http://yllieth.github.io/angular-url-parser/app/index.html

Installation

In your Gemfile, add the following line:

gem 'angular_url_parser_rails'

In your application.js, add the following line:

//= require angular-url-parser

Usage

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 url
  • getRouteAttributes([string] url): array : Return the list of parts of the given url
  • getQuerystring([string] url): string : Return the part of the given url with options
  • getOption([string] param, [string] url): object|string : Return a specific option in the url's options, or all options in an object
  • getHash([string] url): string : Return the hash of the given url
  • parse([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"
    }

Contributing

See https://github.com/yllieth/angular-url-parser

About

Rails gem for the angular-url-parser library

Resources

Stars

Watchers

Forks

Packages

No packages published