Skip to content

Commit 5cd8114

Browse files
committed
remove triple equals
1 parent 3e6115f commit 5cd8114

3 files changed

Lines changed: 35 additions & 39 deletions

File tree

dflow.ts

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -186,10 +186,10 @@ export class Dflow {
186186
nodeConnections: Array<{ sourceId: string; targetId: string }>
187187
): number {
188188
const parentsNodeIds = nodeConnections
189-
.filter(({ targetId }) => nodeId === targetId)
189+
.filter(({ targetId }) => nodeId == targetId)
190190
.map(({ sourceId }) => sourceId);
191191
// A node with no parent as level zero.
192-
if (parentsNodeIds.length === 0) return 0;
192+
if (!parentsNodeIds.length) return 0;
193193
// Otherwise its level is the max level of its parents plus one.
194194
let maxLevel = 0;
195195
for (const parentNodeId of parentsNodeIds)
@@ -235,7 +235,7 @@ export class Dflow {
235235
// If source can have any type or
236236
// target can have any type,
237237
// then source and target are compatible.
238-
if (sourceTypes.length === 0 || targetTypes.length === 0) return true;
238+
if (!sourceTypes.length || !targetTypes.length) return true;
239239

240240
// Check if target accepts some of the `dataType` source can have.
241241
return targetTypes.some((dataType) => sourceTypes.includes(dataType));
@@ -268,11 +268,11 @@ export class Dflow {
268268
set data(arg: unknown) {
269269
if (
270270
// Has any type and `arg` is some valid data...
271-
(types.length === 0 && Dflow.isData(arg)) ||
271+
(!types.length && Dflow.isData(arg)) ||
272272
// ... or output type corresponds to `arg` type.
273273
(types.includes("null") && arg === null) ||
274-
(types.includes("boolean") && typeof arg === "boolean") ||
275-
(types.includes("string") && typeof arg === "string") ||
274+
(types.includes("boolean") && typeof arg == "boolean") ||
275+
(types.includes("string") && typeof arg == "string") ||
276276
(types.includes("number") && Dflow.isNumber(arg)) ||
277277
(types.includes("object") && Dflow.isObject(arg)) ||
278278
(types.includes("array") && Dflow.isArray(arg))
@@ -298,7 +298,7 @@ export class Dflow {
298298
this.#outputs.delete(id);
299299
// Delete all links connected to node.
300300
for (const [linkId, link] of this.#links.entries())
301-
if (link[0] === id || link[2] === id) this.delete(linkId);
301+
if (link[0] == id || link[2] == id) this.delete(linkId);
302302
}
303303
// Delete link.
304304
const link = this.#links.get(id);
@@ -317,8 +317,8 @@ export class Dflow {
317317
// Infer data type
318318
let types: DflowDataType[] = [];
319319
if (data === null) types = ["null"];
320-
if (typeof data === "boolean") types = ["boolean"];
321-
if (typeof data === "string") types = ["string"];
320+
if (typeof data == "boolean") types = ["boolean"];
321+
if (typeof data == "string") types = ["string"];
322322
if (Dflow.isNumber(data)) types = ["number"];
323323
if (Dflow.isArray(data)) types = ["array"];
324324
if (Dflow.isObject(data)) types = ["object"];
@@ -335,10 +335,10 @@ export class Dflow {
335335
): string {
336336
const id = this.#newId(this.#links, "l", wantedId);
337337

338-
const sourceNodeId = typeof source === "string" ? source : source[0];
339-
const sourcePosition = typeof source === "string" ? 0 : source[1];
340-
const targetNodeId = typeof target === "string" ? target : target[0];
341-
const targetPosition = typeof target === "string" ? 0 : target[1];
338+
const sourceNodeId = typeof source == "string" ? source : source[0];
339+
const sourcePosition = typeof source == "string" ? 0 : source[1];
340+
const targetNodeId = typeof target == "string" ? target : target[0];
341+
const targetPosition = typeof target == "string" ? 0 : target[1];
342342

343343
if (
344344
this.canConnect([
@@ -379,7 +379,7 @@ export class Dflow {
379379
for (const nodeId of this.#sortedNodesIds()) {
380380
const kind = this.#kinds.get(nodeId)!;
381381

382-
if (kind === "data") continue;
382+
if (kind == "data") continue;
383383

384384
const run = this.#runs.get(nodeId)!;
385385

@@ -406,10 +406,10 @@ export class Dflow {
406406
const inputData = nodeInputs.map((input) => input.source?.data);
407407
let result: unknown;
408408
try {
409-
if (run.constructor.name === "Function") {
409+
if (run.constructor.name == "Function") {
410410
result = run(...inputData);
411411
}
412-
if (run.constructor.name === "AsyncFunction") {
412+
if (run.constructor.name == "AsyncFunction") {
413413
result = await run(...inputData);
414414
}
415415
} catch (err) {
@@ -427,7 +427,7 @@ export class Dflow {
427427
continue;
428428
}
429429
// Copy result into node .
430-
if (numOutputs === 1) nodeOutputs[0].data = result;
430+
if (numOutputs == 1) nodeOutputs[0].data = result;
431431
if (numOutputs > 1)
432432
for (let position = 0; position < numOutputs; position++)
433433
nodeOutputs[position].data = (result as DflowArray)[position];
@@ -441,7 +441,7 @@ export class Dflow {
441441
const node: DflowGraph["node"] = {};
442442
const data: DflowGraph["data"] = {};
443443
for (const [id, kind] of this.#kinds.entries()) {
444-
if (kind === "data")
444+
if (kind == "data")
445445
data[id] = this.#outputs.get(id)?.[0]?.data as DflowData;
446446
node[id] = kind;
447447
}
@@ -512,7 +512,7 @@ export class Dflow {
512512
rest?: Omit<DflowInput, "types">
513513
): DflowInput {
514514
return {
515-
types: typeof typing === "string" ? [typing] : typing,
515+
types: typeof typing == "string" ? [typing] : typing,
516516
...rest
517517
};
518518
}
@@ -531,7 +531,7 @@ export class Dflow {
531531
rest?: Omit<DflowOutput, "types">
532532
): DflowOutput {
533533
return {
534-
types: typeof typing === "string" ? [typing] : typing,
534+
types: typeof typing == "string" ? [typing] : typing,
535535
...rest
536536
};
537537
}
@@ -550,7 +550,7 @@ export class Dflow {
550550
*/
551551
static isObject(arg: unknown): arg is DflowObject {
552552
return (
553-
typeof arg === "object" &&
553+
typeof arg == "object" &&
554554
arg !== null &&
555555
!Array.isArray(arg) &&
556556
Object.values(arg).every(Dflow.isData)
@@ -559,16 +559,16 @@ export class Dflow {
559559

560560
/** Type guard for a valid number, i.e. finite and not `NaN`. */
561561
static isNumber(arg: unknown): arg is number {
562-
return typeof arg === "number" && !isNaN(arg) && Number.isFinite(arg);
562+
return typeof arg == "number" && !isNaN(arg) && Number.isFinite(arg);
563563
}
564564

565565
/** Type guard for `DflowData`. */
566566
static isData(arg: unknown): arg is Exclude<DflowData, undefined> {
567567
if (arg === undefined) return false;
568568
return (
569569
arg === null ||
570-
typeof arg === "boolean" ||
571-
typeof arg === "string" ||
570+
typeof arg == "boolean" ||
571+
typeof arg == "string" ||
572572
Dflow.isNumber(arg) ||
573573
Dflow.isObject(arg) ||
574574
Dflow.isArray(arg)
@@ -577,19 +577,19 @@ export class Dflow {
577577

578578
/** Validate that data belongs to some of given types. */
579579
static isValidData(types: DflowDataType[], data: unknown) {
580-
if (types.length === 0) return data === undefined || Dflow.isData(data);
580+
if (!types.length) return data === undefined || Dflow.isData(data);
581581
return types.some((dataType) =>
582-
dataType === "null"
582+
dataType == "null"
583583
? data === null
584-
: dataType === "boolean"
585-
? typeof data === "boolean"
586-
: dataType === "string"
587-
? typeof data === "string"
588-
: dataType === "number"
584+
: dataType == "boolean"
585+
? typeof data == "boolean"
586+
: dataType == "string"
587+
? typeof data == "string"
588+
: dataType == "number"
589589
? Dflow.isNumber(data)
590-
: dataType === "object"
590+
: dataType == "object"
591591
? Dflow.isObject(data)
592-
: dataType === "array"
592+
: dataType == "array"
593593
? Dflow.isArray(data)
594594
: false
595595
);

docs/examples/nodes/array.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -88,11 +88,7 @@ const ArraySlice: DflowNode = {
8888
],
8989
outputs: [output("array")],
9090
run(array: DflowArray, start: number, end?: number) {
91-
if (typeof end === "number") {
92-
return array.slice(start, end);
93-
} else {
94-
return array.slice(start);
95-
}
91+
return array.slice(start, end);
9692
}
9793
};
9894

tests/nodes/array_test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ test("arraySlice", () => {
9090
{
9191
input1: ["ant", "bison", "camel", "duck", "elephant"],
9292
input2: 2,
93-
input3: undefined,
93+
// input3: undefined,
9494
output: ["camel", "duck", "elephant"]
9595
},
9696
{

0 commit comments

Comments
 (0)