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

Commit 6e21996

Browse files
authored
Merge pull request #114 from exoego/util-inspect
Util.inspect object is now function
2 parents 639667d + d067315 commit 6e21996

File tree

3 files changed

+15
-19
lines changed

3 files changed

+15
-19
lines changed

app/current/src/main/scala/io/scalajs/nodejs/util/InspectOptions.scala

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,14 @@ import scala.scalajs.js.|
2525
*
2626
* @see [[https://nodejs.org/api/util.html#util_util_inspect_object_options]]
2727
*/
28-
class InspectOptions(var showHidden: js.UndefOr[Boolean] = js.undefined,
29-
var depth: js.UndefOr[Int] = js.undefined,
30-
var colors: js.UndefOr[Boolean] = js.undefined,
31-
var customInspect: js.UndefOr[Boolean] = js.undefined,
32-
var showProxy: js.UndefOr[Boolean] = js.undefined,
33-
var maxArrayLength: js.UndefOr[Int] = js.undefined,
34-
var breakLength: js.UndefOr[Int] = js.undefined,
35-
var compact: js.UndefOr[Boolean | Int] = js.undefined,
28+
class InspectOptions(var showHidden: js.UndefOr[Boolean] = false,
29+
var depth: Int = 2,
30+
var colors: Boolean = false,
31+
var customInspect: Boolean = true,
32+
var showProxy: Boolean = false,
33+
var maxArrayLength: js.UndefOr[Int] = 100,
34+
var breakLength: Int = 80,
35+
var compact: js.UndefOr[Boolean | Int] = 3,
3636
var sorted: js.UndefOr[Boolean | js.Function2[String, String, Int]] = js.undefined,
37-
var getters: js.UndefOr[Boolean | String] = js.undefined)
37+
var getters: js.UndefOr[Boolean | String] = false)
3838
extends js.Object

app/current/src/main/scala/io/scalajs/nodejs/util/Util.scala

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -52,15 +52,6 @@ trait Util extends js.Object {
5252
*/
5353
def inherits(constructor: js.Any, superConstructor: js.Any): js.Any = js.native
5454

55-
/**
56-
* The util.inspect() method returns a string representation of object that is primarily useful for debugging.
57-
* Additional options may be passed that alter certain aspects of the formatted string.
58-
* @param `object` any JavaScript primitive or Object.
59-
* @param options the given [[InspectOptions inspect options]]
60-
* @example util.inspect(object[, options])
61-
*/
62-
def inspect(`object`: js.Any, options: InspectOptions = js.native): String = js.native
63-
6455
val inspect: InspectObject = js.native
6556

6657
def callbackify[T](original: js.Function): js.Function2[js.Any, T, Any] = js.native
@@ -83,7 +74,7 @@ trait Util extends js.Object {
8374
object Util extends Util
8475

8576
@js.native
86-
trait InspectObject extends js.Object {
77+
trait InspectObject extends js.Function2[js.Any, InspectOptions, String] with js.Function1[js.Any, String] {
8778
var defaultOptions: InspectOptions = js.native
8879
var styles: js.Dictionary[String] = js.native
8980

app/nodejs-v8/src/test/scala/io/scalajs/nodejs/util/UtilTest.scala

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,15 @@ package io.scalajs.nodejs.util
22

33
import org.scalatest.FunSpec
44

5+
import scala.scalajs.js
6+
57
class UtilTest extends FunSpec {
68

79
it("have inspect object") {
810
assert(Util.inspect !== null)
11+
assert(Util.inspect(js.Array(1, 2, 3)) === "[ 1, 2, 3 ]")
12+
val inspectOptions = new InspectOptions(maxArrayLength = 1)
13+
assert(Util.inspect(js.Array(1, 2, 3), inspectOptions) === "[ 1, ... 2 more items ]")
914
assert(Util.inspect.defaultOptions !== null)
1015
assert(Util.inspect.styles !== null)
1116
}

0 commit comments

Comments
 (0)