☰

# std/jscore

Theme:

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

Search:
Source Edit

This module wraps core JavaScript functions.

Unless your application has very specific requirements and solely targets JavaScript, you should be using the relevant functions in the `math`, `json`, and `times` stdlib modules instead.

# Imports

since, jsutils

# Types

    DateLib = ref object

  Source Edit

    DateTime = ref object

  Source Edit

    JsonLib = ref object

  Source Edit

    MathLib = ref object

  Source Edit

# Vars

    Date {.importc, nodecl.}: DateLib

  Source Edit

    JSON {.importc, nodecl.}: JsonLib

  Source Edit

    Math {.importc, nodecl.}: MathLib

  Source Edit

# Procs

    proc abs(m: MathLib; a: SomeNumber): SomeNumber {.importcpp, ...raises: [],
        tags: [], forbids: [].}

  Source Edit

    proc acos(m: MathLib; a: SomeNumber): float {.importcpp, ...raises: [], tags: [],
        forbids: [].}

  Source Edit

    proc acosh(m: MathLib; a: SomeNumber): float {.importcpp, ...raises: [], tags: [],
        forbids: [].}

  Source Edit

    proc asin(m: MathLib; a: SomeNumber): float {.importcpp, ...raises: [], tags: [],
        forbids: [].}

  Source Edit

    proc asinh(m: MathLib; a: SomeNumber): float {.importcpp, ...raises: [], tags: [],
        forbids: [].}

  Source Edit

    proc atan(m: MathLib; a: SomeNumber): float {.importcpp, ...raises: [], tags: [],
        forbids: [].}

  Source Edit

    proc atan2(m: MathLib; a: SomeNumber): float {.importcpp, ...raises: [], tags: [],
        forbids: [].}

  Source Edit

    proc atanh(m: MathLib; a: SomeNumber): float {.importcpp, ...raises: [], tags: [],
        forbids: [].}

  Source Edit

    proc cbrt(m: MathLib; f: SomeFloat): SomeFloat {.importcpp, ...raises: [],
        tags: [], forbids: [].}

  Source Edit

    proc ceil(m: MathLib; f: SomeFloat): SomeFloat {.importcpp, ...raises: [],
        tags: [], forbids: [].}

  Source Edit

    proc clz32(m: MathLib; f: SomeInteger): int {.importcpp, ...raises: [], tags: [],
        forbids: [].}

  Source Edit

    func copyWithin[T](self: openArray[T]; target, start, ends: int): seq[T] {.
        importjs: "#.copyWithin(#, #, #)", ...raises: [], tags: [], forbids: [].}

  https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/copyWithin `copyWithin` uses shallow copy.

  Example:

      assert ['a', 'b', 'c', 'd', 'e'].copyWithin(0, 3, 4) == @['d', 'b', 'c', 'd', 'e']
      assert ['a', 'b', 'c', 'd', 'e'].copyWithin(1, 3) == @['a', 'd', 'e', 'd', 'e']
      assert [1, 2, 3, 4, 5].copyWithin(-2) == @[1, 2, 3, 1, 2]
      assert [1, 2, 3, 4, 5].copyWithin(0, 3) == @[4, 5, 3, 4, 5]
      assert [1, 2, 3, 4, 5].copyWithin(0, 3, 4) == @[4, 2, 3, 4, 5]
      assert [1, 2, 3, 4, 5].copyWithin(-2, -3, -1) == @[1, 2, 3, 3, 4]

  Source Edit

    func copyWithin[T](self: openArray[T]; target, start: int): seq[T] {.
        importjs: "#.copyWithin(#, #)", ...raises: [], tags: [], forbids: [].}

  Source Edit

    func copyWithin[T](self: openArray[T]; target: int): seq[T] {.
        importjs: "#.copyWithin(#)", ...raises: [], tags: [], forbids: [].}

  Source Edit

    proc cos(m: MathLib; a: SomeNumber): float {.importcpp, ...raises: [], tags: [],
        forbids: [].}

  Source Edit

    proc cosh(m: MathLib; a: SomeNumber): float {.importcpp, ...raises: [], tags: [],
        forbids: [].}

  Source Edit

    func debugger() {.importjs: "debugger@", ...raises: [], tags: [], forbids: [].}

  https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/debugger Source Edit

    proc exp(m: MathLib; a: SomeNumber): float {.importcpp, ...raises: [], tags: [],
        forbids: [].}

  Source Edit

    proc expm1(m: MathLib; a: SomeNumber): float {.importcpp, ...raises: [], tags: [],
        forbids: [].}

  Source Edit

    proc floor(m: MathLib; f: SomeFloat): int {.importcpp, ...raises: [], tags: [],
        forbids: [].}

  Source Edit

    proc fround(m: MathLib; f: SomeFloat): float32 {.importcpp, ...raises: [],
        tags: [], forbids: [].}

  Source Edit

    proc getDay(d: DateTime): int {.importcpp, ...raises: [], tags: [], forbids: [].}

  Source Edit

    proc getFullYear(d: DateTime): int {.importcpp, ...raises: [], tags: [],
                                         forbids: [].}

  Source Edit

    proc getHours(d: DateTime): int {.importcpp, ...raises: [], tags: [], forbids: [].}

  Source Edit

    proc getMilliseconds(d: DateTime): int {.importcpp, ...raises: [], tags: [],
        forbids: [].}

  Source Edit

    proc getMinutes(d: DateTime): int {.importcpp, ...raises: [], tags: [], forbids: [].}

  Source Edit

    proc getMonth(d: DateTime): int {.importcpp, ...raises: [], tags: [], forbids: [].}

  Source Edit

    proc getSeconds(d: DateTime): int {.importcpp, ...raises: [], tags: [], forbids: [].}

  Source Edit

    proc getTime(d: DateTime): int {.importcpp, ...raises: [], tags: [], forbids: [].}

  Source Edit

    proc getTimezoneOffset(d: DateTime): int {.importcpp, ...raises: [], tags: [],
        forbids: [].}

  Source Edit

    proc getUTCDate(d: DateTime): int {.importcpp, ...raises: [], tags: [], forbids: [].}

  Source Edit

    proc getUTCDay(d: DateTime): int {.importcpp, ...raises: [], tags: [], forbids: [].}

  Source Edit

    proc getUTCFullYear(d: DateTime): int {.importcpp, ...raises: [], tags: [],
                                            forbids: [].}

  Source Edit

    proc getUTCHours(d: DateTime): int {.importcpp, ...raises: [], tags: [],
                                         forbids: [].}

  Source Edit

    proc getUTCMilliseconds(d: DateTime): int {.importcpp, ...raises: [], tags: [],
        forbids: [].}

  Source Edit

    proc getUTCMinutes(d: DateTime): int {.importcpp, ...raises: [], tags: [],
                                           forbids: [].}

  Source Edit

    proc getUTCMonth(d: DateTime): int {.importcpp, ...raises: [], tags: [],
                                         forbids: [].}

  Source Edit

    proc getUTCSeconds(d: DateTime): int {.importcpp, ...raises: [], tags: [],
                                           forbids: [].}

  Source Edit

    proc getYear(d: DateTime): int {.importcpp, ...raises: [], tags: [], forbids: [].}

  Source Edit

    proc hypot(m: MathLib; args: varargs[distinct SomeNumber]): float {.importcpp,
        ...raises: [], tags: [], forbids: [].}

  Source Edit

    proc imul(m: MathLib; a, b: int32): int32 {.importcpp, ...raises: [], tags: [],
        forbids: [].}

  Source Edit

    proc log(m: MathLib; a: SomeNumber): float {.importcpp, ...raises: [], tags: [],
        forbids: [].}

  Source Edit

    proc log1p(m: MathLib; a: SomeNumber): float {.importcpp, ...raises: [], tags: [],
        forbids: [].}

  Source Edit

    proc log2(m: MathLib; a: SomeNumber): float {.importcpp, ...raises: [], tags: [],
        forbids: [].}

  Source Edit

    proc log10(m: MathLib; a: SomeNumber): float {.importcpp, ...raises: [], tags: [],
        forbids: [].}

  Source Edit

    proc max(m: MathLib; a, b: SomeNumber): SomeNumber {.importcpp, ...raises: [],
        tags: [], forbids: [].}

  Source Edit

    proc min[T: SomeNumber | JsRoot](m: MathLib; a, b: T): T {.importcpp,
        ...raises: [], tags: [], forbids: [].}

  Source Edit

    proc newDate(): DateTime {.importcpp: "new Date()", ...raises: [], tags: [],
                               forbids: [].}

  Source Edit

    proc newDate(date: int | string): DateTime {.importcpp: "new Date(#)",
        ...raises: [], tags: [], forbids: [].}

  Source Edit

    proc newDate(date: int64): DateTime {.importcpp: "new Date(Number(#))",
                                          ...raises: [], tags: [], forbids: [].}

  Source Edit

    proc newDate(year, month, day, hours, minutes, seconds, milliseconds: int): DateTime {.
        importcpp: "new Date(#,#,#,#,#,#,#)", ...raises: [], tags: [], forbids: [].}

  Source Edit

    proc now(d: DateLib): int {.importcpp, ...raises: [], tags: [], forbids: [].}

  Source Edit

    proc parse(d: DateLib; s: cstring): int {.importcpp, ...raises: [], tags: [],
        forbids: [].}

  Source Edit

    proc parse(l: JsonLib; s: cstring): JsRoot {.importcpp, ...raises: [], tags: [],
        forbids: [].}

  Source Edit

    proc pow(m: MathLib; a, b: distinct SomeNumber): float {.importcpp, ...raises: [],
        tags: [], forbids: [].}

  Source Edit

    func queueMicrotask(function: proc) {.importjs: "$1(#)", ...raises: [], tags: [],
                                          forbids: [].}

  - https://developer.mozilla.org/en-US/docs/Web/API/queueMicrotask
  - https://developer.mozilla.org/en-US/docs/Web/API/HTML_DOM_API/Microtask_guide

  Example: cmd: -r:off

      queueMicrotask(proc() = echo "Microtask")

  Source Edit

    proc random(m: MathLib): float {.importcpp, ...raises: [], tags: [], forbids: [].}

  Source Edit

    proc round(m: MathLib; f: SomeFloat): int {.importcpp, ...raises: [], tags: [],
        forbids: [].}

  Source Edit

    proc setFullYear(d: DateTime; year: int) {.importcpp, ...raises: [], tags: [],
        forbids: [].}

  Source Edit

    func shift[T](self: seq[T]): T {.importjs: "#.$1()", ...raises: [], tags: [],
                                     forbids: [].}

  https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/shift

  Example:

      var arrai = @[1, 2, 3]
      assert arrai.shift() == 1
      assert arrai == @[2, 3]

  Source Edit

    proc sign(m: MathLib; f: SomeNumber): int {.importcpp, ...raises: [], tags: [],
        forbids: [].}

  Source Edit

    proc sin(m: MathLib; a: SomeNumber): float {.importcpp, ...raises: [], tags: [],
        forbids: [].}

  Source Edit

    proc sinh(m: MathLib; a: SomeNumber): float {.importcpp, ...raises: [], tags: [],
        forbids: [].}

  Source Edit

    proc sqrt(m: MathLib; f: SomeFloat): SomeFloat {.importcpp, ...raises: [],
        tags: [], forbids: [].}

  Source Edit

    proc stringify(l: JsonLib; s: JsRoot): cstring {.importcpp, ...raises: [],
        tags: [], forbids: [].}

  Source Edit

    proc tan(m: MathLib; a: SomeNumber): float {.importcpp, ...raises: [], tags: [],
        forbids: [].}

  Source Edit

    proc tanh(m: MathLib; a: SomeNumber): float {.importcpp, ...raises: [], tags: [],
        forbids: [].}

  Source Edit

    func toDateString(d: DateTime): cstring {.importcpp, ...raises: [], tags: [],
        forbids: [].}

  Source Edit

    func toISOString(d: DateTime): cstring {.importcpp, ...raises: [], tags: [],
        forbids: [].}

  Source Edit

    func toJSON(d: DateTime): cstring {.importcpp, ...raises: [], tags: [], forbids: [].}

  Source Edit

    proc toString(d: DateTime): cstring {.importcpp, ...raises: [], tags: [],
                                          forbids: [].}

  Source Edit

    func toTimeString(d: DateTime): cstring {.importcpp, ...raises: [], tags: [],
        forbids: [].}

  Source Edit

    func toUTCString(d: DateTime): cstring {.importcpp, ...raises: [], tags: [],
        forbids: [].}

  Source Edit

    proc trunc(m: MathLib; f: SomeFloat): int {.importcpp, ...raises: [], tags: [],
        forbids: [].}

  Source Edit

    proc UTC(d: DateLib): int {.importcpp, ...raises: [], tags: [], forbids: [].}

  Source Edit