☰

# std/jsformdata

Theme:

- Manual
- Standard library
- Index
- Compiler docs
- Fusion docs
- devel, stable

Search:
Source Edit

- `FormData` for the JavaScript target: https://developer.mozilla.org/en-US/docs/Web/API/FormData

Example: cmd: -r:off

    import std/jsformdata
    let data: FormData = newFormData()
    data["key0"] = "value0".cstring
    data.add("key1".cstring, "value1".cstring)
    data.delete("key1")
    assert data.hasKey("key0")
    assert data["key0"] == "value0".cstring
    data.clear()
    assert data.len == 0

# Imports

dom

# Types

    FormData = ref object of JsRoot

  FormData API. Source Edit

# Procs

    func `$`(self: FormData): string {....raises: [], tags: [], forbids: [].}

  Source Edit

    func `[]`(self: FormData; name: cstring): cstring {.importjs: "#.get(#)",
        ...raises: [], tags: [], forbids: [].}

  https://developer.mozilla.org/en-US/docs/Web/API/FormData/get Source Edit

    func `[]=`(self: FormData; name: cstring;
               value: SomeNumber | bool | cstring | Blob) {.importjs: "#.set(#, #)",
        ...raises: [], tags: [], forbids: [].}

  https://developer.mozilla.org/en-US/docs/Web/API/FormData/set Source Edit

    func add(self: FormData; name: cstring;
             value: SomeNumber | bool | cstring | Blob) {.
        importjs: "#.append(#, #)", ...raises: [], tags: [], forbids: [].}

  https://developer.mozilla.org/en-US/docs/Web/API/FormData/append
  Hint: Duplicate keys are allowed and order is preserved.
  Source Edit

    func add(self: FormData; name: cstring;
             value: SomeNumber | bool | cstring | Blob; filename: cstring) {.
        importjs: "#.append(#, #, #)", ...raises: [], tags: [], forbids: [].}

  https://developer.mozilla.org/en-US/docs/Web/API/FormData/append
  Hint: Duplicate keys are allowed and order is preserved.
  Source Edit

    func clear(self: FormData) {.importjs: "(() => { const frmdt = #; Array.from(frmdt.keys()).forEach((key) => frmdt.delete(key)) })()",
                                 ...raises: [], tags: [], forbids: [].}

  Convenience func to delete all items from `FormData`. Source Edit

    func delete(self: FormData; name: cstring) {.importjs: "#.$1(#)", ...raises: [],
        tags: [], forbids: [].}

  https://developer.mozilla.org/en-US/docs/Web/API/FormData/delete
  Warning: Deletes all items with the same key name.
  Source Edit

    func getAll(self: FormData; name: cstring): seq[cstring] {.importjs: "#.$1(#)",
        ...raises: [], tags: [], forbids: [].}

  https://developer.mozilla.org/en-US/docs/Web/API/FormData/getAll Source Edit

    func hasKey(self: FormData; name: cstring): bool {.importjs: "#.has(#)",
        ...raises: [], tags: [], forbids: [].}

  https://developer.mozilla.org/en-US/docs/Web/API/FormData/has Source Edit

    func keys(self: FormData): seq[cstring] {.importjs: "Array.from(#.$1())",
        ...raises: [], tags: [], forbids: [].}

  https://developer.mozilla.org/en-US/docs/Web/API/FormData/keys Source Edit

    func len(self: FormData): int {.importjs: "Array.from(#.entries()).length",
                                    ...raises: [], tags: [], forbids: [].}

  Source Edit

    func newFormData(): FormData {.importjs: "new FormData()", ...raises: [], tags: [],
                                   forbids: [].}

  Source Edit

    func pairs(self: FormData): seq[tuple[key, val: cstring]] {.
        importjs: "Array.from(#.entries())", ...raises: [], tags: [], forbids: [].}

  https://developer.mozilla.org/en-US/docs/Web/API/FormData/entries Source Edit

    func put(self: FormData; name: cstring;
             value: SomeNumber | bool | cstring | Blob; filename: cstring) {.
        importjs: "#.set(#, #, #)", ...raises: [], tags: [], forbids: [].}

  https://developer.mozilla.org/en-US/docs/Web/API/FormData/set Source Edit

    func toCstring(self: FormData): cstring {.importjs: "JSON.stringify(#)",
        ...raises: [], tags: [], forbids: [].}

  Source Edit

    func values(self: FormData): seq[cstring] {.importjs: "Array.from(#.$1())",
        ...raises: [], tags: [], forbids: [].}

  https://developer.mozilla.org/en-US/docs/Web/API/FormData/values Source Edit