summaryrefslogtreecommitdiff
path: root/std/node
diff options
context:
space:
mode:
Diffstat (limited to 'std/node')
-rw-r--r--std/node/_fs/_fs_access.ts6
-rw-r--r--std/node/_fs/_fs_common.ts8
-rw-r--r--std/node/_fs/_fs_dir.ts6
-rw-r--r--std/node/_util/_util_promisify.ts6
-rw-r--r--std/node/_util/_util_promisify_test.ts24
-rw-r--r--std/node/buffer.ts8
-rw-r--r--std/node/events.ts68
-rw-r--r--std/node/events_test.ts2
-rw-r--r--std/node/process.ts1
-rw-r--r--std/node/querystring.ts3
10 files changed, 81 insertions, 51 deletions
diff --git a/std/node/_fs/_fs_access.ts b/std/node/_fs/_fs_access.ts
index df84eac9c..8fb8cc7e6 100644
--- a/std/node/_fs/_fs_access.ts
+++ b/std/node/_fs/_fs_access.ts
@@ -8,9 +8,9 @@ import { notImplemented } from "../_utils.ts";
//TODO - 'path' can also be a Buffer. Neither of these polyfills
//is available yet. See https://github.com/denoland/deno/issues/3403
export function access(
- path: string | URL, // eslint-disable-line @typescript-eslint/no-unused-vars
- modeOrCallback: number | Function, // eslint-disable-line @typescript-eslint/no-unused-vars
- callback?: CallbackWithError, // eslint-disable-line @typescript-eslint/no-unused-vars
+ _path: string | URL,
+ _modeOrCallback: number | ((...args: unknown[]) => void),
+ _callback?: CallbackWithError,
): void {
notImplemented("Not yet available");
}
diff --git a/std/node/_fs/_fs_common.ts b/std/node/_fs/_fs_common.ts
index 165b9aeca..5d3f02a5d 100644
--- a/std/node/_fs/_fs_common.ts
+++ b/std/node/_fs/_fs_common.ts
@@ -47,7 +47,13 @@ export function isFileOptions(
}
export function getEncoding(
- optOrCallback?: FileOptions | WriteFileOptions | Function | Encodings | null,
+ optOrCallback?:
+ | FileOptions
+ | WriteFileOptions
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
+ | ((...args: any[]) => any)
+ | Encodings
+ | null,
): Encodings | null {
if (!optOrCallback || typeof optOrCallback === "function") {
return null;
diff --git a/std/node/_fs/_fs_dir.ts b/std/node/_fs/_fs_dir.ts
index 7f2085b3b..20239d4f3 100644
--- a/std/node/_fs/_fs_dir.ts
+++ b/std/node/_fs/_fs_dir.ts
@@ -17,7 +17,8 @@ export default class Dir {
return this.dirPath;
}
- read(callback?: Function): Promise<Dirent | null> {
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
+ read(callback?: (...args: any[]) => void): Promise<Dirent | null> {
return new Promise((resolve, reject) => {
if (!this.asyncIterator) {
this.asyncIterator = Deno.readDir(this.path)[Symbol.asyncIterator]();
@@ -55,7 +56,8 @@ export default class Dir {
* directories, and therefore does not need to close directories when
* finished reading.
*/
- close(callback?: Function): Promise<void> {
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
+ close(callback?: (...args: any[]) => void): Promise<void> {
return new Promise((resolve, reject) => {
try {
if (callback) {
diff --git a/std/node/_util/_util_promisify.ts b/std/node/_util/_util_promisify.ts
index 03ebeba04..6aeee8ecf 100644
--- a/std/node/_util/_util_promisify.ts
+++ b/std/node/_util/_util_promisify.ts
@@ -56,7 +56,11 @@ class NodeInvalidArgTypeError extends TypeError {
}
}
-export function promisify(original: Function): Function {
+export function promisify(
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
+ original: (...args: any[]) => void,
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
+): (...args: any[]) => Promise<any> {
if (typeof original !== "function") {
throw new NodeInvalidArgTypeError("original", "Function", original);
}
diff --git a/std/node/_util/_util_promisify_test.ts b/std/node/_util/_util_promisify_test.ts
index 67ca6af58..6271a8581 100644
--- a/std/node/_util/_util_promisify_test.ts
+++ b/std/node/_util/_util_promisify_test.ts
@@ -29,6 +29,9 @@ import {
import { promisify } from "./_util_promisify.ts";
import * as fs from "../fs.ts";
+// eslint-disable-next-line @typescript-eslint/no-explicit-any
+type VoidFunction = (...args: any[]) => void;
+
const readFile = promisify(fs.readFile);
const customPromisifyArgs = Symbol.for("nodejs.util.promisify.customArgs");
@@ -87,7 +90,7 @@ Deno.test("Custom promisify args", async function testPromisifyCustomArgs() {
const firstValue = 5;
const secondValue = 17;
- function fn(callback: Function): void {
+ function fn(callback: VoidFunction): void {
callback(null, firstValue, secondValue);
}
@@ -101,7 +104,7 @@ Deno.test("Custom promisify args", async function testPromisifyCustomArgs() {
Deno.test(
"Multiple callback args without custom promisify args",
async function testPromisifyWithoutCustomArgs() {
- function fn(callback: Function): void {
+ function fn(callback: VoidFunction): void {
callback(null, "foo", "bar");
}
const value = await promisify(fn)();
@@ -112,7 +115,7 @@ Deno.test(
Deno.test(
"Undefined resolved value",
async function testPromisifyWithUndefinedResolvedValue() {
- function fn(callback: Function): void {
+ function fn(callback: VoidFunction): void {
callback(null);
}
const value = await promisify(fn)();
@@ -123,7 +126,7 @@ Deno.test(
Deno.test(
"Undefined resolved value II",
async function testPromisifyWithUndefinedResolvedValueII() {
- function fn(callback: Function): void {
+ function fn(callback: VoidFunction): void {
callback();
}
const value = await promisify(fn)();
@@ -134,7 +137,7 @@ Deno.test(
Deno.test(
"Resolved value: number",
async function testPromisifyWithNumberResolvedValue() {
- function fn(err: Error | null, val: number, callback: Function): void {
+ function fn(err: Error | null, val: number, callback: VoidFunction): void {
callback(err, val);
}
const value = await promisify(fn)(null, 42);
@@ -145,7 +148,7 @@ Deno.test(
Deno.test(
"Rejected value",
async function testPromisifyWithNumberRejectedValue() {
- function fn(err: Error | null, val: null, callback: Function): void {
+ function fn(err: Error | null, val: null, callback: VoidFunction): void {
callback(err, val);
}
await assertThrowsAsync(
@@ -157,9 +160,8 @@ Deno.test(
);
Deno.test("Rejected value", async function testPromisifyWithAsObjectMethod() {
- const o: { fn?: Function } = {};
- const fn = promisify(function (cb: Function): void {
- // @ts-expect-error TypeScript
+ const o: { fn?: VoidFunction } = {};
+ const fn = promisify(function (this: unknown, cb: VoidFunction): void {
cb(null, this === o);
});
@@ -177,7 +179,7 @@ Deno.test(
);
const stack = err.stack;
- const fn = promisify(function (cb: Function): void {
+ const fn = promisify(function (cb: VoidFunction): void {
cb(null);
cb(err);
});
@@ -203,7 +205,7 @@ Deno.test("Test error", async function testInvalidArguments() {
a: number,
b: number,
c: number,
- cb: Function,
+ cb: VoidFunction,
): void {
errToThrow = new Error(`${a}-${b}-${c}-${cb}`);
throw errToThrow;
diff --git a/std/node/buffer.ts b/std/node/buffer.ts
index 7656803d9..c88d7f8b7 100644
--- a/std/node/buffer.ts
+++ b/std/node/buffer.ts
@@ -94,7 +94,9 @@ export default class Buffer extends Uint8Array {
if (typeof fill === "string") {
encoding = checkEncoding(encoding);
if (
- typeof fill === "string" && fill.length === 1 && encoding === "utf8"
+ typeof fill === "string" &&
+ fill.length === 1 &&
+ encoding === "utf8"
) {
buf.fill(fill.charCodeAt(0));
} else bufFill = Buffer.from(fill, encoding);
@@ -221,7 +223,7 @@ export default class Buffer extends Uint8Array {
/**
* Returns true if obj is a Buffer, false otherwise.
*/
- static isBuffer(obj: object): obj is Buffer {
+ static isBuffer(obj: unknown): obj is Buffer {
return obj instanceof Buffer;
}
@@ -408,7 +410,7 @@ export default class Buffer extends Uint8Array {
* Returns a JSON representation of buf. JSON.stringify() implicitly calls
* this function when stringifying a Buffer instance.
*/
- toJSON(): object {
+ toJSON(): Record<string, unknown> {
return { type: "Buffer", data: Array.from(this) };
}
diff --git a/std/node/events.ts b/std/node/events.ts
index b267852aa..bc27731ca 100644
--- a/std/node/events.ts
+++ b/std/node/events.ts
@@ -24,8 +24,11 @@
import { validateIntegerRange } from "./util.ts";
import { assert } from "../_util/assert.ts";
+// eslint-disable-next-line @typescript-eslint/no-explicit-any
+export type GenericFunction = (...args: any[]) => any;
+
export interface WrappedFunction extends Function {
- listener: Function;
+ listener: GenericFunction;
}
/**
@@ -35,7 +38,10 @@ export default class EventEmitter {
public static defaultMaxListeners = 10;
public static errorMonitor = Symbol("events.errorMonitor");
private maxListeners: number | undefined;
- private _events: Map<string | symbol, Array<Function | WrappedFunction>>;
+ private _events: Map<
+ string | symbol,
+ Array<GenericFunction | WrappedFunction>
+ >;
public constructor() {
this._events = new Map();
@@ -43,13 +49,13 @@ export default class EventEmitter {
private _addListener(
eventName: string | symbol,
- listener: Function | WrappedFunction,
+ listener: GenericFunction | WrappedFunction,
prepend: boolean,
): this {
this.emit("newListener", eventName, listener);
if (this._events.has(eventName)) {
const listeners = this._events.get(eventName) as Array<
- Function | WrappedFunction
+ GenericFunction | WrappedFunction
>;
if (prepend) {
listeners.unshift(listener);
@@ -76,7 +82,7 @@ export default class EventEmitter {
/** Alias for emitter.on(eventName, listener). */
public addListener(
eventName: string | symbol,
- listener: Function | WrappedFunction,
+ listener: GenericFunction | WrappedFunction,
): this {
return this._addListener(eventName, listener, false);
}
@@ -96,7 +102,9 @@ export default class EventEmitter {
) {
this.emit(EventEmitter.errorMonitor, ...args);
}
- const listeners = (this._events.get(eventName) as Function[]).slice(); // We copy with slice() so array is not mutated during emit
+ const listeners = (this._events.get(
+ eventName,
+ ) as GenericFunction[]).slice(); // We copy with slice() so array is not mutated during emit
for (const listener of listeners) {
try {
listener.apply(this, args);
@@ -138,7 +146,7 @@ export default class EventEmitter {
*/
public listenerCount(eventName: string | symbol): number {
if (this._events.has(eventName)) {
- return (this._events.get(eventName) as Function[]).length;
+ return (this._events.get(eventName) as GenericFunction[]).length;
} else {
return 0;
}
@@ -148,21 +156,19 @@ export default class EventEmitter {
target: EventEmitter,
eventName: string | symbol,
unwrap: boolean,
- ): Function[] {
+ ): GenericFunction[] {
if (!target._events.has(eventName)) {
return [];
}
- const eventListeners: Function[] = target._events.get(
- eventName,
- ) as Function[];
+ const eventListeners = target._events.get(eventName) as GenericFunction[];
return unwrap
? this.unwrapListeners(eventListeners)
: eventListeners.slice(0);
}
- private unwrapListeners(arr: Function[]): Function[] {
- const unwrappedListeners: Function[] = new Array(arr.length) as Function[];
+ private unwrapListeners(arr: GenericFunction[]): GenericFunction[] {
+ const unwrappedListeners = new Array(arr.length) as GenericFunction[];
for (let i = 0; i < arr.length; i++) {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
unwrappedListeners[i] = (arr[i] as any)["listener"] || arr[i];
@@ -171,7 +177,7 @@ export default class EventEmitter {
}
/** Returns a copy of the array of listeners for the event named eventName.*/
- public listeners(eventName: string | symbol): Function[] {
+ public listeners(eventName: string | symbol): GenericFunction[] {
return this._listeners(this, eventName, true);
}
@@ -181,12 +187,12 @@ export default class EventEmitter {
*/
public rawListeners(
eventName: string | symbol,
- ): Array<Function | WrappedFunction> {
+ ): Array<GenericFunction | WrappedFunction> {
return this._listeners(this, eventName, false);
}
/** Alias for emitter.removeListener(). */
- public off(eventName: string | symbol, listener: Function): this {
+ public off(eventName: string | symbol, listener: GenericFunction): this {
return this.removeListener(eventName, listener);
}
@@ -199,7 +205,7 @@ export default class EventEmitter {
*/
public on(
eventName: string | symbol,
- listener: Function | WrappedFunction,
+ listener: GenericFunction | WrappedFunction,
): this {
return this.addListener(eventName, listener);
}
@@ -208,7 +214,7 @@ export default class EventEmitter {
* Adds a one-time listener function for the event named eventName. The next
* time eventName is triggered, this listener is removed and then invoked.
*/
- public once(eventName: string | symbol, listener: Function): this {
+ public once(eventName: string | symbol, listener: GenericFunction): this {
const wrapped: WrappedFunction = this.onceWrap(eventName, listener);
this.on(eventName, wrapped);
return this;
@@ -217,19 +223,22 @@ export default class EventEmitter {
// Wrapped function that calls EventEmitter.removeListener(eventName, self) on execution.
private onceWrap(
eventName: string | symbol,
- listener: Function,
+ listener: GenericFunction,
): WrappedFunction {
const wrapper = function (
this: {
eventName: string | symbol;
- listener: Function;
- rawListener: Function;
+ listener: GenericFunction;
+ rawListener: GenericFunction | WrappedFunction;
context: EventEmitter;
},
// eslint-disable-next-line @typescript-eslint/no-explicit-any
...args: any[]
): void {
- this.context.removeListener(this.eventName, this.rawListener);
+ this.context.removeListener(
+ this.eventName,
+ this.rawListener as GenericFunction,
+ );
this.listener.apply(this.context, args);
};
const wrapperContext = {
@@ -255,7 +264,7 @@ export default class EventEmitter {
*/
public prependListener(
eventName: string | symbol,
- listener: Function | WrappedFunction,
+ listener: GenericFunction | WrappedFunction,
): this {
return this._addListener(eventName, listener, true);
}
@@ -267,7 +276,7 @@ export default class EventEmitter {
*/
public prependOnceListener(
eventName: string | symbol,
- listener: Function,
+ listener: GenericFunction,
): this {
const wrapped: WrappedFunction = this.onceWrap(eventName, listener);
this.prependListener(eventName, wrapped);
@@ -283,7 +292,7 @@ export default class EventEmitter {
if (eventName) {
if (this._events.has(eventName)) {
const listeners = (this._events.get(eventName) as Array<
- Function | WrappedFunction
+ GenericFunction | WrappedFunction
>).slice(); // Create a copy; We use it AFTER it's deleted.
this._events.delete(eventName);
for (const listener of listeners) {
@@ -304,10 +313,13 @@ export default class EventEmitter {
* Removes the specified listener from the listener array for the event
* named eventName.
*/
- public removeListener(eventName: string | symbol, listener: Function): this {
+ public removeListener(
+ eventName: string | symbol,
+ listener: GenericFunction,
+ ): this {
if (this._events.has(eventName)) {
const arr:
- | Array<Function | WrappedFunction>
+ | Array<GenericFunction | WrappedFunction>
| undefined = this._events.get(eventName);
assert(arr);
@@ -382,7 +394,7 @@ export function once(
}
resolve(args);
};
- let errorListener: Function;
+ let errorListener: GenericFunction;
// Adding an error listener is not optional because
// if an error is thrown on an event emitter we cannot
diff --git a/std/node/events_test.ts b/std/node/events_test.ts
index 62b20594c..adeae5b93 100644
--- a/std/node/events_test.ts
+++ b/std/node/events_test.ts
@@ -6,7 +6,7 @@ import {
} from "../testing/asserts.ts";
import EventEmitter, { WrappedFunction, once, on } from "./events.ts";
-const shouldNeverBeEmitted: Function = () => {
+const shouldNeverBeEmitted = () => {
fail("Should never be called");
};
diff --git a/std/node/process.ts b/std/node/process.ts
index ce5f828c0..a05a423fd 100644
--- a/std/node/process.ts
+++ b/std/node/process.ts
@@ -42,6 +42,7 @@ export const process = {
/** https://nodejs.org/api/process.html#process_process_events */
// on is not exported by node, it is only available within process:
// node --input-type=module -e "import { on } from 'process'; console.log(on)"
+ // eslint-disable-next-line @typescript-eslint/ban-types
on(_event: string, _callback: Function): void {
// TODO(rsp): to be implemented
notImplemented();
diff --git a/std/node/querystring.ts b/std/node/querystring.ts
index 4e3c728c1..35dfbbc86 100644
--- a/std/node/querystring.ts
+++ b/std/node/querystring.ts
@@ -107,7 +107,8 @@ export function encodeStr(
}
export function stringify(
- obj: object,
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
+ obj: Record<string, any>,
sep = "&",
eq = "=",
{ encodeURIComponent = escape }: StringifyOptions = {},