Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

node-relation

Package Overview
Dependencies
Maintainers
1
Versions
46
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

node-relation

Manage strings that are related to each other.

  • 2.0.0
  • npm
  • Socket score

Version published
Weekly downloads
6
increased by100%
Maintainers
1
Weekly downloads
 
Created
Source

node-relation

This module helps you manage string, numbers as a group.

The data in the instance is immutable. Do not modify the data in the instance that invokes the method (setRelation, getRelation, getLegionRelation, deleteNode, etc.). Instead, it returns the result with a new instance.

Check the code.

import Relation from 'node-relation'

const relationA = new Relation().setRelation('a', 'b', 'c')
console.log(relationA.nodes)

const relationB = relationA.setRelation('b', 'd')
console.log(relationB.nodes)

const relationC = relationB.setRelation('e', 'f')
console.log(relationC.getLegionRelation('e').nodes)

const relationD = relationC.setRelation('e', 'a')
console.log(relationD.getLegionRelation('e').nodes)

Methods

setRelation(target: RelationNode, ...nodes: RelationNode[]): Relation

Creates a new relationship between nodes, and returns it as a relation instance.

const A = new Relation().setRelation('language', 'English', 'Korean', 'Japanese')
const B = A.setRelation('English', 'US', 'France', 'Italy')

getRelation(...nodes: RelationNode[]): Relation

Only the nodes that are related to the node received by the parameter are filtered and returned in a new relation instance.

A.getRelation('language').nodes // English, Korean, Japanese
B.getRelation('English').nodes // US, France, Italy

getLegionRelation(...nodes: RelationNode[]): Relation

Only groups of nodes that are associated with the node received by the parameter. Then make and return a new relation instance.

B.getLegionRelation('language').nodes // English, Korean, Japanese, US, France, Italy

deleteRelation(target: RelationNode, ...nodes: RelationNode[]): Relation

Deletes the relationship between nodes and returns it as a new relation instance.

B.deleteRelation('English', 'France')

deleteNode(...nodes: RelationNode[]): Relation

Delete the node. If the node associated with the deleted node is isolated, it is deleted together. Returns the result with a new relation instance.

B.deleteNode('lanugage').nodes // English, US, France, Italy

Try it simply

const relation = new Relation()
                    .setRelation('language', 'English', 'Korean', 'Japanese')
                    .setRelation('English', 'US', 'France', 'Italy')

console.log(`Languages: ${ relation.getRelativeNodes('language') }`)
// Languages: English, Korean, Japanese

console.log(`English country: ${ relation.getRelation('English').deleteNode('language').getRelativeNodes('English') }`)
// English country: US, France, Italy 

FAQs

Package last updated on 07 Sep 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc