Skip to content

docs: add since tag #32

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 27, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/object-graph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export class ObjectGraph<NodeValue extends Record<string, unknown>> {

/**
* @description Returns an instance of ObjectGraph.
* @since 0.1.0
*/
constructor(nodeValues: Array<NodeValue>, keyExtractor: (nodeValue: NodeValue) => string) {
if (!nodeValues) {
Expand All @@ -23,13 +24,15 @@ export class ObjectGraph<NodeValue extends Record<string, unknown>> {

/**
* @description Returns the length of the object graph.
* @since 0.1.0
*/
public get length() {
return this.nodes.size;
}

/**
* @description Returns a node of the object graph.
* @since 0.1.0
*/
public get(nodeKey: string) {
if (!nodeKey) {
Expand All @@ -47,20 +50,23 @@ export class ObjectGraph<NodeValue extends Record<string, unknown>> {

/**
* @description Returns all nodes of the object graph.
* @since 0.1.0
*/
public getAll() {
return Array.from(this.nodes.values());
}

/**
* @description Returns a copy of the original object graph.
* @since 0.1.0
*/
public copy() {
return new ObjectGraph(Array.from(this.nodes.values()), this.keyExtractor);
}

/**
* @description Adds a node to the object graph.
* @since 0.1.0
*/
public add(nodeValue: NodeValue) {
if (!nodeValue) {
Expand All @@ -75,6 +81,7 @@ export class ObjectGraph<NodeValue extends Record<string, unknown>> {

/**
* @description Returns a copy of the original object graph with a received node added.
* @since 0.1.0
*/
public toAdded(nodeValue: NodeValue) {
const copiedObjectGraph = this.copy();
Expand All @@ -84,6 +91,7 @@ export class ObjectGraph<NodeValue extends Record<string, unknown>> {

/**
* @description Updates a node in the object graph.
* @since 0.1.0
*/
public update(nodeValue: NodeValue) {
if (!nodeValue) {
Expand All @@ -98,6 +106,7 @@ export class ObjectGraph<NodeValue extends Record<string, unknown>> {

/**
* @description Returns a copy of the original object graph with a received node updated.
* @since 0.1.0
*/
public toUpdated(nodeValue: NodeValue) {
const copiedObjectGraph = this.copy();
Expand All @@ -107,6 +116,7 @@ export class ObjectGraph<NodeValue extends Record<string, unknown>> {

/**
* @description Removes a node from the object graph.
* @since 0.1.0
*/
public remove(nodeKey: string) {
if (!nodeKey) {
Expand All @@ -123,6 +133,7 @@ export class ObjectGraph<NodeValue extends Record<string, unknown>> {

/**
* @description Returns a copy of the original object graph with a received node removed.
* @since 0.1.0
*/
public toRemoved(nodeKey: string) {
const copiedObjectGraph = this.copy();
Expand All @@ -132,6 +143,7 @@ export class ObjectGraph<NodeValue extends Record<string, unknown>> {

/**
* @description Returns all values of the provided property.
* @since 0.1.0
*/
public valuesOf(propertyKey: keyof NodeValue) {
if (!propertyKey) {
Expand All @@ -149,6 +161,7 @@ export class ObjectGraph<NodeValue extends Record<string, unknown>> {

/**
* @description Returns all nodes that match with the provided shape.
* @since 0.1.0
*/
public match(shape: Partial<Record<keyof NodeValue, Array<unknown>>>) {
if (!shape) {
Expand Down