Skip to content

Commit

Permalink
feat: add remove option field to playground (#445)
Browse files Browse the repository at this point in the history
* feat: added `remove` field with regex parsing

* feat: added placeholder for `remove` field

* feat: fold advanced options under a <details> disclosure
  • Loading branch information
screensaversclub committed May 24, 2024
1 parent e77b683 commit 8888d69
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
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

0 comments on commit 8888d69

Please sign in to comment.