angular-url-parser

WebJar for angular-url-parser

License

License

MIT
Categories

Categories

Angular User Interface Web Frameworks
GroupId

GroupId

org.webjars.bower
ArtifactId

ArtifactId

angular-url-parser
Last Version

Last Version

1.0.0
Release Date

Release Date

Type

Type

jar
Description

Description

angular-url-parser
WebJar for angular-url-parser
Project URL

Project URL

http://webjars.org
Source Code Management

Source Code Management

https://github.com/xemle/angular-url-parser

Download angular-url-parser

How to add to project

<!-- https://jarcasting.com/artifacts/org.webjars.bower/angular-url-parser/ -->
<dependency>
    <groupId>org.webjars.bower</groupId>
    <artifactId>angular-url-parser</artifactId>
    <version>1.0.0</version>
</dependency>
// https://jarcasting.com/artifacts/org.webjars.bower/angular-url-parser/
implementation 'org.webjars.bower:angular-url-parser:1.0.0'
// https://jarcasting.com/artifacts/org.webjars.bower/angular-url-parser/
implementation ("org.webjars.bower:angular-url-parser:1.0.0")
'org.webjars.bower:angular-url-parser:jar:1.0.0'
<dependency org="org.webjars.bower" name="angular-url-parser" rev="1.0.0">
  <artifact name="angular-url-parser" type="jar" />
</dependency>
@Grapes(
@Grab(group='org.webjars.bower', module='angular-url-parser', version='1.0.0')
)
libraryDependencies += "org.webjars.bower" % "angular-url-parser" % "1.0.0"
[org.webjars.bower/angular-url-parser "1.0.0"]

Dependencies

There are no dependencies for this project. It is a standalone project that does not depend on any other jars.

Project Modules

There are no modules declared in this project.

Angular filter parse an URL

This module provides an urlParser filter for Angular. It converts an URL string to an object with its components.

Installation

bower install --save angular-url-parser

Parser

The parser uses the URL parser of the anchor (<a>) DOM element based on the gist from jlong.

Following components are extracted:

  • protocol
  • username
  • password
  • hostname
  • port
  • host (hostname + port)
  • pathname
  • search
  • hash

Example

For given URL http://john:[email protected]:3000/users?page=2#user-4711 the urlParser filter extracts:

{
  protocol: 'http:',
  username: 'john',
  password: 's3cure',
  hostname: 'api.site.com',
  port: '3000',
  host: 'api.site.com:3000',
  pathname: '/users',
  search: '?page=2',
  hash: '#user-4711'
}

Following example shows a simple sitemap.xml fetch service from an URL:

angular.module('app', ['urlParser'])

  // Service to fetch the sitemap.xml of an web URL
  .factory('sitemapService', [
    '$http',
    'urlParserFilter',
    function ($http, urlParserFilter) {
      return {
        get: function(url) {
          var obj = urlParserFilter(url),
              sitemapUrl;

          sitemapUrl = obj.protocol + '//' + obj.host + '/sitemap.xml';

          return $http.get(sitemapUrl);
        }
      };
    }
  ]);

Test

Please install karma-cli and all dependencies via npm install and bower install. Then run

karma start

You might also set the CHROME_BIN environment variable.

Contribute

  • Fork github repository
  • Create a brunch
    • Fix a single bug
    • Write test
  • Send push request

Similar Projects

  • URL.js - JS library to parse and set URLs

Licence

MIT

Versions

Version
1.0.0