/slug

Haxe port of npm slugify.

Primary LanguageHaxe

hx-slug

Haxe port of npm slugify.

Installation

$ haxelib install slug

API

Slug.encode(data:String, ?options:SlugOptions):String

Encodes the given data into a slug.

SlugOptions

This is a class with @:structInit, so it can be created from an anonymous structure with some of the fields.

class SlugOptions {
  // If true, all character will be converted to lowercase.
  public final lower:Bool = true;
  
  // If not null, all matches for this regular expression will be
  // removed from the slug.
  // If null, Slug.safe is used.
  public final remove:EReg = null;
  
  // String used to replace spaces.
  public final replacement:String = "-";
}
import haxe.format.Slug;

class Main {
  public static function main():Void {
    trace(Slug.encode("Čokoľvek $ %"));
    // output: cokolvek-dollar-percent
  }
}