canonical_url 1.0.4

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 pub get

Alternatively, your editor might support pub get or flutter pub 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';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
63
Health:
Code health derived from static analysis. [more]
99
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
86
Overall:
Weighted score of the above. [more]
78
Learn more about scoring.

We analyzed this package on Sep 20, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.5.0
  • pana: 0.12.21

Platforms

Detected platforms: Flutter, web, other

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

Health suggestions

Fix lib/canonical_url.dart. (-1.49 points)

Analysis of lib/canonical_url.dart reported 3 hints:

line 14 col 14: Use = to separate a named parameter from its default value.

line 15 col 20: Use = to separate a named parameter from its default value.

line 17 col 24: Use = to separate a named parameter from its default value.

Maintenance suggestions

Package is getting outdated. (-13.70 points)

The package was last published 59 weeks ago.

Dependencies

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