uri_parser 2.0.2 copy "uri_parser: ^2.0.2" to clipboard
uri_parser: ^2.0.2 copied to clipboard

A minimal & safe utility to parse URIs.

package:uri_parser #

🔗 A minimal & safe utility to parse URIs.

Install #

Add in your pubspec.yaml.

dependencies:
  uri_parser: ^1.0.0

Example #

Parse or Identify #

final parser = URIParser('C:/Windows/System32');
print(parser.type);            // URIType.directory
print(parser.file);            // null
print(parser.directory);       // Directory: 'C:/Windows/System32'
print(parser.uri);             // null
final parser = URIParser('C:\Windows\explorer.exe');
print(parser.type);            // URIType.file
print(parser.file);            // File: 'C:/Windows/explorer.exe'
print(parser.directory);       // null
print(parser.uri);             // null
final parser = URIParser('file://C:/Windows/explorer.exe');
print(parser.type);            // URIType.file
print(parser.file);            // File: 'C:/Windows/explorer.exe'
print(parser.directory);       // null
print(parser.uri);             // null
final parser = URIParser('https://www.example.com/test');
print(parser.type);            // URIType.network
print(parser.file);            // null
print(parser.directory);       // null
print(parser.uri);             // https://www.example.com/test

Validate or Get Uri #

final parser = URIParser('C:\Windows\explorer.exe');
final bool valid = parser.validate();
final Uri result = parser.result;

Why #

First of all, this is built with requirements of Harmonoid in mind.

Being a music player, there's a great involvement of URIs everywhere. Since, users can give their inputs in wide range of formats, this is built to handle that while providing some finer control. Few being:

  • Handles both file:// URIs & File/Directory path as input.
  • Provides a way to distinguish between File, Directory & network URLs.
  • Correctly handles File paths with backward slashes on Windows.
  • Uri.parse & Uri.toFilePath do not handle file:// scheme (with two slashes) correctly on Windows.

License #

Copyright © 2022, Hitesh Kumar Saini <saini123hitesh@gmail.com>

This project & the work under this repository is governed by MIT license that can be found in the LICENSE file.

1
likes
120
pub points
80%
popularity

Publisher

unverified uploader

A minimal & safe utility to parse URIs.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (LICENSE)

Dependencies

path, safe_local_storage

More

Packages that depend on uri_parser