diff --git a/docs/object-graph.doc.md b/docs/object-graph.doc.md index ae66236..a1c5840 100644 --- a/docs/object-graph.doc.md +++ b/docs/object-graph.doc.md @@ -20,6 +20,10 @@ Returns an instance of ObjectGraph. Returns the length of the object graph. +### size + +Returns the size of the object graph. + ## Instance Methods ### keys() diff --git a/package-lock.json b/package-lock.json index e923967..aea4998 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@kasnix/structured-objects", - "version": "1.1.0", + "version": "1.2.0", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@kasnix/structured-objects", - "version": "1.1.0", + "version": "1.2.0", "license": "MIT", "devDependencies": { "@biomejs/biome": "1.9.4", diff --git a/package.json b/package.json index 467bfe2..88f7618 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@kasnix/structured-objects", - "version": "1.1.0", + "version": "1.2.0", "repository": { "type": "git", "url": "git+https://github.com/luckasnix/structured-objects.git" diff --git a/src/object-graph.ts b/src/object-graph.ts index 431ee50..0a45194 100644 --- a/src/object-graph.ts +++ b/src/object-graph.ts @@ -25,11 +25,20 @@ export class ObjectGraph> { /** * @description Returns the length of the object graph. * @since 1.0.0 + * @deprecated Since version 1.2.0. Will be removed in version 2.0.0. Use "size" instead. */ public get length(): number { return this.nodes.size; } + /** + * @description Returns the size of the object graph. + * @since 1.2.0 + */ + public get size(): number { + return this.nodes.size; + } + /** * @description Returns an iterator object that contains the keys of the object graph. * @since 1.0.0 diff --git a/tests/object-graph.test.ts b/tests/object-graph.test.ts index c018d58..7dddf3f 100644 --- a/tests/object-graph.test.ts +++ b/tests/object-graph.test.ts @@ -22,6 +22,19 @@ describe("length", () => { }); }); +describe("size", () => { + test("gets the size of the object graph", () => { + const shirtToAdd: Shirt = { sku: "9", color: "orange", size: "small" }; + const shirtsObjectGraph = new ObjectGraph(shirtsMock, (shirt) => shirt.sku); + + expect(shirtsObjectGraph.size).toBe(8); + + shirtsObjectGraph.add(shirtToAdd); + + expect(shirtsObjectGraph.size).toBe(9); + }); +}); + describe("keys()", () => { test("gets an iterator object that contains the keys of the object graph", () => { const shirtsObjectGraph = new ObjectGraph(shirtsMock, (shirt) => shirt.sku); @@ -104,8 +117,8 @@ describe("toAdded()", () => { const copiedShirtsObjectGraph = shirtsObjectGraph.toAdded(shirtsMock[0]); - expect(shirtsObjectGraph.length).toBe(0); - expect(copiedShirtsObjectGraph.length).toBe(1); + expect(shirtsObjectGraph.size).toBe(0); + expect(copiedShirtsObjectGraph.size).toBe(1); const returnedNodeFromCopy = copiedShirtsObjectGraph.get("1"); @@ -191,8 +204,8 @@ describe("toRemoved()", () => { const copiedShirtsObjectGraph = shirtsObjectGraph.toRemoved("1"); - expect(shirtsObjectGraph.length).toBe(8); - expect(copiedShirtsObjectGraph.length).toBe(7); + expect(shirtsObjectGraph.size).toBe(8); + expect(copiedShirtsObjectGraph.size).toBe(7); const returnedNodeFromOriginal = shirtsObjectGraph.get("1");