src/fusion/js/jssets

Set for the JavaScript target.

Example:

import src/fusion/js/jssets
import std/jsffi
if defined(fusionJsSetTests):
  let a: JsSet = newJsSet([1.toJs, 2.toJs, 3.toJs, 4.toJs])
  let b: JsSet = newJsSet([1.0.toJs, 2.0.toJs, 3.0.toJs])
  doAssert a.len == 4
  doAssert b.len == 3
  doAssert a.toString() == @["1".cstring, "2", "3", "4"]
  doAssert b.toString() == @["1".cstring, "2", "3"]
  a.clear()
  b.clear()
  let d: JsSet = newJsSet([1.toJs, 2.toJs, 3.toJs])
  doAssert d.len == 3
  d.add(4.toJs)
  d.delete(2.toJs)
  doAssert 3.toJs in d
  doAssert "3".cstring.toJs notin d
  doAssert d.contains 1.toJs
  doAssert $d == """@["1", "3", "4"]"""

Types

JsSet {.importjs: "Set".} = ref object of JsRoot
  size: cint
Set API.

Procs

func `$`(this: JsSet): string {....raises: [], tags: [].}
func len(this: JsSet): int {....raises: [], tags: [].}
func newJsSet(): JsSet {.importjs: "new Set()".}
Constructor for JsSet.
func newJsSet(items: openArray[JsObject]): JsSet {.importjs: "new Set(#)".}
Constructor for JsSet.
func toString(this: JsSet): seq[cstring] {.importjs: """  (() => {const result = []; #.forEach(item => result.push(JSON.stringify(item))); return result})()""".}
Convert JsSet to seq[cstring], all items will be converted to cstring.