instance-stringer
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 = const propsStringer arrayStringer = instanceStringer
For Web browser (only supporting es6):
Usage
Converts content of the instance of MyClass
:
{ thisp = 1 thisq = 2 } { thisa = 123 thisb = c: 'A' d: g: 1 h: 2 3 e: } const myInstance = // => "MyClass { a: 123, b: { c: 'A', d: [{ g: 1, h: 2 }, 3], e: SubClass { p: 1, q: 2 } } }" // => "{ a: 123, b: { c: 'A', d: [{ g: 1, h: 2 }, 3], e: SubClass { p: 1, q: 2 } } }" // => "[{ 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.