Skip to content
This repository was archived by the owner on Jul 30, 2024. It is now read-only.

Commit da73185

Browse files
authored
Merge pull request #317 from exoego/crypto-randomint
[crypto] Add crypto.randomInt
2 parents b8d1ca4 + 845eff4 commit da73185

File tree

5 files changed

+40
-3
lines changed

5 files changed

+40
-3
lines changed

.node-version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
v14.7.0
1+
v14.10.0

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ jdk:
1010

1111
env:
1212
matrix:
13-
- TRAVIS_NODE_VERSION="14.7.0"
13+
- TRAVIS_NODE_VERSION="14.10.0"
1414
- TRAVIS_NODE_VERSION="12.18.3"
1515
- TRAVIS_NODE_VERSION="10.22.0"
1616

app/nodejs-v14/src/main/scala/io/scalajs/nodejs/crypto/Crypto.scala

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,15 @@ trait Crypto extends js.Object {
321321
js.native
322322
def randomFill[T <: scala.scalajs.js.typedarray.TypedArray[_, T]](buffer: T, callback: Callback1[T]): T = js.native
323323

324+
@enableIf(io.scalajs.nodejs.internal.CompilerSwitches.gteNodeJs14)
325+
def randomInt(max: Int): Int = js.native
326+
@enableIf(io.scalajs.nodejs.internal.CompilerSwitches.gteNodeJs14)
327+
def randomInt(max: Int, callback: Callback1[Int]): Unit = js.native
328+
@enableIf(io.scalajs.nodejs.internal.CompilerSwitches.gteNodeJs14)
329+
def randomInt(min: Int, max: Int): Int = js.native
330+
@enableIf(io.scalajs.nodejs.internal.CompilerSwitches.gteNodeJs14)
331+
def randomInt(min: Int, max: Int, callback: Callback1[Int]): Unit = js.native
332+
324333
def scrypt(password: String, salt: String, keylen: Int, options: ScryptOptions, callback: Callback1[Buffer]): Unit =
325334
js.native
326335
def scrypt(password: String,
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package io.scalajs.nodejs.crypto
2+
3+
import org.scalatest.funsuite.AnyFunSuite
4+
5+
class CryptoNodeJS14Test extends AnyFunSuite {
6+
test("randomInt") {
7+
val i1 = Crypto.randomInt(10)
8+
assert(0 <= i1 && i1 <= 10)
9+
10+
val i2 = Crypto.randomInt(10, 100)
11+
assert(10 <= i2 && i2 <= 100)
12+
13+
Crypto.randomInt(
14+
10,
15+
(_, i3) => {
16+
assert(0 <= i3 && i3 <= 10)
17+
}
18+
)
19+
20+
Crypto.randomInt(
21+
10,
22+
100,
23+
(_, i4) => {
24+
assert(10 <= i4 && i4 <= 100)
25+
}
26+
)
27+
}
28+
}

build.sbt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ lazy val core = (project in file("./core"))
2525
libraryDependencies ++= Dependencies.core.value
2626
)
2727

28-
lazy val nodejs_v14 = createNodeVersionSpecificProject("14.7.0")
28+
lazy val nodejs_v14 = createNodeVersionSpecificProject("14.10.0")
2929
lazy val nodejs_v12 = createNodeVersionSpecificProject("12.18.3")
3030
lazy val nodejs_v10 = createNodeVersionSpecificProject("10.22.0")
3131

0 commit comments

Comments
 (0)