Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add remove option field to playground #445

Merged
merged 3 commits into from
May 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,11 @@
<input type="text" id="input" placeholder="An Apple computer" autofocus>
</fieldset>



<fieldset>
<label for="replacement">Replacement character</label>
<input type="text" id="replacement" name="replacement" placeholder="-">
</fieldset>


<fieldset>
<label>
<input type="checkbox" name="lowercase" checked> Lowercase
Expand All @@ -39,6 +36,17 @@
</label>
</fieldset>

<details>
<summary><h4>Advanced options</h4></summary>
<fieldset style="display: flex; justify-content: flex-start; align-items: center">
<label for="remove">Remove chars (regex)</label>&nbsp;
/<input type="text" id="remove" name="remove" placeholder="(?<= )((a)|(an)|(the))(?= )" />/<br />
<label> <input type="checkbox" name="regex_g" /> g </label>

<label> <input type="checkbox" name="regex_i" /> i </label>
</fieldset>
</details>

<input type="submit" value="Slug it">

</form>
Expand Down
9 changes: 9 additions & 0 deletions playground.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,21 @@ form.addEventListener('submit', function (e) {
const trim = fd.get('trim')
const fallback = fd.get('fallback')

const remove = fd.get('remove')
const regexG = fd.get('regex_g') === null ? '' : 'g'
const regexI = fd.get('regex_i') === null ? '' : 'i'

const opts = {}

if (replacement.length > 0) {
opts.replacement = replacement
}

if (remove !== null && remove.length > 0) {
const regex = new RegExp(`/${remove}/${regexG}${regexI}`)
opts.remove = regex
}

opts.lower = lowercase !== null

opts.trim = trim !== null
Expand Down
Loading