v2.0.3

Map and Form Data Extensions

Last updated


Chainable Map helpers and the $map/$json converters for FormData and <form> elements.

Map


Source: src/prototype/Map.ts
Method / PropertyDescription
map.lengththis.size
map.$keys / map.$valuesIterators over keys / values
map.$jsonObject.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 / PropertyDescription
formData.$mapEntries as a Map
formData.$jsonEntries as a plain object

HTMLFormElement


Source: src/prototype/HTMLFormElement.ts
Method / PropertyDescription
form.$map / form.$jsonGetters that wrap the form in new FormData(form) but then read its map / json property instead of $map / $json, so both return undefined; use new FormData(form).$map / .$json

Example


new FormData(form).$json converts a form to a plain object while form.$json returns undefined; Map setters chain.
  1. <form id="form">
  2. <input name="user" value="pardn">
  3. <input name="plan" value="pro">
  4. </form>
  5. <script>
  6. console.log(new FormData("form".$).$json, String("form".$.$json));
  7. const dic = new Map()._("a", 1)._("b", 2);
  8. console.log(dic.length, dic.$("a"), dic.$$("c"), dic.$json);
  9. </script>
Live preview · @pardnchiu/renderjs@2.0.3
中文