New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

circular-reference-remover

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

circular-reference-remover

Removes the inner circular references from objects

latest
npmnpm
Version
2.1.0
Version published
Maintainers
1
Created
Source

Info

Removes the inner circular references from objects

  • GITHUB
  • NPM

Installation

npm i circular-reference-remover

Usage

import {remove} from "./circular-remover";

let a:any = {name:'circular a'};
let b:any = {name:'circular b'};
let c:any = {name:'circular c'};
let d:any = {name:'not circular'};

a.a = a;
a.b = b;
a.c = c;
a.d = d;
b.b = b;
b.a = a;
b.c = c;
b.d = d;
c.c = c;
c.a = a;
c.b = b;
c.d = d;


remove(a).then((result:any)=>{
    console.log(
        JSON.stringify(result,null,2)
    );
})

console.log('\n------------------\n');

//WITH setUndefined TRUE
remove(a,{setUndefined:true}).then((result:any)=>{
    console.log(
        JSON.stringify(result,null,2)
    );
})


Result:

{
  "name": "circular a",
  "a": null,
  "b": {
    "name": "circular b",
    "b": null,
    "a": null,
    "c": {
      "name": "circular c",
      "c": null,
      "a": null,
      "b": null,
      "d": {
        "name": "not circular"
      }
    },
    "d": {
      "name": "not circular"
    }
  },
  "c": {
    "name": "circular c",
    "c": null,
    "a": null,
    "b": {
      "name": "circular b",
      "b": null,
      "a": null,
      "c": null,
      "d": {
        "name": "not circular"
      }
    },
    "d": {
      "name": "not circular"
    }
  },
  "d": {
    "name": "not circular"
  }
}

------------------

{
  "name": "circular a",
  "b": {
    "name": "circular b",
    "c": {
      "name": "circular c",
      "d": {
        "name": "not circular"
      }
    },
    "d": {
      "name": "not circular"
    }
  },
  "c": {
    "name": "circular c",
    "b": {
      "name": "circular b",
      "d": {
        "name": "not circular"
      }
    },
    "d": {
      "name": "not circular"
    }
  },
  "d": {
    "name": "not circular"
  }
}

Documentation

  • Function remove(src:any,options?:remover.Options):Promise<any> - Returns a Promise that resolves a copy of the src object with its inner circular references setted to null or undefined. If the src is null or undefined return a Promise with the respective value.

  • Function removeSync(src:any,options?:remover.Options):any - Returns a copy of the src object with its inner circular references setted to null or undefined. If the src is null or undefined return the respective value.

  • RemoverOptions -

    • setUndefined?:boolean - If true set references as undefined instead of null

Contributing

Pull requests are welcome, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

Keywords

circular-reference

FAQs

Package last updated on 20 Dec 2021

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