Socket
Socket
Sign inDemoInstall

node-relation

Package Overview
Dependencies
0
Maintainers
1
Versions
46
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    node-relation

Manage strings that are related to each other.


Version published
Weekly downloads
32
increased by220%
Maintainers
1
Install size
30.6 kB
Created
Weekly downloads
 

Readme

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

Last updated on 07 Sep 2020

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc