UNPKG

@tienedev/datype

Version:

Modern TypeScript utility library with pragmatic typing and zero dependencies

73 lines 2.05 kB
/** * Options for configuring slugify behavior */ export interface SlugifyOptions { /** * The separator to use between words * @default '-' */ separator?: string; /** * Convert to lowercase * @default true */ lowercase?: boolean; /** * Remove consecutive separators * @default true */ trim?: boolean; /** * Custom replacement map for specific characters * @default undefined */ replacements?: Record<string, string>; /** * Remove characters that cannot be transliterated * @default true */ remove?: boolean; /** * Strict mode: only allow alphanumeric characters and separators * @default false */ strict?: boolean; } /** * Converts a string into a URL-friendly slug by removing/replacing special characters, * handling Unicode characters, and applying various formatting options. * * @param input - The string to slugify * @param options - Configuration options for slugification * @returns A URL-safe slug string * * @example * ```typescript * import { slugify } from 'datype'; * * // Basic usage * slugify('Hello World!'); // 'hello-world' * slugify('Café & Restaurant'); // 'cafe-restaurant' * * // Unicode handling * slugify('Привет мир'); // 'privet-mir' * slugify('Café à Paris'); // 'cafe-a-paris' * slugify('北京市'); // 'bei-jing-shi' (with proper transliteration) * * // Custom options * slugify('Hello World', { separator: '_' }); // 'hello_world' * slugify('Café', { lowercase: false }); // 'Cafe' * slugify('Product #123', { strict: true }); // 'product-123' * * // Custom replacements * slugify('AT&T', { * replacements: { '&': '-and-' } * }); // 'at-and-t' * * // Advanced usage * slugify(' Spaced Out ', { trim: true }); // 'spaced-out' * slugify('Special chars: @#$%', { remove: true }); // 'special-chars' * ``` */ export declare function slugify(input: string, options?: SlugifyOptions): string; //# sourceMappingURL=index.d.ts.map