canonical_url 1.0.1

  • README.md
  • CHANGELOG.md
  • Example
  • Installing
  • Versions
  • 50

canonical_url

The UrlCanonicalizer is used for the process of converting an URL into a canonical (normalized) form. It will:

  • make scheme and host lowercase
  • remove port if it matches the default (80, 443)
  • canonicalize path (e.g. /a/../, /a/./)
  • sort query parameters (default)
  • use query parameter ordering (optional)
  • whitelist / blacklist parameters (optional)
  • remove fragment (optional)

It can also calculate the url relative to a context (e.g. base url + relative link).

Usage

A simple usage example:

import 'package:canonical_url/canonical_url.dart';

main() {
  final urlc = new UrlCanonicalizer(removeFragment: true);

  // prints http://example.com/b.txt
  print(urlc.canonicalize('http://example.com:80/a/../b.txt'));

  // prints https://example.com/abc
  print(urlc.canonicalize('https://example.com/abc#xyz'));

  // prints http://example.com/api?a=2&b=3&c=1
  print(urlc.canonicalize('http://example.com/api?c=1&a=2&b=3'));
}

Changelog

1.0.1

  • Handle URLs without hosts.

1.0.0

  • First public version.

example/example.dart

import 'package:canonical_url/canonical_url.dart';

main() {
  final urlc = new UrlCanonicalizer(removeFragment: true);

  // prints http://example.com/b.txt
  print(urlc.canonicalize('http://example.com:80/a/../b.txt'));

  // prints https://example.com/abc
  print(urlc.canonicalize('https://example.com/abc#xyz'));

  // prints http://example.com/api?a=2&b=3&c=1
  print(urlc.canonicalize('http://example.com/api?c=1&a=2&b=3'));
}

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  canonical_url: "^1.0.1"

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter packages get

Alternatively, your editor might support pub get or packages get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:canonical_url/canonical_url.dart';
        
Version Uploaded Documentation Archive
1.0.1 Mar 27, 2018 Go to the documentation of canonical_url 1.0.1 Download canonical_url 1.0.1 archive
1.0.0 Mar 23, 2018 Go to the documentation of canonical_url 1.0.0 Download canonical_url 1.0.0 archive

Analysis

We analyzed this package on Apr 23, 2018, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.0.0-dev.49.0
  • pana: 0.10.6

Scores

Popularity:
Describes how popular the package is relative to other packages. [more]
0 / 100
Health:
Code health derived from static analysis. [more]
100 / 100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100 / 100
Overall score:
Weighted score of the above. [more]
50
Learn more about scoring.

Platforms

Detected platforms: Flutter, web, other

No platform restriction found in primary library package:canonical_url/canonical_url.dart.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=1.20.1 <2.0.0
path ^1.5.1 1.5.1
Dev dependencies
test ^0.12.0