canonical_url 1.0.4

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

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.4

  • Enable Dart 2 versions.

1.0.3+1

  • Bugfix: keep trailing slash.

1.0.2

  • Handling multiple query parameter values.
  • Option to sort query parameter values.

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'));
}

Use this package as a library

1. Depend on it

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


dependencies:
  canonical_url: ^1.0.4

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 flutter 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.4 Jul 31, 2018 Go to the documentation of canonical_url 1.0.4 Download canonical_url 1.0.4 archive
1.0.3+1 Jul 7, 2018 Go to the documentation of canonical_url 1.0.3+1 Download canonical_url 1.0.3+1 archive
1.0.3 Jul 7, 2018 Go to the documentation of canonical_url 1.0.3 Download canonical_url 1.0.3 archive
1.0.2 Jun 16, 2018 Go to the documentation of canonical_url 1.0.2 Download canonical_url 1.0.2 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
Popularity:
Describes how popular the package is relative to other packages. [more]
74
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
87
Learn more about scoring.

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

  • Dart: 2.0.0
  • pana: 0.11.8

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 <3.0.0
path ^1.5.1 1.6.2
Dev dependencies
test ^0.12.0