slugify 1.0.0

Slugify #

Dart[1] package to convert a string to a slug, useful for URLs, filenames, IDs and more.

Features #

  • Removes unfavorable characters
  • Approximates replacements for characters not in the Latin alphabet
  • Options for a custom delimiter and case sensitivity

Usage #

import 'package:slugify/slugify.dart';

// Use with default options.
String slug = Slugify('Hello, World! Foo Bar');
print(slug); // hello-world-foo-bar

// Use with custom options.
String slug2 = Slugify('Hello, World! Foo Bar', lowercase: false, delimiter: '🙂');
print(slug2) // Hello🙂World🙂Foo🙂Bar

Options #

delimiterString"-"Separator between words
lowercasebooltrueConvert text to lowercase

[1]: This package supports Dart 2

Changelog #

All notable changes to this project will be documented in this file.

The format is based on Keep a Changelog and this project adheres to Semantic Versioning.

[1.0.0] - 2019-04-23

Added #

  • Environment to pubspec
  • Ampersand to replacements
  • Vietnamese replacements (thanks @lyquocnam)

Changed #

  • Update package to Dart 2
  • Replace unittest package with test
  • Refactor class to top-level function
  • Rewrite tests
  • Add version constraint for test package
  • Code formatting with dartfmt


Changed #

  • Set return type on Slugify.slugify()


Added #

  • documentation


Added #

  • Unit tests
  • Examples


Added #

  • Initial commit


import 'package:slugify/slugify.dart';

void main() {
  // Slugify with default config.
  var slug1 = Slugify('Hello, world!');
  print(slug1); // 'hello-world'

  // Set a custom delimiter.
  var slug2 = Slugify('Some prefer snake case', delimiter: '_');
  print(slug2); // 'some_prefer_snake_case'

  // Preserve the original case.
  var slug3 = Slugify('BREAKING NEWS! The world is ending!', lowercase: false);
  print(slug3); // 'BREAKING-NEWS-The-world-is-ending'

  // Normalize to latin characters.
  var slug4 = Slugify("C'est déjà l'été.");
  print(slug4); // 'cest-deja-lete'

Use this package as a library

1. Depend on it

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

  slugify: ^1.0.0

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:slugify/slugify.dart';
Describes how popular the package is relative to other packages. [more]
Code health derived from static analysis. [more]
Reflects how tidy and up-to-date the package is. [more]
Weighted score of the above. [more]
Learn more about scoring.

We analyzed this package on Feb 13, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.7.1
  • pana: 0.13.5


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0 <3.0.0
Dev dependencies
test ^1.6.2