Socket
Socket
Sign inDemoInstall

tosource

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

tosource

toSource converts JavaScript objects back to source


Version published
Weekly downloads
259K
decreased by-22.49%
Maintainers
1
Weekly downloads
 
Created

What is tosource?

The 'tosource' npm package is used to convert JavaScript objects into their source code representation. This can be useful for debugging, serialization, or simply understanding the structure of complex objects.

What are tosource's main functionalities?

Convert Object to Source Code

This feature allows you to convert a JavaScript object into its source code representation. The code sample demonstrates converting a nested object into a string of its source code.

const tosource = require('tosource');
const obj = { a: 1, b: [2, 3], c: { d: 4 } };
const source = tosource(obj);
console.log(source);

Handle Functions and RegExp

This feature allows you to convert objects that contain functions and regular expressions into their source code representation. The code sample demonstrates converting an object with a function and a RegExp.

const tosource = require('tosource');
const obj = { a: function() { return 1; }, b: /test/i };
const source = tosource(obj);
console.log(source);

Circular References

This feature allows you to handle circular references within objects. The code sample demonstrates converting an object with a circular reference.

const tosource = require('tosource');
const obj = { a: 1 };
obj.b = obj;
const source = tosource(obj);
console.log(source);

Other packages similar to tosource

Keywords

FAQs

Package last updated on 31 Jul 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

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