JavaScriptToString ![Twitter](https://img.shields.io/twitter/url?url=https%3A%2F%2Fwww.npmjs.com%2Fpackage%2F%40lopatnov%2Fjavascripttostring)
![GitHub top language](https://img.shields.io/github/languages/top/lopatnov/jsToString)
![LinkedIn](https://img.shields.io/badge/LinkedIn-lopatnov-informational?style=social&logo=linkedin)
![Build Status](https://travis-ci.org/lopatnov/jsToString.png?branch=master)
JavaScript value to string runtime converter. It converts a runtime value into string a value.
Install
![https://nodei.co/npm/@lopatnov/javascripttostring.png?downloads=true&downloadRank=true&stars=true](https://nodei.co/npm/@lopatnov/javascripttostring.png?downloads=true&downloadRank=true&stars=true)
npm install @lopatnov/javascripttostring
Browser
<script src="//lopatnov.github.io/jsToString/dist/javascripttostring.umd.js"></script>
Import package to the project
TypeScript
import javaScriptToString from '@lopatnov/javascripttostring';
JavaScript
var javaScriptToString = require("@lopatnov/javascripttostring");
Convert JavaScript values into string values
javaScriptToString(value: any, options?: IJ2SOptions) => string
where
interface IJ2SOptions {
includeFunctionProperties?: boolean;
includeFunctionPrototype?: boolean;
includeBuffers?: boolean;
nestedObjectsAmount?: number;
nestedArraysAmount?: number;
nestedFunctionsAmount?: number;
}
Examples
let myStringOfString = javaScriptToString('Hello world');
console.log(myStringOfString);
let myStringOfArray = javaScriptToString(["Hello", "World", ".", "How", "do", "you", "do", "?"]);
console.log(myStringOfArray);
let myObjectString = javaScriptToString({
friend1: "Shurik",
friend2: "Alex",
friends: {
friend3: 123456,
friend4: {},
friend5: ["Hola", "amigo"],
friend6: () => {
console.log("How you doing?");
}
}
});
console.log(myObjectString);
let myFunctionString = javaScriptToString(function(a,b) {
console.log("Just a function");
})
console.log(myFunctionString);
function Simple(title) {
this.title = title || "world";
}
Simple.count = 0;
Simple.prototype.show = function(){
Simple.count++;
console.log('title = ', this.title);
console.log('count = ', Simple.count);
}
console.log(javaScriptToString(Simple));
var x = [1,2,3];
x[0] = x;
console.log(javaScriptToString(x));
Demo
See, how it's working: https://runkit.com/lopatnov/javascripttostring-demo
Test it with a runkit: https://npm.runkit.com/%40lopatnov%2Fjavascripttostring
Rights and Agreements
License Apache-2.0
Copyright 2019–2021 Oleksandr Lopatnov