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

instance-stringer

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

instance-stringer

Convert content of a class instance to a string.

  • 1.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
590
increased by39.15%
Maintainers
1
Weekly downloads
 
Created
Source

instance-stringer NPM MIT License Build Status Build Status Coverage Status

Converts a content of a class instance to a string.

Install

To install from npm:

$ npm i instance-stringer --save

Load this module

For Node.js

const instanceStringer = require('instance-stringer')
const { propsStringer, arrayStringer } = instanceStringer

For Web browser (only supporting es6):

<script src="instance-stringer.min.js"></script>
<script>
const { propsStringer, arrayStringer } = instanceStringer
</script>

Usage

Converts content of the instance of MyClass :

class SubClass {
  constructor() {
    this.p = 1
    this.q = 2
  }
}
class MyClass {
  constructor() {
    this.a = 123
    this.b = { c: 'A', d: [{ g: 1, h: 2 }, 3], e: new SubClass() }
  }
}

const myInstance = new MyClass()

instanceStringer(myInstance)
// => "MyClass { a: 123, b: { c: 'A', d: [{ g: 1, h: 2 }, 3], e: SubClass { p: 1, q: 2 } } }"

propsStringer(myInstance)
// => "{ a: 123, b: { c: 'A', d: [{ g: 1, h: 2 }, 3], e: SubClass { p: 1, q: 2 } } }"


arrayStringer(myInstance.b.d)
// => "[{ g: 1, h: 2 }, 3]"

API

instanceStringer(instance) : string

Converts content of class instance to a string with its class name. If the instance is a plain object its class name (Object) is not output.

propsStringer(object) : string

Converts properties of a plain object or a class instance to a string without its class name.

arrayStringer(array) : string

Converts elements of an array to a string.

License

Copyright (C) 2017-2018 Takayuki sato

This program is free software under MIT License. See the file LICENSE in this distribution for more details.

Keywords

FAQs

Package last updated on 08 Jul 2018

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