UNPKG

@azizbecha/strkit

Version:

strkit is a utility library offering a collection of essential string functions including validation, case conversion, truncation, and more. Ideal for both JavaScript and TypeScript developers to simplify string operations in their applications.

32 lines 1.08 kB
(function (factory) { if (typeof module === "object" && typeof module.exports === "object") { var v = factory(require, exports); if (v !== undefined) module.exports = v; } else if (typeof define === "function" && define.amd) { define(["require", "exports"], factory); } })(function (require, exports) { "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = toSlug; /** * Converts a string to a URL-friendly slug. * * @param str - The string to convert to slug * @returns A URL-friendly slug string * * @example * toSlug('Hello World!'); // "hello-world" * toSlug('This is a TEST'); // "this-is-a-test" */ function toSlug(str) { return str .toLowerCase() .trim() .replace(/[^\w\s-]/g, '') // Remove special characters .replace(/\s+/g, '-') // Replace spaces with - .replace(/-+/g, '-'); // Replace multiple - with single - } }); //# sourceMappingURL=toSlug.js.map