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

Deprecate helper method unrelated to nodejs #177

Merged
merged 1 commit into from
Feb 22, 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
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package io.scalajs.nodejs

import scala.scalajs.js

object TestHelper {
def isDefined(obj: js.Any): Boolean = obj != null && !js.isUndefined(obj)
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package io.scalajs.nodejs
package child_process

import io.scalajs.nodejs.buffer.Buffer
import io.scalajs.util.ScalaJsHelper._
import io.scalajs.nodejs.TestHelper._
import io.scalajs.util.NodeJSConverters._

import scala.concurrent.{ExecutionContext, Promise}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package io.scalajs.nodejs.fs

import io.scalajs.nodejs.setImmediate
import io.scalajs.util.NodeJSConverters._
import io.scalajs.util.ScalaJsHelper._
import io.scalajs.nodejs.TestHelper._

import scala.concurrent.{ExecutionContext, Promise}
import org.scalatest.funspec.AsyncFunSpec
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package io.scalajs.nodejs.os

import io.scalajs.util.ScalaJsHelper._
import io.scalajs.nodejs.TestHelper._
import org.scalatest.funspec.AnyFunSpec

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package io.scalajs.nodejs
package url

import io.scalajs.util.JSONHelper._
import org.scalatest.funspec.AnyFunSpec

import scala.scalajs.js

/**
* URLObject Tests
*/
Expand All @@ -14,7 +15,7 @@ class URLObjectTest extends AnyFunSpec {

it("should break down URLs into components") {
assert(
urlObject.toJson === "\"https://www.google.com/webhp?sourceid=chrome-instant&ion=1&espv=2&ie=UTF-8#q=node\""
js.JSON.stringify(urlObject) === "\"https://www.google.com/webhp?sourceid=chrome-instant&ion=1&espv=2&ie=UTF-8#q=node\""
)
// """{"protocol":"https:","slashes":true,"auth":null,"host":"www.google.com","port":null,"hostname":"www.google.com","hash":"#q=node","search":"?sourceid=chrome-instant&ion=1&espv=2&ie=UTF-8","query":"sourceid=chrome-instant&ion=1&espv=2&ie=UTF-8","pathname":"/webhp","path":"/webhp?sourceid=chrome-instant&ion=1&espv=2&ie=UTF-8","href":"https://www.google.com/webhp?sourceid=chrome-instant&ion=1&espv=2&ie=UTF-8#q=node"}"""
}
Expand Down
3 changes: 3 additions & 0 deletions core/src/main/scala/io/scalajs/util/DateHelper.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@ import scala.scalajs.js
/**
* Date Helper
*/
@deprecated("Unrelated to Node.js. Use your own extension method.", "v0.10.0")
object DateHelper {

/**
* Date Enrichment
* @param date0 the given [[js.Date date]]
*/
@deprecated("Unrelated to Node.js. Use your own extension method.", "v0.10.0")
implicit final class DateEnrichment(private val date0: js.Date) extends AnyVal {
@inline
def +(duration: Duration) = new js.Date(date0.getTime() + duration.toMillis)
Expand Down Expand Up @@ -39,6 +41,7 @@ object DateHelper {
* Duration Enrichment
* @param duration the given [[Duration duration]]
*/
@deprecated("Unrelated to Node.js. Use your own extension method.", "v0.10.0")
implicit final class DurationEnrichment(private val duration: Duration) extends AnyVal {
@inline
def +(date: js.Date) = new js.Date(date.getTime() + duration.toMillis)
Expand Down
4 changes: 4 additions & 0 deletions core/src/main/scala/io/scalajs/util/JSONHelper.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@ import scala.scalajs.js
/**
* JSON Helper
*/
@deprecated("Unrelated to Node.js. Use your own extension method.", "v0.10.0")
object JSONHelper {

/**
* JSON Conversions
* @param value the given JavaScript value
*/
@deprecated("Unrelated to Node.js. Use your own extension method.", "v0.10.0")
implicit final class JSONConversionsToJson[T <: js.Any](val value: T) extends AnyVal {
@inline
def toJson: String = js.JSON.stringify(value)
Expand All @@ -23,11 +25,13 @@ object JSONHelper {
* JSON Conversions
* @param text the given text string
*/
@deprecated("Unrelated to Node.js. Use your own extension method.", "v0.10.0")
implicit final class JSONConversionFromJson(val text: String) extends AnyVal {
@inline
def fromJson[T <: js.Any]: T = js.JSON.parse(text).asInstanceOf[T]
}

@deprecated("Unrelated to Node.js. Use your own extension method.", "v0.10.0")
implicit final class ScalaJsJSONEnrichment(val json: js.JSON.type) extends AnyVal {
@inline
def parseAs[T](text: String): T =
Expand Down
4 changes: 4 additions & 0 deletions core/src/main/scala/io/scalajs/util/ScalaJsHelper.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,17 @@ import scala.scalajs.js
/**
* ScalaJS Convenience Helper Functions
*/
@deprecated("Unrelated to Node.js. Use your own extension method.", "v0.10.0")
object ScalaJsHelper {
////////////////////////////////////////////////////////////////////////
// Convenience Functions
////////////////////////////////////////////////////////////////////////

@deprecated("Unrelated to Node.js. Use your own extension method.", "v0.10.0")
@inline
def die[T](message: String): T = throw new IllegalStateException(message)

@deprecated("Unrelated to Node.js. Use your own extension method.", "v0.10.0")
@inline
def isDefined(obj: js.Any): Boolean = obj != null && !js.isUndefined(obj)

Expand All @@ -24,6 +27,7 @@ object ScalaJsHelper {
* js.Dynamic to Value Extensions
* @param obj the given [[js.Dynamic object]]
*/
@deprecated("Unrelated to Node.js. Use your own extension method.", "v0.10.0")
implicit final class JsAnyExtensions(val obj: js.Any) extends AnyVal {
@inline
def asUndefOr[T]: js.UndefOr[T] = obj.asInstanceOf[js.UndefOr[T]]
Expand Down