Skip to main content

linkifydart 0.1.0 copy "linkifydart: ^0.1.0" to clipboard
linkifydart: ^0.1.0 copied to clipboard

A dependency-free Dart port of linkifyjs 4.3.3 for detecting URLs and email addresses with typed options and UTF-16 source offsets.

example/example.dart

import 'package:linkifydart/linkifydart.dart' as linkify;

void main() {
  const input = 'Visit example.com or email hello@example.com.';
  print('Links: ${linkify.find(input)}');
  print('Whole URL: ${linkify.test('example.com', type: 'url')}');

  for (final token in linkify.tokenize(input)) {
    if (token.isLink) {
      print('${token.type} at ${token.start}:${token.end}: '
          '${token.toHref('https')}');
    }
  }

  final formatted = linkify.find(
    input,
    options: linkify.LinkifyOptions(
      defaultProtocol: 'https',
      format: linkify.LinkOption.transform((value) => value.toUpperCase()),
      validate: linkify.LinkOption.byType({
        'email': linkify.TokenOption.transform(
          (value) => value.endsWith('@example.com'),
        ),
      }),
      truncate: const linkify.LinkOption.value(16),
    ),
  );
  print('Formatted links: $formatted');
}
0
likes
160
points
155
downloads

Documentation

API reference

Publisher

verified publisheryooss.cn

Weekly Downloads

A dependency-free Dart port of linkifyjs 4.3.3 for detecting URLs and email addresses with typed options and UTF-16 source offsets.

Repository (GitHub)
View/report issues

Topics

#linkify #url #autolink #parser #text

License

MIT (license)

More

Packages that depend on linkifydart