From 390a49ff2ddf5fbfa1b5d03b32b31f2d6d0f13da Mon Sep 17 00:00:00 2001 From: Lawrence Daniels Date: Thu, 30 Mar 2017 11:58:18 -0700 Subject: [PATCH 1/4] Improved the repl binding --- .../scala/io/scalajs/nodejs/Process.scala | 2 +- .../scala/io/scalajs/nodejs/package.scala | 2 + .../scala/io/scalajs/nodejs/repl/REPL.scala | 2 +- .../io/scalajs/nodejs/repl/REPLServer.scala | 36 ++++---- .../io/scalajs/nodejs/repl/package.scala | 88 +++++++++++++++++++ 5 files changed, 112 insertions(+), 18 deletions(-) create mode 100644 src/main/scala/io/scalajs/nodejs/repl/package.scala diff --git a/src/main/scala/io/scalajs/nodejs/Process.scala b/src/main/scala/io/scalajs/nodejs/Process.scala index e00802b00..346c0634c 100644 --- a/src/main/scala/io/scalajs/nodejs/Process.scala +++ b/src/main/scala/io/scalajs/nodejs/Process.scala @@ -53,7 +53,7 @@ trait Process extends IEventEmitter { /** * An object containing the user environment. */ - def env: js.Dictionary[String] = js.native + def env: Environment = js.native /** * This is the set of Node.js-specific command line options from the executable that started the process. diff --git a/src/main/scala/io/scalajs/nodejs/package.scala b/src/main/scala/io/scalajs/nodejs/package.scala index f70401ff3..1646e31f9 100644 --- a/src/main/scala/io/scalajs/nodejs/package.scala +++ b/src/main/scala/io/scalajs/nodejs/package.scala @@ -18,6 +18,8 @@ package object nodejs { */ type FileDescriptor = Integer + type Environment = js.Dictionary[String] + ///////////////////////////////////////////////////////////////////////////////// // Built-in Properties ///////////////////////////////////////////////////////////////////////////////// diff --git a/src/main/scala/io/scalajs/nodejs/repl/REPL.scala b/src/main/scala/io/scalajs/nodejs/repl/REPL.scala index dc74c1f30..367a14a0a 100644 --- a/src/main/scala/io/scalajs/nodejs/repl/REPL.scala +++ b/src/main/scala/io/scalajs/nodejs/repl/REPL.scala @@ -18,7 +18,7 @@ import scala.scalajs.js.| trait REPL extends IEventEmitter { var REPL_MODE_SLOPPY: String = js.native var REPL_MODE_STRICT: String = js.native - var REPL_MODE_MAGIC: String = js.native + var REPL_MODE_MAGIC: String = js.native /** * @example repl.start([options]) diff --git a/src/main/scala/io/scalajs/nodejs/repl/REPLServer.scala b/src/main/scala/io/scalajs/nodejs/repl/REPLServer.scala index a3e98c2e7..a19cf7de4 100644 --- a/src/main/scala/io/scalajs/nodejs/repl/REPLServer.scala +++ b/src/main/scala/io/scalajs/nodejs/repl/REPLServer.scala @@ -15,30 +15,34 @@ trait REPLServer extends IEventEmitter with Interface { /** * The REPL's context */ - // TODO find document for this property - val context: js.Dynamic = js.native + val context: REPLContext = js.native /** - * Makes a command available in the REPL. The command is invoked by typing a . followed by the keyword. - * The cmd is an object with the following values: + * The replServer.defineCommand() method is used to add new .-prefixed commands to the REPL instance. + * Such commands are invoked by typing a period (.) followed by the keyword. The cmd is either a Function + * or an object with the following properties: * - * If a function is provided instead of an object for cmd, it is treated as the action. - * @example replServer.defineCommand(keyword, cmd) + * @param keyword The command keyword (without a leading . character). + * @param cmd The function to invoke when the command is processed. */ - def defineCommand(keyword: String, cmd: js.Any): Unit = js.native + def defineCommand(keyword: String, cmd: js.Function0[Any]): Unit = js.native /** - * Like readline.prompt except also adding indents with ellipses when inside blocks. The preserveCursor argument - * is passed to readline.prompt. This is used primarily with defineCommand. It's also used internally to render - * each prompt line. - * @example replServer.displayPrompt([preserveCursor]) - * @see [[prompt()]] + * The replServer.displayPrompt() method readies the REPL instance for input from the user, printing the + * configured prompt to a new line in the output and resuming the input to accept new input. + * + * When multi-line input is being entered, an ellipsis is printed rather than the 'prompt'. + * * + * When preserveCursor is true, the cursor placement will not be reset to 0. + * + * The replServer.displayPrompt method is primarily intended to be called from within the action function + * for commands registered using the replServer.defineCommand() method. + * @param preserveCursor indicates whether to preserver the cursor (position?) */ - def displayPrompt(preserveCursor: Boolean): Unit = js.native + def displayPrompt(preserveCursor: Boolean = js.native): Unit = js.native /** * Like readline.prompt except also adding indents with ellipses when inside blocks. The preserveCursor argument diff --git a/src/main/scala/io/scalajs/nodejs/repl/package.scala b/src/main/scala/io/scalajs/nodejs/repl/package.scala new file mode 100644 index 000000000..a73c36111 --- /dev/null +++ b/src/main/scala/io/scalajs/nodejs/repl/package.scala @@ -0,0 +1,88 @@ +package io.scalajs.nodejs + +import scala.scalajs.js + +/** + * repl package object + * @author lawrence.daniels@gmail.com + */ +package object repl { + + type REPLContext = js.Dynamic + + /** + * REPL Server events + * @param server the given [[REPLServer instance]] + */ + final implicit class REPLServerEvents(val server: REPLServer) extends AnyVal { + + @inline + def contextAs[T]: T = server.context.asInstanceOf[T] + + /** + * The 'exit' event is emitted when the REPL is exited either by receiving the .exit command as input, + * the user pressing CTRL-C twice to signal SIGINT, or by pressing CTRL-D to signal 'end' on the input stream. + * The listener callback is invoked without any arguments. + * @param listener The listener callback + */ + @inline + def onExit(listener: () => Any): server.type = server.on("exit", listener) + + /** + * The 'reset' event is emitted when the REPL's context is reset. This occurs whenever the .clear command + * is received as input unless the REPL is using the default evaluator and the repl.REPLServer instance + * was created with the useGlobal option set to true. The listener callback will be called with a reference + * to the context object as the only argument. + * @param listener The listener callback + */ + @inline + def onReset(listener: REPLContext => Any): server.type = server.on("reset", listener) + + } + + /** + * Various behaviors of the Node.js REPL can be customized using the following environment variables: + * + */ + final implicit class EnvironmentVariableOptions(val env: Environment) extends AnyVal { + + /** + * When a valid path is given, persistent REPL history will be saved to the specified file rather + * than .node_repl_history in the user's home directory. Setting this value to "" will disable persistent + * REPL history. Whitespace will be trimmed from the value. + */ + @inline + def NODE_REPL_HISTORY: Option[String] = env.get("NODE_REPL_HISTORY") + + /** + * Previously in Node.js/io.js v2.x, REPL history was controlled by using a NODE_REPL_HISTORY_FILE environment + * variable, and the history was saved in JSON format. This variable has now been deprecated, and the old + * JSON REPL history file will be automatically converted to a simplified plain text format. This new file + * will be saved to either the user's home directory, or a directory defined by the NODE_REPL_HISTORY variable, + * as documented in the Environment Variable Options. + */ + @inline + @deprecated("Use NODE_REPL_HISTORY instead.", since = "3.0.0") + def NODE_REPL_HISTORY_FILE: Option[String] = env.get("NODE_REPL_HISTORY_FILE") + + /** + * Defaults to 1000. Controls how many lines of history will be persisted if history is available. + * Must be a positive number. + */ + @inline + def NODE_REPL_HISTORY_SIZE: Option[Int] = env.get("NODE_REPL_HISTORY_SIZE").map(_.toInt) + + /** + * May be any of sloppy, strict, or magic. Defaults to magic, which will automatically run "strict mode only" + * statements in strict mode. + */ + @inline + def NODE_REPL_MODE: Option[String] = env.get("NODE_REPL_MODE") + + } + +} From 8a3fa387dab122f7805d70ff317c08070acebc3c Mon Sep 17 00:00:00 2001 From: Lawrence Daniels Date: Thu, 6 Apr 2017 22:33:48 -0700 Subject: [PATCH 2/4] Pre-release v0.4.0-pre3: Miscellaneous fixes in OS and Stream packages --- README.md | 10 +++--- build.sbt | 2 +- package.json | 2 +- .../scala/io/scalajs/nodejs/os/CPUInfo.scala | 6 ++-- src/main/scala/io/scalajs/nodejs/os/OS.scala | 2 +- .../scala/io/scalajs/nodejs/os/package.scala | 22 +++++++++++++ .../io/scalajs/nodejs/stream/Writable.scala | 32 +++++-------------- src/test/resources/watchfile.json | 2 +- 8 files changed, 42 insertions(+), 36 deletions(-) create mode 100644 src/main/scala/io/scalajs/nodejs/os/package.scala diff --git a/README.md b/README.md index 8e50d113e..4bee6f196 100644 --- a/README.md +++ b/README.md @@ -76,9 +76,9 @@ The following applications were developed using ScalaJs.io: | Application | Frontend | Backend | Scalajs.io version | Description | |------------------------------------------------------------------------|-----------------------|--------------------|--------------------|------------------------------------------| | [Phaser-Invaders](https://github.com/scalajs-io/phaser-invaders-demo) | Scala.js + DOM | Scala + NodeJS | 0.3.0.1 | Port of Phaser Invaders. | -| [Socialize](https://github.com/ldaniels528/scalajs-nodejs-socialized) | Scala.js + AngularJS | Scala.js + NodeJS | 0.3.0.3 | A Facebook-inspired Social networking web application. | -| [Todo MVC](https://github.com/ldaniels528/scalajs-nodejs-todomvc) | Scala.js + AngularJS | Scala.js + NodeJS | 0.2.3.1 | A simple Todo example application. | -| [Trifecta](https://github.com/ldaniels528/trifecta) | Scala.js + AngularJS | Scala + Play 2.4.x | 0.3.0.0 | Trifecta is a web-based and CLI tool that simplifies inspecting Kafka messages and Zookeeper data. | +| [Socialize](https://github.com/scalajs-io/scalajs-nodejs-socialized) | Scala.js + AngularJS | Scala.js + NodeJS | 0.3.0.3 | A Facebook-inspired Social networking web application. | +| [Todo MVC](https://github.com/scalajs-io/scalajs-nodejs-todomvc) | Scala.js + AngularJS | Scala.js + NodeJS | 0.2.3.1 | A simple Todo example application. | +| [Trifecta](https://github.com/scalajs-io/trifecta) | Scala.js + AngularJS | Scala + Play 2.4.x | 0.3.0.0 | Trifecta is a web-based and CLI tool that simplifies inspecting Kafka messages and Zookeeper data. | ### The MEAN Stack — AngularJS, MongoDB, Mongoose, Express and more @@ -231,7 +231,7 @@ The following core Node.js modules (v7.7.1) have been implemented: | vm | The vm module provides APIs for compiling and running code within V8 Virtual Machine contexts.| | zlib | This provides bindings to Gzip/Gunzip, Deflate/Inflate, and DeflateRaw/InflateRaw classes. | -*NOTE*: The SBT artifact for the complete Node.js platform is: "io.scalajs.npm" %%% "nodejs" % "0.4.0-pre2" +*NOTE*: The SBT artifact for the complete Node.js platform is: "io.scalajs.npm" %%% "nodejs" % "0.4.0-pre3" #### Third-party Modules @@ -298,7 +298,7 @@ The following Third Party/OSS Node.js (npm) modules have been implemented: | [winston-daily-rotate-file](https://github.com/scalajs-io/winston-daily-rotate-file) | 1.4.4 | A multi-transport async logging library for Node.js. | | [xml2js](https://github.com/scalajs-io/xml2js) | 0.4.16 | Simple XML to JavaScript object converter. | -*NOTE*: The full SBT artifact expression is: "io.scalajs.npm" %%% "xxxx" % version (e.g. "io.scalajs.npm" %%% "express" % "0.4.0-pre2") +*NOTE*: The full SBT artifact expression is: "io.scalajs.npm" %%% "xxxx" % version (e.g. "io.scalajs.npm" %%% "express" % "0.4.0-pre3") I've provided an example to demonstrate how similar the Scala.js code is to the JavaScript that it replaces. diff --git a/build.sbt b/build.sbt index f9990cb60..51701c9a0 100644 --- a/build.sbt +++ b/build.sbt @@ -5,7 +5,7 @@ import sbt._ import scala.language.postfixOps -val scalaJsIOVersion = "0.4.0-pre2" +val scalaJsIOVersion = "0.4.0-pre3" val apiVersion = scalaJsIOVersion val scalaJsVersion = "2.12.1" diff --git a/package.json b/package.json index 5ace53cce..4cf63de2a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "nodejs-sfs", - "version": "0.4.0-pre2", + "version": "0.4.0-pre3", "private": true, "dependencies": { "source-map": "^0.5.6" diff --git a/src/main/scala/io/scalajs/nodejs/os/CPUInfo.scala b/src/main/scala/io/scalajs/nodejs/os/CPUInfo.scala index fdc83edfb..b147f317d 100644 --- a/src/main/scala/io/scalajs/nodejs/os/CPUInfo.scala +++ b/src/main/scala/io/scalajs/nodejs/os/CPUInfo.scala @@ -8,7 +8,7 @@ import scala.scalajs.js */ @js.native trait CPUInfo extends js.Object { - var model: String = js.native - var speed: Double = js.native - var times: js.Array[CPUTime] = js.native + var model: String = js.native + var speed: Double = js.native + var times: js.Dictionary[Double] = js.native } diff --git a/src/main/scala/io/scalajs/nodejs/os/OS.scala b/src/main/scala/io/scalajs/nodejs/os/OS.scala index c1851a657..c1468645f 100644 --- a/src/main/scala/io/scalajs/nodejs/os/OS.scala +++ b/src/main/scala/io/scalajs/nodejs/os/OS.scala @@ -50,7 +50,7 @@ trait OS extends js.Object { * spent in: user, nice, sys, idle, and irq). * @example os.cpus() */ - def cpus(): js.Array[js.Any] = js.native + def cpus(): js.Array[CPUInfo] = js.native /** * Returns the endianness of the CPU. Possible values are 'BE' for big endian or 'LE' for little endian. diff --git a/src/main/scala/io/scalajs/nodejs/os/package.scala b/src/main/scala/io/scalajs/nodejs/os/package.scala new file mode 100644 index 000000000..3ee8b907c --- /dev/null +++ b/src/main/scala/io/scalajs/nodejs/os/package.scala @@ -0,0 +1,22 @@ +package io.scalajs.nodejs + +import scala.scalajs.js + +/** + * os package object + * @author lawrence.daniels@gmail.com + */ +package object os { + + /** + * CPU Info Enrichment + * @param cpuInfo the given [[CPUInfo CPU Info]] + */ + final implicit class CPUInfoEnrichment(val cpuInfo: CPUInfo) extends AnyVal { + + @inline + def timesObject: js.Array[CPUTime] = cpuInfo.times.asInstanceOf[js.Array[CPUTime]] + + } + +} diff --git a/src/main/scala/io/scalajs/nodejs/stream/Writable.scala b/src/main/scala/io/scalajs/nodejs/stream/Writable.scala index bd625c506..46b9e38f3 100644 --- a/src/main/scala/io/scalajs/nodejs/stream/Writable.scala +++ b/src/main/scala/io/scalajs/nodejs/stream/Writable.scala @@ -1,9 +1,10 @@ package io.scalajs.nodejs package stream +import io.scalajs.util.PromiseHelper._ +import io.scalajs.util.PromiseHelper.Implicits._ import io.scalajs.nodejs.buffer.Buffer import io.scalajs.nodejs.events.IEventEmitter -import io.scalajs.util.PromiseHelper._ import scala.concurrent.Promise import scala.scalajs.js @@ -143,24 +144,9 @@ trait Writable extends IEventEmitter { * @return true, if the data was handled completely * @example writable.write(chunk[, encoding][, callback]) */ - def write(chunk: String, encoding: String, callback: js.Function1[Error, Any]): Boolean = js.native - - /** - * Flush all data, buffered since stream.cork() call. - * @param chunk The data to write ( | ) - * @param callback the Callback for when this chunk of data is flushed - * @return true, if the data was handled completely - * @example writable.write(chunk[, encoding][, callback]) - */ - def write(chunk: String, callback: js.Function1[Error, Any]): Boolean = js.native - - /** - * Flush all data, buffered since stream.cork() call. - * @param chunk The data to write ( | ) - * @return true, if the data was handled completely - * @example writable.write(chunk[, encoding][, callback]) - */ - def write(chunk: Buffer, callback: js.Function1[Error, Any]): Boolean = js.native + def write(chunk: Buffer | String, + encoding: String = js.native, + callback: js.Function1[Error, Any] = js.native): Boolean = js.native } @@ -237,10 +223,7 @@ object Writable { def endAsync(): Promise[Unit] = promiseWithError0[Error](writable.end) @inline - def writeAsync(chunk: Buffer): Promise[Unit] = promiseWithError0[Error](writable.write(chunk, _)) - - @inline - def writeAsync(chunk: String, encoding: String = null): Promise[Unit] = { + def writeAsync(chunk: Buffer | String, encoding: String = null): Promise[Unit] = { promiseWithError0[Error](writable.write(chunk, encoding, _)) } @@ -254,5 +237,6 @@ object Writable { * @param encoding the data's optional encoding */ @ScalaJSDefined -class Chunk(val chunk: Buffer | String, val encoding: js.UndefOr[String] = js.undefined) +class Chunk(val chunk: Buffer | String, + val encoding: js.UndefOr[String] = js.undefined) extends js.Object \ No newline at end of file diff --git a/src/test/resources/watchfile.json b/src/test/resources/watchfile.json index 4021e01a8..1c716fb56 100644 --- a/src/test/resources/watchfile.json +++ b/src/test/resources/watchfile.json @@ -1,6 +1,6 @@ { "name": "scalajs-io", - "version": "0.4.0-pre2", + "version": "0.4.0-pre3", "private": true, "dependencies": { "async": "^2.0.1", From 495832469f4a9feceb8979feb7426f0bcd02e16d Mon Sep 17 00:00:00 2001 From: Lawrence Daniels Date: Sun, 16 Apr 2017 10:08:30 -0700 Subject: [PATCH 3/4] =?UTF-8?q?Continued=20development=201.=20Added=20puny?= =?UTF-8?q?=20code=20(although=20it=E2=80=99s=20deprecated)=202.=20Fixes?= =?UTF-8?q?=20on=20stream.Writable=20class=203.=20Fixes=20for=20setInterva?= =?UTF-8?q?l=20function=204.=20Fixed=20issue=20with=20process.hrtime()?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 6 +- build.sbt | 2 +- package.json | 2 +- .../scala/io/scalajs/nodejs/Process.scala | 4 +- src/main/scala/io/scalajs/nodejs/fs/Fs.scala | 2 +- .../io/scalajs/nodejs/punycode/Punycode.scala | 87 +++++++++++++++++++ .../io/scalajs/nodejs/stream/Writable.scala | 29 +++++-- .../nodejs/timers/ClearImmediate.scala | 5 +- .../scalajs/nodejs/timers/ClearInterval.scala | 4 +- .../scalajs/nodejs/timers/ClearTimeout.scala | 4 +- .../io/scalajs/nodejs/timers/Interval.scala | 50 ----------- .../scalajs/nodejs/timers/SetInterval.scala | 2 +- .../io/scalajs/nodejs/timers/Timeout.scala | 6 +- src/test/resources/watchfile.json | 2 +- 14 files changed, 130 insertions(+), 75 deletions(-) create mode 100644 src/main/scala/io/scalajs/nodejs/punycode/Punycode.scala delete mode 100644 src/main/scala/io/scalajs/nodejs/timers/Interval.scala diff --git a/README.md b/README.md index 4bee6f196..ff035602e 100644 --- a/README.md +++ b/README.md @@ -101,7 +101,7 @@ The following applications were developed using ScalaJs.io: | [mongoose](https://github.com/scalajs-io/mongoose) | 4.8.1 | Mongoose is a MongoDB object modeling tool designed to work in an asynchronous environment. | | [mpromise](https://github.com/scalajs-io/mpromise) | 0.5.5 | A promises/A+ conformant implementation, written for mongoose. | -Looking for a complete list of available bindings? Go [here](https://github.com/scalajs-io/scalajs.io-platform) +Looking for a complete list of available bindings? Go [here](https://github.com/scalajs-io/scalajs-io-platform) ### Discussions @@ -231,7 +231,7 @@ The following core Node.js modules (v7.7.1) have been implemented: | vm | The vm module provides APIs for compiling and running code within V8 Virtual Machine contexts.| | zlib | This provides bindings to Gzip/Gunzip, Deflate/Inflate, and DeflateRaw/InflateRaw classes. | -*NOTE*: The SBT artifact for the complete Node.js platform is: "io.scalajs.npm" %%% "nodejs" % "0.4.0-pre3" +*NOTE*: The SBT artifact for the complete Node.js platform is: "io.scalajs.npm" %%% "nodejs" % "0.4.0-pre4" #### Third-party Modules @@ -298,7 +298,7 @@ The following Third Party/OSS Node.js (npm) modules have been implemented: | [winston-daily-rotate-file](https://github.com/scalajs-io/winston-daily-rotate-file) | 1.4.4 | A multi-transport async logging library for Node.js. | | [xml2js](https://github.com/scalajs-io/xml2js) | 0.4.16 | Simple XML to JavaScript object converter. | -*NOTE*: The full SBT artifact expression is: "io.scalajs.npm" %%% "xxxx" % version (e.g. "io.scalajs.npm" %%% "express" % "0.4.0-pre3") +*NOTE*: The full SBT artifact expression is: "io.scalajs.npm" %%% "xxxx" % version (e.g. "io.scalajs.npm" %%% "express" % "0.4.0-pre4") I've provided an example to demonstrate how similar the Scala.js code is to the JavaScript that it replaces. diff --git a/build.sbt b/build.sbt index 51701c9a0..f717fe9e3 100644 --- a/build.sbt +++ b/build.sbt @@ -5,7 +5,7 @@ import sbt._ import scala.language.postfixOps -val scalaJsIOVersion = "0.4.0-pre3" +val scalaJsIOVersion = "0.4.0-pre4" val apiVersion = scalaJsIOVersion val scalaJsVersion = "2.12.1" diff --git a/package.json b/package.json index 4cf63de2a..cd6a8bf29 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "nodejs-sfs", - "version": "0.4.0-pre3", + "version": "0.4.0-pre4", "private": true, "dependencies": { "source-map": "^0.5.6" diff --git a/src/main/scala/io/scalajs/nodejs/Process.scala b/src/main/scala/io/scalajs/nodejs/Process.scala index e00802b00..87fc54098 100644 --- a/src/main/scala/io/scalajs/nodejs/Process.scala +++ b/src/main/scala/io/scalajs/nodejs/Process.scala @@ -245,9 +245,9 @@ trait Process extends IEventEmitter { * Returns the current high-resolution real time in a [seconds, nanoseconds] tuple Array. It is relative to an * arbitrary time in the past. It is not related to the time of day and therefore not subject to clock drift. * The primary use is for measuring performance between intervals. - * @example process.hrtime() + * @example process.hrtime([time]) */ - def hrtime(): js.Array[Int] = js.native + def hrtime(time: js.Array[Int] = js.native): js.Array[Int] = js.native /** * Reads /etc/group and initializes the group access list, using all groups of which the user is a member. diff --git a/src/main/scala/io/scalajs/nodejs/fs/Fs.scala b/src/main/scala/io/scalajs/nodejs/fs/Fs.scala index eb3e1b178..51f67db83 100644 --- a/src/main/scala/io/scalajs/nodejs/fs/Fs.scala +++ b/src/main/scala/io/scalajs/nodejs/fs/Fs.scala @@ -674,7 +674,7 @@ trait Fs extends IEventEmitter { * data will be read from the current file position. * @return the number of bytesRead. */ - def readSync(fd: FileDescriptor, buffer: Buffer, offset: Int, length: Int, position: Int): Buffer = js.native + def readSync(fd: FileDescriptor, buffer: Buffer, offset: Int, length: Int, position: Int): Int = js.native /** * Asynchronous readdir(3). Reads the contents of a directory. diff --git a/src/main/scala/io/scalajs/nodejs/punycode/Punycode.scala b/src/main/scala/io/scalajs/nodejs/punycode/Punycode.scala new file mode 100644 index 000000000..f1c30a048 --- /dev/null +++ b/src/main/scala/io/scalajs/nodejs/punycode/Punycode.scala @@ -0,0 +1,87 @@ +package io.scalajs.nodejs.punycode + +import scala.scalajs.js +import scala.scalajs.js.annotation.JSImport + +/** + * The version of the punycode module bundled in Node.js is being deprecated. In a future major version of Node.js + * this module will be removed. Users currently depending on the punycode module should switch to using the + * userland-provided Punycode.js module instead. + * @see https://nodejs.org/dist/latest-v7.x/docs/api/punycode.html + */ +@js.native +trait Punycode extends js.Object { + + /** + * The punycode.decode() method converts a Punycode string of ASCII-only characters to the equivalent + * string of Unicode codepoints. + * @param string a Punycode string of ASCII-only characters + * @return the equivalent string of Unicode codepoints. + */ + def decode(string: String): String = js.native + + /** + * The punycode.encode() method converts a string of Unicode codepoints to a Punycode string of ASCII-only characters. + * @param codePoints a string of Unicode codepoints + * @return a Punycode string of ASCII-only characters. + */ + def encode(codePoints: String): String = js.native + + /** + * The punycode.toASCII() method converts a Unicode string representing an Internationalized Domain Name to Punycode. + * Only the non-ASCII parts of the domain name will be converted. Calling punycode.toASCII() on a string that already + * only contains ASCII characters will have no effect. + * @param domain the domain name + * @return a Unicode string representing an Internationalized Domain Name as Punycode + */ + def toASCII(domain: String): String = js.native + + /** + * The punycode.toUnicode() method converts a string representing a domain name containing Punycode encoded + * characters into Unicode. Only the Punycode encoded parts of the domain name are be converted. + * @param domain a string representing a domain name containing Punycode encoded characters + * @return the Unicode string + */ + def toUnicode(domain: String): String = js.native + + /** + * The UCS2 object + * @return The [[UCS2 UCS2]] object + */ + def ucs2: UCS2 = js.native + + /** + * Returns a string identifying the current Punycode.js version number. + * @return a string identifying the current Punycode.js version number. + */ + def version: String = js.native + +} + +/** + * Punycode.UCS2 + * @see https://nodejs.org/dist/latest-v7.x/docs/api/punycode.html + */ +@js.native +trait UCS2 extends js.Object { + + /** + * The punycode.ucs2.decode() method returns an array containing the numeric codepoint values of each Unicode + * symbol in the string. + * @param string the string containing Unicode symbols + * @return an array containing the numeric codepoint values of each Unicode symbol + */ + def decode(string: String): js.Array[Int] = js.native + + /** + * The punycode.ucs2.encode() method returns a string based on an array of numeric code point values. + * @param codePoints an array of numeric code point values + * @return a string based on an array of numeric code point values + */ + def encode(codePoints: js.Array[Int]): String = js.native + +} + +@js.native +@JSImport("punycode", JSImport.Namespace) +object Punycode extends Punycode diff --git a/src/main/scala/io/scalajs/nodejs/stream/Writable.scala b/src/main/scala/io/scalajs/nodejs/stream/Writable.scala index 46b9e38f3..567d6fe16 100644 --- a/src/main/scala/io/scalajs/nodejs/stream/Writable.scala +++ b/src/main/scala/io/scalajs/nodejs/stream/Writable.scala @@ -1,10 +1,9 @@ package io.scalajs.nodejs package stream -import io.scalajs.util.PromiseHelper._ -import io.scalajs.util.PromiseHelper.Implicits._ import io.scalajs.nodejs.buffer.Buffer import io.scalajs.nodejs.events.IEventEmitter +import io.scalajs.util.PromiseHelper._ import scala.concurrent.Promise import scala.scalajs.js @@ -136,6 +135,24 @@ trait Writable extends IEventEmitter { */ def uncork(): Unit = js.native + /** + * Flush all data, buffered since stream.cork() call. + * @param chunk The data to write ( | ) + * @param callback the Callback for when this chunk of data is flushed + * @return true, if the data was handled completely + * @example writable.write(chunk[, encoding][, callback]) + */ + def write(chunk: Buffer | String, callback: js.Function1[Error, Any] = js.native): Boolean = js.native + + /** + * Flush all data, buffered since stream.cork() call. + * @param chunk The data to write ( | ) + * @param encoding The encoding, if chunk is a String + * @return true, if the data was handled completely + * @example writable.write(chunk[, encoding][, callback]) + */ + def write(chunk: Buffer | String, encoding: String): Boolean = js.native + /** * Flush all data, buffered since stream.cork() call. * @param chunk The data to write ( | ) @@ -145,8 +162,8 @@ trait Writable extends IEventEmitter { * @example writable.write(chunk[, encoding][, callback]) */ def write(chunk: Buffer | String, - encoding: String = js.native, - callback: js.Function1[Error, Any] = js.native): Boolean = js.native + encoding: String, + callback: js.Function1[Error, Any]): Boolean = js.native } @@ -160,7 +177,7 @@ object Writable { * Writable Events * @author lawrence.daniels@gmail.com */ - implicit class WritableEvents(val writable: Writable) extends AnyVal { + implicit class WritableEvents[T <: Writable](val writable: T) extends AnyVal { /** * Emitted when the stream and any of its underlying resources (a file descriptor, for example) have been closed. @@ -209,7 +226,7 @@ object Writable { * Writable Extensions * @author lawrence.daniels@gmail.com */ - implicit class WritableExtensions(val writable: Writable) extends AnyVal { + implicit class WritableExtensions[T <: Writable](val writable: T) extends AnyVal { @inline def endAsync(chunk: Buffer): Promise[Unit] = promiseWithError0[Error](writable.end(chunk, _)) diff --git a/src/main/scala/io/scalajs/nodejs/timers/ClearImmediate.scala b/src/main/scala/io/scalajs/nodejs/timers/ClearImmediate.scala index 461459fbe..97ed517d0 100644 --- a/src/main/scala/io/scalajs/nodejs/timers/ClearImmediate.scala +++ b/src/main/scala/io/scalajs/nodejs/timers/ClearImmediate.scala @@ -10,9 +10,10 @@ import scala.scalajs.js trait ClearImmediate extends js.Object { /** - * Stops an immediateObject, as created by setImmediate, from triggering. + * Stops an immediate, as created by setImmediate, from triggering. + * @param handle the immediate handle * @example clearImmediate(immediateObject) */ - def apply(immediateObject: Immediate): Unit = js.native + def apply(handle: Immediate): Unit = js.native } diff --git a/src/main/scala/io/scalajs/nodejs/timers/ClearInterval.scala b/src/main/scala/io/scalajs/nodejs/timers/ClearInterval.scala index b5289e3de..0725847b9 100644 --- a/src/main/scala/io/scalajs/nodejs/timers/ClearInterval.scala +++ b/src/main/scala/io/scalajs/nodejs/timers/ClearInterval.scala @@ -10,9 +10,9 @@ import scala.scalajs.js trait ClearInterval extends js.Object { /** - * Stops an intervalObject, as created by setInterval, from triggering. + * Stops an interval, as created by setInterval, from triggering. * @example clearInterval(intervalObject) */ - def apply(intervalObject: Interval): Unit = js.native + def apply(handle: Timeout): Unit = js.native } diff --git a/src/main/scala/io/scalajs/nodejs/timers/ClearTimeout.scala b/src/main/scala/io/scalajs/nodejs/timers/ClearTimeout.scala index 5bf853408..4dc92f456 100644 --- a/src/main/scala/io/scalajs/nodejs/timers/ClearTimeout.scala +++ b/src/main/scala/io/scalajs/nodejs/timers/ClearTimeout.scala @@ -10,9 +10,9 @@ import scala.scalajs.js trait ClearTimeout extends js.Object { /** - * Prevents a timeoutObject, as created by setTimeout, from triggering. + * Prevents a timeout, as created by setTimeout, from triggering. * @example clearTimeout(timeoutObject) */ - def apply(timeoutObject: Timeout): Unit = js.native + def apply(handle: Timeout): Unit = js.native } diff --git a/src/main/scala/io/scalajs/nodejs/timers/Interval.scala b/src/main/scala/io/scalajs/nodejs/timers/Interval.scala deleted file mode 100644 index 1198ff49f..000000000 --- a/src/main/scala/io/scalajs/nodejs/timers/Interval.scala +++ /dev/null @@ -1,50 +0,0 @@ -package io.scalajs.nodejs.timers - -import io.scalajs.nodejs.clearInterval - -import scala.scalajs.js - -/** - * Interval Handle - * @author lawrence.daniels@gmail.com - */ -@js.native -trait Interval extends Timeout { - - def _idleStart: js.UndefOr[Int] = js.native - - def _idleTimeout: js.UndefOr[Int] = js.native - - def _idlePrev: Interval.TimerList = js.native - -} - -/** - * Interval Companion - * @author lawrence.daniels@gmail.com - */ -object Interval { - - @js.native - trait TimerList extends js.Object { - - def _timer: SetTimeout = js.native - - def _unrefed: js.UndefOr[Boolean] = js.native - - def msecs: js.UndefOr[Int] = js.native - - } - - /** - * Interval Enrichment - * @param interval the given [[Interval interval]] handle - */ - implicit class IntervalEnrichment(val interval: Interval) extends AnyVal { - - @inline - def clear(): Unit = clearInterval(interval) - - } - -} diff --git a/src/main/scala/io/scalajs/nodejs/timers/SetInterval.scala b/src/main/scala/io/scalajs/nodejs/timers/SetInterval.scala index ee51d7b2d..2f7d5958c 100644 --- a/src/main/scala/io/scalajs/nodejs/timers/SetInterval.scala +++ b/src/main/scala/io/scalajs/nodejs/timers/SetInterval.scala @@ -18,6 +18,6 @@ trait SetInterval extends js.Object { * or less than 1, Node.js will use 1 as the delay. * @example setInterval(callback, delay[, arg][, ...]) */ - def apply(callback: js.Function, delay: Int, args: js.Any*): Interval = js.native + def apply(callback: js.Function, delay: Int, args: js.Any*): Timeout = js.native } diff --git a/src/main/scala/io/scalajs/nodejs/timers/Timeout.scala b/src/main/scala/io/scalajs/nodejs/timers/Timeout.scala index dd9fa7a22..c5f18b4f2 100644 --- a/src/main/scala/io/scalajs/nodejs/timers/Timeout.scala +++ b/src/main/scala/io/scalajs/nodejs/timers/Timeout.scala @@ -27,12 +27,12 @@ object Timeout { /** * Timeout Enrichment - * @param Timeout the given [[Timeout Timeout]] handle + * @param handle the given [[Timeout timeout]] handle */ - implicit class TimeoutEnrichment(val Timeout: Timeout) extends AnyVal { + implicit class TimeoutEnrichment(val handle: Timeout) extends AnyVal { @inline - def clear(): Unit = clearTimeout(Timeout) + def clear(): Unit = clearTimeout(handle) } diff --git a/src/test/resources/watchfile.json b/src/test/resources/watchfile.json index 1c716fb56..a74559b4e 100644 --- a/src/test/resources/watchfile.json +++ b/src/test/resources/watchfile.json @@ -1,6 +1,6 @@ { "name": "scalajs-io", - "version": "0.4.0-pre3", + "version": "0.4.0-pre4", "private": true, "dependencies": { "async": "^2.0.1", From 5a37777b8012b78c78efaf0bf3c70d518abf678b Mon Sep 17 00:00:00 2001 From: Lawrence Daniels Date: Tue, 18 Apr 2017 18:06:00 -0700 Subject: [PATCH 4/4] Fixed SBT dependency --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index ff035602e..58f7a00f0 100644 --- a/README.md +++ b/README.md @@ -231,7 +231,7 @@ The following core Node.js modules (v7.7.1) have been implemented: | vm | The vm module provides APIs for compiling and running code within V8 Virtual Machine contexts.| | zlib | This provides bindings to Gzip/Gunzip, Deflate/Inflate, and DeflateRaw/InflateRaw classes. | -*NOTE*: The SBT artifact for the complete Node.js platform is: "io.scalajs.npm" %%% "nodejs" % "0.4.0-pre4" +*NOTE*: The SBT artifact for the complete Node.js platform is: "io.scalajs" %%% "nodejs" % "0.4.0-pre4" #### Third-party Modules