Skip to content

Commit 601bb4c

Browse files
authored
fix: add validations to the "subgraph" method (#71)
1 parent 27bf4f4 commit 601bb4c

File tree

3 files changed

+12
-3
lines changed

3 files changed

+12
-3
lines changed

package-lock.json

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@kasnix/structured-objects",
3-
"version": "1.3.0",
3+
"version": "1.3.1",
44
"repository": {
55
"type": "git",
66
"url": "git+https://github.com/luckasnix/structured-objects.git"

src/object-graph.ts

+9
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,15 @@ export class ObjectGraph<NodeValue extends Record<string, unknown>> {
8686
* @since 1.3.0
8787
*/
8888
public subgraph(nodeKeys: Array<string>): ObjectGraph<NodeValue> {
89+
if (!nodeKeys) {
90+
throw new Error("Provide a value for the 'nodeKeys' parameter");
91+
}
92+
if (!Array.isArray(nodeKeys)) {
93+
throw new TypeError("The parameter 'nodeKeys' must be an array");
94+
}
95+
if (nodeKeys.length === 0) {
96+
throw new Error("The parameter 'nodeKeys' must contain at least one item");
97+
}
8998
const subgraph = new ObjectGraph([], this.keyExtractor);
9099
for (const [nodeKey, nodeValue] of this.nodes) {
91100
if (nodeKeys.includes(nodeKey)) {

0 commit comments

Comments
 (0)