JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 155
  • Score
    100M100P100Q87435F
  • License ISC

Removes the inner circular references from objects

Package Exports

  • circular-reference-remover
  • circular-reference-remover/src/app/index.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (circular-reference-remover) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

Info

Removes the inner circular references from objects

Installation

npm i circular-reference-remover

Usage

import remover 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;

console.log(
    JSON.stringify(remover(a),null,2)
);

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

//WITH setUndefined TRUE
console.log(
    JSON.stringify(
        remover(a, { setUndefined: true })
        , 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 a the respective value.

  • remover.Options -

    • 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.