Skip to content

Commit 4958324

Browse files
committed
Continued development
1. Added puny code (although it’s deprecated) 2. Fixes on stream.Writable class 3. Fixes for setInterval function 4. Fixed issue with process.hrtime()
1 parent 8a3fa38 commit 4958324

File tree

14 files changed

+130
-75
lines changed

14 files changed

+130
-75
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ The following applications were developed using ScalaJs.io:
101101
| [mongoose](https://github.com/scalajs-io/mongoose) | 4.8.1 | Mongoose is a MongoDB object modeling tool designed to work in an asynchronous environment. |
102102
| [mpromise](https://github.com/scalajs-io/mpromise) | 0.5.5 | A promises/A+ conformant implementation, written for mongoose. |
103103

104-
Looking for a complete list of available bindings? Go [here](https://github.com/scalajs-io/scalajs.io-platform)
104+
Looking for a complete list of available bindings? Go [here](https://github.com/scalajs-io/scalajs-io-platform)
105105

106106
<a name="discussions"></a>
107107
### Discussions
@@ -231,7 +231,7 @@ The following core Node.js modules (v7.7.1) have been implemented:
231231
| vm | The vm module provides APIs for compiling and running code within V8 Virtual Machine contexts.|
232232
| zlib | This provides bindings to Gzip/Gunzip, Deflate/Inflate, and DeflateRaw/InflateRaw classes. |
233233

234-
*NOTE*: The SBT artifact for the complete Node.js platform is: "io.scalajs.npm" %%% "nodejs" % "0.4.0-pre3"
234+
*NOTE*: The SBT artifact for the complete Node.js platform is: "io.scalajs.npm" %%% "nodejs" % "0.4.0-pre4"
235235

236236
<a name="npm_modules">
237237
#### Third-party Modules
@@ -298,7 +298,7 @@ The following Third Party/OSS Node.js (npm) modules have been implemented:
298298
| [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. |
299299
| [xml2js](https://github.com/scalajs-io/xml2js) | 0.4.16 | Simple XML to JavaScript object converter. |
300300

301-
*NOTE*: The full SBT artifact expression is: "io.scalajs.npm" %%% "xxxx" % version (e.g. "io.scalajs.npm" %%% "express" % "0.4.0-pre3")
301+
*NOTE*: The full SBT artifact expression is: "io.scalajs.npm" %%% "xxxx" % version (e.g. "io.scalajs.npm" %%% "express" % "0.4.0-pre4")
302302

303303
I've provided an example to demonstrate how similar the Scala.js code is to the JavaScript
304304
that it replaces.

build.sbt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import sbt._
55

66
import scala.language.postfixOps
77

8-
val scalaJsIOVersion = "0.4.0-pre3"
8+
val scalaJsIOVersion = "0.4.0-pre4"
99
val apiVersion = scalaJsIOVersion
1010
val scalaJsVersion = "2.12.1"
1111

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "nodejs-sfs",
3-
"version": "0.4.0-pre3",
3+
"version": "0.4.0-pre4",
44
"private": true,
55
"dependencies": {
66
"source-map": "^0.5.6"

src/main/scala/io/scalajs/nodejs/Process.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -245,9 +245,9 @@ trait Process extends IEventEmitter {
245245
* Returns the current high-resolution real time in a [seconds, nanoseconds] tuple Array. It is relative to an
246246
* arbitrary time in the past. It is not related to the time of day and therefore not subject to clock drift.
247247
* The primary use is for measuring performance between intervals.
248-
* @example process.hrtime()
248+
* @example process.hrtime([time])
249249
*/
250-
def hrtime(): js.Array[Int] = js.native
250+
def hrtime(time: js.Array[Int] = js.native): js.Array[Int] = js.native
251251

252252
/**
253253
* Reads /etc/group and initializes the group access list, using all groups of which the user is a member.

src/main/scala/io/scalajs/nodejs/fs/Fs.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -674,7 +674,7 @@ trait Fs extends IEventEmitter {
674674
* data will be read from the current file position.
675675
* @return the number of bytesRead.
676676
*/
677-
def readSync(fd: FileDescriptor, buffer: Buffer, offset: Int, length: Int, position: Int): Buffer = js.native
677+
def readSync(fd: FileDescriptor, buffer: Buffer, offset: Int, length: Int, position: Int): Int = js.native
678678

679679
/**
680680
* Asynchronous readdir(3). Reads the contents of a directory.
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
package io.scalajs.nodejs.punycode
2+
3+
import scala.scalajs.js
4+
import scala.scalajs.js.annotation.JSImport
5+
6+
/**
7+
* The version of the punycode module bundled in Node.js is being deprecated. In a future major version of Node.js
8+
* this module will be removed. Users currently depending on the punycode module should switch to using the
9+
* userland-provided Punycode.js module instead.
10+
* @see https://nodejs.org/dist/latest-v7.x/docs/api/punycode.html
11+
*/
12+
@js.native
13+
trait Punycode extends js.Object {
14+
15+
/**
16+
* The punycode.decode() method converts a Punycode string of ASCII-only characters to the equivalent
17+
* string of Unicode codepoints.
18+
* @param string a Punycode string of ASCII-only characters
19+
* @return the equivalent string of Unicode codepoints.
20+
*/
21+
def decode(string: String): String = js.native
22+
23+
/**
24+
* The punycode.encode() method converts a string of Unicode codepoints to a Punycode string of ASCII-only characters.
25+
* @param codePoints a string of Unicode codepoints
26+
* @return a Punycode string of ASCII-only characters.
27+
*/
28+
def encode(codePoints: String): String = js.native
29+
30+
/**
31+
* The punycode.toASCII() method converts a Unicode string representing an Internationalized Domain Name to Punycode.
32+
* Only the non-ASCII parts of the domain name will be converted. Calling punycode.toASCII() on a string that already
33+
* only contains ASCII characters will have no effect.
34+
* @param domain the domain name
35+
* @return a Unicode string representing an Internationalized Domain Name as Punycode
36+
*/
37+
def toASCII(domain: String): String = js.native
38+
39+
/**
40+
* The punycode.toUnicode() method converts a string representing a domain name containing Punycode encoded
41+
* characters into Unicode. Only the Punycode encoded parts of the domain name are be converted.
42+
* @param domain a string representing a domain name containing Punycode encoded characters
43+
* @return the Unicode string
44+
*/
45+
def toUnicode(domain: String): String = js.native
46+
47+
/**
48+
* The UCS2 object
49+
* @return The [[UCS2 UCS2]] object
50+
*/
51+
def ucs2: UCS2 = js.native
52+
53+
/**
54+
* Returns a string identifying the current Punycode.js version number.
55+
* @return a string identifying the current Punycode.js version number.
56+
*/
57+
def version: String = js.native
58+
59+
}
60+
61+
/**
62+
* Punycode.UCS2
63+
* @see https://nodejs.org/dist/latest-v7.x/docs/api/punycode.html
64+
*/
65+
@js.native
66+
trait UCS2 extends js.Object {
67+
68+
/**
69+
* The punycode.ucs2.decode() method returns an array containing the numeric codepoint values of each Unicode
70+
* symbol in the string.
71+
* @param string the string containing Unicode symbols
72+
* @return an array containing the numeric codepoint values of each Unicode symbol
73+
*/
74+
def decode(string: String): js.Array[Int] = js.native
75+
76+
/**
77+
* The punycode.ucs2.encode() method returns a string based on an array of numeric code point values.
78+
* @param codePoints an array of numeric code point values
79+
* @return a string based on an array of numeric code point values
80+
*/
81+
def encode(codePoints: js.Array[Int]): String = js.native
82+
83+
}
84+
85+
@js.native
86+
@JSImport("punycode", JSImport.Namespace)
87+
object Punycode extends Punycode

src/main/scala/io/scalajs/nodejs/stream/Writable.scala

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
package io.scalajs.nodejs
22
package stream
33

4-
import io.scalajs.util.PromiseHelper._
5-
import io.scalajs.util.PromiseHelper.Implicits._
64
import io.scalajs.nodejs.buffer.Buffer
75
import io.scalajs.nodejs.events.IEventEmitter
6+
import io.scalajs.util.PromiseHelper._
87

98
import scala.concurrent.Promise
109
import scala.scalajs.js
@@ -136,6 +135,24 @@ trait Writable extends IEventEmitter {
136135
*/
137136
def uncork(): Unit = js.native
138137

138+
/**
139+
* Flush all data, buffered since stream.cork() call.
140+
* @param chunk The data to write (<String> | <Buffer>)
141+
* @param callback the Callback for when this chunk of data is flushed
142+
* @return true, if the data was handled completely
143+
* @example writable.write(chunk[, encoding][, callback])
144+
*/
145+
def write(chunk: Buffer | String, callback: js.Function1[Error, Any] = js.native): Boolean = js.native
146+
147+
/**
148+
* Flush all data, buffered since stream.cork() call.
149+
* @param chunk The data to write (<String> | <Buffer>)
150+
* @param encoding The encoding, if chunk is a String
151+
* @return true, if the data was handled completely
152+
* @example writable.write(chunk[, encoding][, callback])
153+
*/
154+
def write(chunk: Buffer | String, encoding: String): Boolean = js.native
155+
139156
/**
140157
* Flush all data, buffered since stream.cork() call.
141158
* @param chunk The data to write (<String> | <Buffer>)
@@ -145,8 +162,8 @@ trait Writable extends IEventEmitter {
145162
* @example writable.write(chunk[, encoding][, callback])
146163
*/
147164
def write(chunk: Buffer | String,
148-
encoding: String = js.native,
149-
callback: js.Function1[Error, Any] = js.native): Boolean = js.native
165+
encoding: String,
166+
callback: js.Function1[Error, Any]): Boolean = js.native
150167

151168
}
152169

@@ -160,7 +177,7 @@ object Writable {
160177
* Writable Events
161178
* @author lawrence.daniels@gmail.com
162179
*/
163-
implicit class WritableEvents(val writable: Writable) extends AnyVal {
180+
implicit class WritableEvents[T <: Writable](val writable: T) extends AnyVal {
164181

165182
/**
166183
* Emitted when the stream and any of its underlying resources (a file descriptor, for example) have been closed.
@@ -209,7 +226,7 @@ object Writable {
209226
* Writable Extensions
210227
* @author lawrence.daniels@gmail.com
211228
*/
212-
implicit class WritableExtensions(val writable: Writable) extends AnyVal {
229+
implicit class WritableExtensions[T <: Writable](val writable: T) extends AnyVal {
213230

214231
@inline
215232
def endAsync(chunk: Buffer): Promise[Unit] = promiseWithError0[Error](writable.end(chunk, _))

src/main/scala/io/scalajs/nodejs/timers/ClearImmediate.scala

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,10 @@ import scala.scalajs.js
1010
trait ClearImmediate extends js.Object {
1111

1212
/**
13-
* Stops an immediateObject, as created by setImmediate, from triggering.
13+
* Stops an immediate, as created by setImmediate, from triggering.
14+
* @param handle the immediate handle
1415
* @example clearImmediate(immediateObject)
1516
*/
16-
def apply(immediateObject: Immediate): Unit = js.native
17+
def apply(handle: Immediate): Unit = js.native
1718

1819
}

src/main/scala/io/scalajs/nodejs/timers/ClearInterval.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ import scala.scalajs.js
1010
trait ClearInterval extends js.Object {
1111

1212
/**
13-
* Stops an intervalObject, as created by setInterval, from triggering.
13+
* Stops an interval, as created by setInterval, from triggering.
1414
* @example clearInterval(intervalObject)
1515
*/
16-
def apply(intervalObject: Interval): Unit = js.native
16+
def apply(handle: Timeout): Unit = js.native
1717

1818
}

src/main/scala/io/scalajs/nodejs/timers/ClearTimeout.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ import scala.scalajs.js
1010
trait ClearTimeout extends js.Object {
1111

1212
/**
13-
* Prevents a timeoutObject, as created by setTimeout, from triggering.
13+
* Prevents a timeout, as created by setTimeout, from triggering.
1414
* @example clearTimeout(timeoutObject)
1515
*/
16-
def apply(timeoutObject: Timeout): Unit = js.native
16+
def apply(handle: Timeout): Unit = js.native
1717

1818
}

src/main/scala/io/scalajs/nodejs/timers/Interval.scala

Lines changed: 0 additions & 50 deletions
This file was deleted.

src/main/scala/io/scalajs/nodejs/timers/SetInterval.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,6 @@ trait SetInterval extends js.Object {
1818
* or less than 1, Node.js will use 1 as the delay.
1919
* @example setInterval(callback, delay[, arg][, ...])
2020
*/
21-
def apply(callback: js.Function, delay: Int, args: js.Any*): Interval = js.native
21+
def apply(callback: js.Function, delay: Int, args: js.Any*): Timeout = js.native
2222

2323
}

src/main/scala/io/scalajs/nodejs/timers/Timeout.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,12 @@ object Timeout {
2727

2828
/**
2929
* Timeout Enrichment
30-
* @param Timeout the given [[Timeout Timeout]] handle
30+
* @param handle the given [[Timeout timeout]] handle
3131
*/
32-
implicit class TimeoutEnrichment(val Timeout: Timeout) extends AnyVal {
32+
implicit class TimeoutEnrichment(val handle: Timeout) extends AnyVal {
3333

3434
@inline
35-
def clear(): Unit = clearTimeout(Timeout)
35+
def clear(): Unit = clearTimeout(handle)
3636

3737
}
3838

src/test/resources/watchfile.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "scalajs-io",
3-
"version": "0.4.0-pre3",
3+
"version": "0.4.0-pre4",
44
"private": true,
55
"dependencies": {
66
"async": "^2.0.1",

0 commit comments

Comments
 (0)