Map and Form Data Extensions
Chainable Map helpers and the $map/$json converters for FormData and <form> elements.
Map
Source: src/prototype/Map.ts
| Method / Property | Description |
|---|---|
map.length |
this.size |
map.$keys / map.$values |
Iterators over keys / values |
map.$json |
Object.fromEntries(this) |
map._(key, value?) |
Chainable set(key, value) |
map.$(key?) |
get(key) |
map.$_(key?) |
Chainable delete(key) |
map.$$(key?) |
has(key) if given, else this.size > 0 |
FormData
Source: src/prototype/FormData.ts
| Method / Property | Description |
|---|---|
formData.$map |
Entries as a Map |
formData.$json |
Entries as a plain object |
HTMLFormElement
Source: src/prototype/HTMLFormElement.ts
| Method / Property | Description |
|---|---|
form.$map |
Form fields as a Map (via an internal FormData wrapper) |
form.$json |
Form fields as a plain object |
Example
A <form> converts straight to a plain object; Map setters chain.
<form id="form">
<input name="user" value="pardn">
<input name="plan" value="pro">
</form>
<script>
console.log("form".$.$json);
const dic = new Map()._("a", 1)._("b", 2);
console.log(dic.length, dic.$("a"), dic.$$("c"), dic.$json);
</script>