jscore.nim 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. #
  2. #
  3. # Nim's Runtime Library
  4. # (c) Copyright 2018 Nim contributors
  5. #
  6. # See the file "copying.txt", included in this
  7. # distribution, for details about the copyright.
  8. #
  9. ## This module wraps core JavaScript functions.
  10. ##
  11. ## Unless your application has very
  12. ## specific requirements and solely targets JavaScript, you should be using
  13. ## the relevant functions in the ``math``, ``json``, and ``times`` stdlib
  14. ## modules instead.
  15. when not defined(js) and not defined(Nimdoc):
  16. {.error: "This module only works on the JavaScript platform".}
  17. type
  18. MathLib* = ref object
  19. JsonLib* = ref object
  20. DateLib* = ref object
  21. DateTime* = ref object
  22. var
  23. Math* {.importc, nodecl.}: MathLib
  24. Date* {.importc, nodecl.}: DateLib
  25. JSON* {.importc, nodecl.}: JsonLib
  26. # Math library
  27. proc abs*(m: MathLib, a: SomeNumber): SomeNumber {.importcpp.}
  28. proc acos*(m: MathLib, a: SomeNumber): float {.importcpp.}
  29. proc acosh*(m: MathLib, a: SomeNumber): float {.importcpp.}
  30. proc asin*(m: MathLib, a: SomeNumber): float {.importcpp.}
  31. proc asinh*(m: MathLib, a: SomeNumber): float {.importcpp.}
  32. proc atan*(m: MathLib, a: SomeNumber): float {.importcpp.}
  33. proc atan2*(m: MathLib, a: SomeNumber): float {.importcpp.}
  34. proc atanh*(m: MathLib, a: SomeNumber): float {.importcpp.}
  35. proc cbrt*(m: MathLib, f: SomeFloat): SomeFloat {.importcpp.}
  36. proc ceil*(m: MathLib, f: SomeFloat): SomeFloat {.importcpp.}
  37. proc clz32*(m: MathLib, f: SomeInteger): int {.importcpp.}
  38. proc cos*(m: MathLib, a: SomeNumber): float {.importcpp.}
  39. proc cosh*(m: MathLib, a: SomeNumber): float {.importcpp.}
  40. proc exp*(m: MathLib, a: SomeNumber): float {.importcpp.}
  41. proc expm1*(m: MathLib, a: SomeNumber): float {.importcpp.}
  42. proc floor*(m: MathLib, f: SomeFloat): int {.importcpp.}
  43. proc fround*(m: MathLib, f: SomeFloat): float32 {.importcpp.}
  44. proc hypot*(m: MathLib, args: varargs[distinct SomeNumber]): float {.importcpp.}
  45. proc imul*(m: MathLib, a, b: int32): int32 {.importcpp.}
  46. proc log*(m: MathLib, a: SomeNumber): float {.importcpp.}
  47. proc log10*(m: MathLib, a: SomeNumber): float {.importcpp.}
  48. proc log1p*(m: MathLib, a: SomeNumber): float {.importcpp.}
  49. proc log2*(m: MathLib, a: SomeNumber): float {.importcpp.}
  50. proc max*(m: MathLib, a, b: SomeNumber): SomeNumber {.importcpp.}
  51. proc min*[T: SomeNumber | JsRoot](m: MathLib, a, b: T): T {.importcpp.}
  52. proc pow*(m: MathLib, a, b: distinct SomeNumber): float {.importcpp.}
  53. proc random*(m: MathLib): float {.importcpp.}
  54. proc round*(m: MathLib, f: SomeFloat): int {.importcpp.}
  55. proc sign*(m: MathLib, f: SomeNumber): int {.importcpp.}
  56. proc sin*(m: MathLib, a: SomeNumber): float {.importcpp.}
  57. proc sinh*(m: MathLib, a: SomeNumber): float {.importcpp.}
  58. proc sqrt*(m: MathLib, f: SomeFloat): SomeFloat {.importcpp.}
  59. proc tan*(m: MathLib, a: SomeNumber): float {.importcpp.}
  60. proc tanh*(m: MathLib, a: SomeNumber): float {.importcpp.}
  61. proc trunc*(m: MathLib, f: SomeFloat): int {.importcpp.}
  62. # Date library
  63. proc now*(d: DateLib): int {.importcpp.}
  64. proc UTC*(d: DateLib): int {.importcpp.}
  65. proc parse*(d: DateLib, s: cstring): int {.importcpp.}
  66. proc newDate*(): DateTime {.
  67. importcpp: "new Date()".}
  68. proc newDate*(date: int|int64|string): DateTime {.
  69. importcpp: "new Date(#)".}
  70. proc newDate*(year, month, day, hours, minutes,
  71. seconds, milliseconds: int): DateTime {.
  72. importcpp: "new Date(#,#,#,#,#,#,#)".}
  73. proc getDay*(d: DateTime): int {.importcpp.}
  74. proc getFullYear*(d: DateTime): int {.importcpp.}
  75. proc getHours*(d: DateTime): int {.importcpp.}
  76. proc getMilliseconds*(d: DateTime): int {.importcpp.}
  77. proc getMinutes*(d: DateTime): int {.importcpp.}
  78. proc getMonth*(d: DateTime): int {.importcpp.}
  79. proc getSeconds*(d: DateTime): int {.importcpp.}
  80. proc getYear*(d: DateTime): int {.importcpp.}
  81. proc getTime*(d: DateTime): int {.importcpp.}
  82. proc toString*(d: DateTime): cstring {.importcpp.}
  83. proc getUTCDate*(d: DateTime): int {.importcpp.}
  84. proc getUTCFullYear*(d: DateTime): int {.importcpp.}
  85. proc getUTCHours*(d: DateTime): int {.importcpp.}
  86. proc getUTCMilliseconds*(d: DateTime): int {.importcpp.}
  87. proc getUTCMinutes*(d: DateTime): int {.importcpp.}
  88. proc getUTCMonth*(d: DateTime): int {.importcpp.}
  89. proc getUTCSeconds*(d: DateTime): int {.importcpp.}
  90. proc getUTCDay*(d: DateTime): int {.importcpp.}
  91. proc getTimezoneOffset*(d: DateTime): int {.importcpp.}
  92. proc setFullYear*(d: DateTime, year: int) {.importcpp.}
  93. #JSON library
  94. proc stringify*(l: JsonLib, s: JsRoot): cstring {.importcpp.}
  95. proc parse*(l: JsonLib, s: cstring): JsRoot {.importcpp.}