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 #

NameTypeDefaultDescription
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

[0.1.1]

Changed #

  • Set return type on Slugify.slugify()

[0.1.0]

Added #

  • documentation

[0.0.2]

Added #

  • Unit tests
  • Examples

[0.0.1]

Added #

  • Initial commit

example/slugify_example.dart

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:


dependencies:
  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';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
68
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]
84
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:slugify/slugify.dart.

Dependencies

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