Sha256: 28d8f4497bbcceb26199b2f0a432d75007547fefc0487918fa479661f8d62d89
Contents?: true
Size: 633 Bytes
Versions: 66
Compression:
Stored size: 633 Bytes
Contents
import { Controller } from "@hotwired/stimulus"; /** * Connect an input (e.g. title) to slug. */ export default class SluggableController extends Controller { static targets = ["source", "slug"]; static values = { slug: String, }; sourceChanged(e) { if (this.slugValue === "") { this.slugTarget.value = parameterize(this.sourceTarget.value); } } slugChanged(e) { this.slugValue = this.slugTarget.value; } } function parameterize(input) { return input .toLowerCase() .replace(/'/g, "-") .replace(/[^-\w\s]/g, "") .replace(/[^a-z0-9]+/g, "-") .replace(/(^-|-$)/g, ""); }
Version data entries
66 entries across 66 versions & 1 rubygems