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

Prefer overload over union types #261

Merged
merged 1 commit into from
Jun 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 29 additions & 20 deletions app/nodejs-v14/src/main/scala/io/scalajs/nodejs/Assert.scala
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,18 @@ trait Assert extends js.Object {
def deepStrictEqual(actual: js.Any, expected: js.Any, message: String): Unit = js.native
def deepStrictEqual(actual: js.Any, expected: js.Any): Unit = js.native

def doesNotReject(asyncFn: js.Function | js.Promise[_], error: js.RegExp | js.Function, message: String): Unit =
js.native
def doesNotReject(asyncFn: js.Function | js.Promise[_], error: js.RegExp | js.Function): Unit = js.native
def doesNotReject(asyncFn: js.Function | js.Promise[_], message: String): Unit = js.native
def doesNotReject(asyncFn: js.Function | js.Promise[_]): Unit = js.native
def doesNotReject(asyncFn: js.Function, error: js.RegExp, message: String): Unit = js.native
def doesNotReject(asyncFn: js.Function, error: js.RegExp): Unit = js.native
def doesNotReject(asyncFn: js.Function, error: js.Function, message: String): Unit = js.native
def doesNotReject(asyncFn: js.Function, error: js.Function): Unit = js.native
def doesNotReject(asyncFn: js.Function, message: String): Unit = js.native
def doesNotReject(asyncFn: js.Function): Unit = js.native
def doesNotReject(asyncFn: js.Promise[_], error: js.RegExp, message: String): Unit = js.native
def doesNotReject(asyncFn: js.Promise[_], error: js.RegExp): Unit = js.native
def doesNotReject(asyncFn: js.Promise[_], error: js.Function, message: String): Unit = js.native
def doesNotReject(asyncFn: js.Promise[_], error: js.Function): Unit = js.native
def doesNotReject(asyncFn: js.Promise[_], message: String): Unit = js.native
def doesNotReject(asyncFn: js.Promise[_]): Unit = js.native

/**
* Asserts that the function block does not throw an error. See assert.throws() for more details.
Expand All @@ -44,10 +51,12 @@ trait Assert extends js.Object {
* error is of a different type, or if the error parameter is undefined, the error is propagated back to the caller.
* @example assert.doesNotThrow(block[, error][, message])
*/
def doesNotThrow(block: js.Function, error: js.RegExp | js.Function, message: String): Unit = js.native
def doesNotThrow(block: js.Function, error: js.RegExp | js.Function): Unit = js.native
def doesNotThrow(block: js.Function, message: String): Unit = js.native
def doesNotThrow(block: js.Function): Unit = js.native
def doesNotThrow(block: js.Function, error: js.RegExp, message: String): Unit = js.native
def doesNotThrow(block: js.Function, error: js.RegExp): Unit = js.native
def doesNotThrow(block: js.Function, error: js.Function, message: String): Unit = js.native
def doesNotThrow(block: js.Function, error: js.Function): Unit = js.native
def doesNotThrow(block: js.Function, message: String): Unit = js.native
def doesNotThrow(block: js.Function): Unit = js.native

/**
* @see https://nodejs.org/api/assert.html#assert_assert_fail_message
Expand Down Expand Up @@ -102,17 +111,17 @@ trait Assert extends js.Object {
* of the message parameter. If the message parameter is undefined, a default error message is assigned.
* @example assert.throws(block[, error][, message])
*/
def throws(block: js.Function, error: js.RegExp | js.Function | js.Object | Error, message: String): Unit = js.native
def throws(block: js.Function, error: js.RegExp | js.Function | js.Object | Error): Unit = js.native

def rejects(asyncFn: js.Function | js.Promise[_],
error: js.RegExp | js.Function | js.Object | Error,
message: String
): Unit = js.native
def rejects(asyncFn: js.Function | js.Promise[_], error: js.RegExp | js.Function | js.Object | Error): Unit =
js.native
def rejects(asyncFn: js.Function | js.Promise[_], message: String): Unit = js.native
def rejects(asyncFn: js.Function | js.Promise[_]): Unit = js.native
def throws(block: js.Function, error: js.Object, message: String): Unit = js.native
def throws(block: js.Function, error: js.Object): Unit = js.native

def rejects(asyncFn: js.Function, error: js.Object, message: String): Unit = js.native
def rejects(asyncFn: js.Function, error: js.Object): Unit = js.native
def rejects(asyncFn: js.Function, message: String): Unit = js.native
def rejects(asyncFn: js.Function): Unit = js.native
def rejects(asyncFn: js.Promise[_], error: js.Object, message: String): Unit = js.native
def rejects(asyncFn: js.Promise[_], error: js.Object): Unit = js.native
def rejects(asyncFn: js.Promise[_], message: String): Unit = js.native
def rejects(asyncFn: js.Promise[_]): Unit = js.native
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,14 @@ class StringDecoder(encoding: String) extends IEventEmitter {
* Returns any trailing bytes that were left in the buffer.
* @example decoder.end()
*/
def end(buffer: TypedArray[_, _] | DataView): String = js.native
def end(): String = js.native
def end(buffer: TypedArray[_, _]): String = js.native
def end(buffer: DataView): String = js.native
def end(): String = js.native

/**
* Returns a decoded string.
* @example decoder.write(buffer)
*/
def write(buffer: TypedArray[_, _] | DataView): String = js.native
def write(buffer: TypedArray[_, _]): String = js.native
def write(buffer: DataView): String = js.native
}
104 changes: 45 additions & 59 deletions app/nodejs-v14/src/main/scala/io/scalajs/nodejs/buffer/Buffer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -97,49 +97,36 @@ class Buffer private[this] () extends Uint8Array( /* dummy to trick constructor
*/
def equals(otherBuffer: Uint8Array): Boolean = js.native

/**
* Fills buf with the specified value. If the offset and end are not given, the entire buf will be filled.
* This is meant to be a small simplification to allow the creation and filling of a Buffer to be done on a single line.
*
* @param value The value to fill buf with
* @param offset Where to start filling buf. Default: 0
* @param end Where to stop filling buf (not inclusive). Default: buf.length
* @param encoding If value is a string, this is its encoding. Default: 'utf8'
* @return A reference to buf
* @see https://nodejs.org/api/buffer.html#buffer_buf_fill_value_offset_end_encoding
*/
def fill(value: Uint8Array | Int | String, offset: Int, end: Int, encoding: String): this.type = js.native
def fill(value: Uint8Array | Int | String, offset: Int, end: Int): this.type = js.native
def fill(value: Uint8Array | Int | String, offset: Int, encoding: String): this.type = js.native
def fill(value: Uint8Array | Int | String, offset: Int): this.type = js.native
def fill(value: Uint8Array | Int | String, encoding: String): this.type = js.native
def fill(value: Uint8Array | Int | String): this.type = js.native

/**
* Returns the index of the first occurrence of value in buf or -1 if buf does not contain value
* @param value What to search for
* @param byteOffset Where to begin searching in buf. Default: 0
* @param encoding If value is a string, this is its encoding. Default: 'utf8'
* @return The index of the first occurrence of value in buf or -1 if buf does not contain value
* @example {{{ buf.indexOf(value[, byteOffset][, encoding]) }}}
*/
def indexOf(value: Buffer | Int | String, byteOffset: Int, encoding: String): Int = js.native
def indexOf(value: Buffer | Int | String, byteOffset: Int): Int = js.native
def indexOf(value: Buffer | Int | String, encoding: String): Int = js.native
def indexOf(value: Buffer | Int | String): Int = js.native

/**
* Equivalent to buf.indexOf() !== -1.
* @param value What to search for
* @param byteOffset Where to begin searching in buf. Default: 0
* @param encoding If value is a string, this is its encoding. Default: 'utf8'
* @return true if value was found in buf, false otherwise
* @example {{{ buf.includes(value[, byteOffset][, encoding]) }}}
*/
def includes(value: Buffer | Int | String, byteOffset: Int, encoding: String): Boolean = js.native
def includes(value: Buffer | Int | String, byteOffset: Int): Boolean = js.native
def includes(value: Buffer | Int | String, encoding: String): Boolean = js.native
def includes(value: Buffer | Int | String): Boolean = js.native
def fill(value: Uint8Array, offset: Int, end: Int): this.type = js.native
def fill(value: Uint8Array, offset: Int): this.type = js.native
def fill(value: Uint8Array): this.type = js.native
def fill(value: Int, offset: Int, end: Int): this.type = js.native
def fill(value: Int, offset: Int): this.type = js.native
def fill(value: Int): this.type = js.native
def fill(value: String, offset: Int, end: Int, encoding: String): this.type = js.native
def fill(value: String, offset: Int, end: Int): this.type = js.native
def fill(value: String, offset: Int, encoding: String): this.type = js.native
def fill(value: String, offset: Int): this.type = js.native
def fill(value: String, encoding: String): this.type = js.native
def fill(value: String): this.type = js.native

def indexOf(value: Buffer, byteOffset: Int): Int = js.native
def indexOf(value: Buffer): Int = js.native
def indexOf(value: Int, byteOffset: Int): Int = js.native
def indexOf(value: Int): Int = js.native
def indexOf(value: String, byteOffset: Int, encoding: String): Int = js.native
def indexOf(value: String, byteOffset: Int): Int = js.native
def indexOf(value: String, encoding: String): Int = js.native
def indexOf(value: String): Int = js.native

def includes(value: Buffer, byteOffset: Int): Boolean = js.native
def includes(value: Buffer): Boolean = js.native
def includes(value: Int, byteOffset: Int): Boolean = js.native
def includes(value: Int): Boolean = js.native
def includes(value: String, byteOffset: Int, encoding: String): Boolean = js.native
def includes(value: String, byteOffset: Int): Boolean = js.native
def includes(value: String, encoding: String): Boolean = js.native
def includes(value: String): Boolean = js.native

/**
* Creates and returns an iterator of buf keys (indices).
Expand All @@ -148,18 +135,14 @@ class Buffer private[this] () extends Uint8Array( /* dummy to trick constructor
*/
def keys(): js.Iterator[Int] = js.native

/**
* Identical to buf.indexOf(), except buf is searched from back to front instead of front to back.
* @param value What to search for
* @param byteOffset Where to begin searching in buf. Default: 0
* @param encoding If value is a string, this is its encoding. Default: 'utf8'
* @return The index of the last occurrence of value in buf or -1 if buf does not contain value
* @example {{{ buf.lastIndexOf(value[, byteOffset][, encoding]) }}}
*/
def lastIndexOf(value: Buffer | Int | String, byteOffset: Int, encoding: String): Int = js.native
def lastIndexOf(value: Buffer | Int | String, byteOffset: Int): Int = js.native
def lastIndexOf(value: Buffer | Int | String, encoding: String): Int = js.native
def lastIndexOf(value: Buffer | Int | String): Int = js.native
def lastIndexOf(value: Buffer, byteOffset: Int): Int = js.native
def lastIndexOf(value: Buffer): Int = js.native
def lastIndexOf(value: Int, byteOffset: Int): Int = js.native
def lastIndexOf(value: Int): Int = js.native
def lastIndexOf(value: String, byteOffset: Int, encoding: String): Int = js.native
def lastIndexOf(value: String, byteOffset: Int): Int = js.native
def lastIndexOf(value: String, encoding: String): Int = js.native
def lastIndexOf(value: String): Int = js.native

/**
* Returns the amount of memory allocated for buf in bytes.
Expand Down Expand Up @@ -925,8 +908,11 @@ object Buffer extends js.Object {
*
* @see [[https://nodejs.org/api/buffer.html#buffer_class_method_buffer_bytelength_string_encoding]]
*/
def byteLength(string: String | TypedArray[_, _] | DataView | ArrayBuffer, encoding: String = "utf8"): Int =
js.native
def byteLength(string: String, encoding: String): Int = js.native
def byteLength(string: String): Int = js.native
def byteLength(string: TypedArray[_, _]): Int = js.native
def byteLength(string: DataView): Int = js.native
def byteLength(string: ArrayBuffer): Int = js.native

/**
* Compares `buf1` to `buf2` typically for the purpose of sorting arrays of `Buffer` instances.
Expand All @@ -945,8 +931,8 @@ object Buffer extends js.Object {
* @see [[https://nodejs.org/api/buffer.html#buffer_class_method_buffer_concat_list_totallength]]
*
*/
def concat(list: js.Array[Buffer] | js.Array[Uint8Array], totalLength: Int): Buffer = js.native
def concat(list: js.Array[Buffer] | js.Array[Uint8Array]): Buffer = js.native
def concat[B <: Uint8Array](list: js.Array[B], totalLength: Int): Buffer = js.native
def concat[B <: Uint8Array](list: js.Array[B]): Buffer = js.native

/**
* When passed a reference to the .buffer property of a TypedArray instance, the newly created Buffer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,9 @@ package object buffer {
/**
* Returns the actual byte length of a string. This is not the same as String.prototype.length since that returns
* the number of characters in a string.
*
* @param encoding the optional encoding (default "utf8")
*/
@inline
def byteLength(encoding: String = "utf8"): Int = Buffer.byteLength(buffer, encoding)
def byteLength(encoding: String): Int = Buffer.byteLength(buffer)

/**
* Returns the hex-formatted string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@ import scala.scalajs.js.|
@js.native
@JSImport("crypto", "Certificate")
object Certificate extends js.Object {
def exportChallenge(spkac: String | BufferLike): Buffer = js.native
def exportChallenge(spkac: String): Buffer = js.native
def exportChallenge(spkac: BufferLike): Buffer = js.native

def exportPublicKey(spkac: String | BufferLike, encoding: String): Buffer = js.native
def exportPublicKey(spkac: String | BufferLike): Buffer = js.native
def exportPublicKey(spkac: String, encoding: String): Buffer = js.native
def exportPublicKey(spkac: String): Buffer = js.native
def exportPublicKey(spkac: BufferLike): Buffer = js.native

def verifySpkac(spkac: BufferLike): Boolean = js.native
}
Loading