Skip to content

Releases: lopatnov/jsToString

@lopatnov/javascripttostring

08 Aug 22:10
Compare
Choose a tag to compare

JavaScriptToString

NPM version
License
Build Status
Twitter

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

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; // default true
  includeFunctionPrototype?: boolean; // default true
  includeBuffers?: boolean; // default true
  nestedObjectsAmount?: number; // default Number.POSITIVE_INFINITY
  nestedArraysAmount?: number; // default Number.POSITIVE_INFINITY
  nestedFunctionsAmount?: number; // default Number.POSITIVE_INFINITY
}

Examples

let myStringOfString = javaScriptToString('Hello world');
console.log(myStringOfString);
/* expected myStringOfString value: "\"Hello world\"" */
let myStringOfArray = javaScriptToString(["Hello", "World", ".", "How", "do", "you", "do", "?"]);
console.log(myStringOfArray);
/* expected myStringOfArray value: "[\"Hello\",\"World\",\".\",\"How\",\"do\",\"you\",\"do\",\"?\"]" */
let myObjectString = javaScriptToString({
    friend1: "Shurik",
    friend2: "Alex",
    friends: {
        friend3: 123456,
        friend4: {},
        friend5: ["Hola", "amigo"],
        friend6: () => {
            console.log("How you doing?");
        }
    }
});

console.log(myObjectString);
/* expected myObjectString value:
"{friend1: \"Shurik\",friend2: \"Alex\",friends: {friend3: 123456,friend4: {},friend5: [\"Hola\",\"amigo\"],friend6: () => {
            console.log(\"How you doing?\");
        }}}"
*/
let myFunctionString = javaScriptToString(function(a,b) {
  console.log("Just a function");
})

console.log(myFunctionString);
/* expected myFunctionString:
"function(a,b) {
  console.log(\"Just a function\");
}"
*/
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));

/* Expected:

"(function(){
 var Simple = 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);
};

 return Simple;
}())"

*/
var x = [1,2,3];
x[0] = x;
console.log(javaScriptToString(x));

/*
"(function(){ var ___j2s_0 = [null, 2, 3]; ___j2s_0['0'] = ___j2s_0;  return ___j2s_0; }())"
*/

Demo

See, how it's working: https://runkit.com/lopatnov/javascripttostring-demo

Test it with a runkit: https://npm.runkit.com/%40lopatnov%2Fjavascripttostring

Changelog

Version Task
1.7.0 Resolve references to parent elements and itself

Rights and Agreements

License Apache-2.0

Copyright 2019–2020 Oleksandr Lopatnov

@lopatnov/javascripttostring

08 Aug 19:16
Compare
Choose a tag to compare

JavaScriptToString

NPM version
License
Build Status
Twitter

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

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; // default true
  includeFunctionPrototype?: boolean; // default true
  includeBuffers?: boolean; // default true
  nestedObjectsAmount?: number; // default Number.POSITIVE_INFINITY
  nestedArraysAmount?: number; // default Number.POSITIVE_INFINITY
  nestedFunctionsAmount?: number; // default Number.POSITIVE_INFINITY
}

Examples

let myStringOfString = javaScriptToString('Hello world');
console.log(myStringOfString);
/* expected myStringOfString value: "\"Hello world\"" */
let myStringOfArray = javaScriptToString(["Hello", "World", ".", "How", "do", "you", "do", "?"]);
console.log(myStringOfArray);
/* expected myStringOfArray value: "[\"Hello\",\"World\",\".\",\"How\",\"do\",\"you\",\"do\",\"?\"]" */
let myObjectString = javaScriptToString({
    friend1: "Shurik",
    friend2: "Alex",
    friends: {
        friend3: 123456,
        friend4: {},
        friend5: ["Hola", "amigo"],
        friend6: () => {
            console.log("How you doing?");
        }
    }
});

console.log(myObjectString);
/* expected myObjectString value:
"{friend1: \"Shurik\",friend2: \"Alex\",friends: {friend3: 123456,friend4: {},friend5: [\"Hola\",\"amigo\"],friend6: () => {
            console.log(\"How you doing?\");
        }}}"
*/
let myFunctionString = javaScriptToString(function(a,b) {
  console.log("Just a function");
})

console.log(myFunctionString);
/* expected myFunctionString:
"function(a,b) {
  console.log(\"Just a function\");
}"
*/
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));

/* Expected:

"(function(){
 var Simple = 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);
};

 return Simple;
}())"

*/
var x = [1,2,3];
x[0] = x;
console.log(javaScriptToString(x));

/*
"(function(){ var ___j2s_0 = [null, 2, 3]; ___j2s_0['0'] = ___j2s_0;  return ___j2s_0; }())"
*/

Demo

See, how it's working: https://runkit.com/lopatnov/javascripttostring-demo

Test it with a runkit: https://npm.runkit.com/%40lopatnov%2Fjavascripttostring

Changelog

Version Task
1.7.0 Resolve references to parent elements and itself

Rights and Agreements

License Apache-2.0

Copyright 2019–2020 Oleksandr Lopatnov

@lopatnov/javascripttostring

08 Aug 19:05
Compare
Choose a tag to compare

JavaScriptToString

NPM version
License
Build Status
Twitter

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

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; // default true
  includeFunctionPrototype?: boolean; // default true
  includeBuffers?: boolean; // default true
  nestedObjectsAmount?: number; // default Number.POSITIVE_INFINITY
  nestedArraysAmount?: number; // default Number.POSITIVE_INFINITY
  nestedFunctionsAmount?: number; // default Number.POSITIVE_INFINITY
}

Examples

let myStringOfString = javaScriptToString('Hello world');
console.log(myStringOfString);
/* expected myStringOfString value: "\"Hello world\"" */
let myStringOfArray = javaScriptToString(["Hello", "World", ".", "How", "do", "you", "do", "?"]);
console.log(myStringOfArray);
/* expected myStringOfArray value: "[\"Hello\",\"World\",\".\",\"How\",\"do\",\"you\",\"do\",\"?\"]" */
let myObjectString = javaScriptToString({
    friend1: "Shurik",
    friend2: "Alex",
    friends: {
        friend3: 123456,
        friend4: {},
        friend5: ["Hola", "amigo"],
        friend6: () => {
            console.log("How you doing?");
        }
    }
});

console.log(myObjectString);
/* expected myObjectString value:
"{friend1: \"Shurik\",friend2: \"Alex\",friends: {friend3: 123456,friend4: {},friend5: [\"Hola\",\"amigo\"],friend6: () => {
            console.log(\"How you doing?\");
        }}}"
*/
let myFunctionString = javaScriptToString(function(a,b) {
  console.log("Just a function");
})

console.log(myFunctionString);
/* expected myFunctionString:
"function(a,b) {
  console.log(\"Just a function\");
}"
*/
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));

/* Expected:

"(function(){
 var Simple = 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);
};

 return Simple;
}())"

*/

Demo

See, how it's working: https://runkit.com/lopatnov/javascripttostring-demo

Test it with a runkit: https://npm.runkit.com/%40lopatnov%2Fjavascripttostring

TBD

Resolve references to parent elements and itself

Rights and Agreements

License Apache-2.0

Copyright 2019–2020 Oleksandr Lopatnov

@lopatnov/javascripttostring

08 Aug 14:37
a6f4b7d
Compare
Choose a tag to compare

JavaScriptToString

NPM version
License
Build Status
Twitter

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

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; // default true
  includeFunctionPrototype?: boolean; // default true
  includeBuffers?: boolean; // default true
  nestedObjectsAmount?: number; // default Number.POSITIVE_INFINITY
  nestedArraysAmount?: number; // default Number.POSITIVE_INFINITY
  nestedFunctionsAmount?: number; // default Number.POSITIVE_INFINITY
}

Examples

let myStringOfString = javaScriptToString('Hello world');
console.log(myStringOfString);
/* expected myStringOfString value: "\"Hello world\"" */
let myStringOfArray = javaScriptToString(["Hello", "World", ".", "How", "do", "you", "do", "?"]);
console.log(myStringOfArray);
/* expected myStringOfArray value: "[\"Hello\",\"World\",\".\",\"How\",\"do\",\"you\",\"do\",\"?\"]" */
let myObjectString = javaScriptToString({
    friend1: "Shurik",
    friend2: "Alex",
    friends: {
        friend3: 123456,
        friend4: {},
        friend5: ["Hola", "amigo"],
        friend6: () => {
            console.log("How you doing?");
        }
    }
});

console.log(myObjectString);
/* expected myObjectString value:
"{friend1: \"Shurik\",friend2: \"Alex\",friends: {friend3: 123456,friend4: {},friend5: [\"Hola\",\"amigo\"],friend6: () => {
            console.log(\"How you doing?\");
        }}}"
*/
let myFunctionString = javaScriptToString(function(a,b) {
  console.log("Just a function");
})

console.log(myFunctionString);
/* expected myFunctionString:
"function(a,b) {
  console.log(\"Just a function\");
}"
*/
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));

/* Expected:

"(function(){
 var Simple = 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);
};

 return Simple;
}())"

*/

Demo

See, how it's working: https://runkit.com/lopatnov/javascripttostring-demo

Test it with a runkit: https://npm.runkit.com/%40lopatnov%2Fjavascripttostring

TBD

Resolve references to parent elements and itself

Rights and Agreements

License Apache-2.0

Copyright 2019–2020 Oleksandr Lopatnov

Update security dependencies

22 Mar 22:56
Compare
Choose a tag to compare

— Update typedoc
— Update @lopatnov/get-internal-type

@lopatnov/javascripttostring

22 Dec 20:37
Compare
Choose a tag to compare

JavaScriptToString

NPM version
License
Build Status
Twitter

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

npm install @lopatnov/javascripttostring

Browser

<script src="//lopatnov.github.io/jsToString/dist/javascripttostring.umd.js"></script>

Import package to the project

import javaScriptToString from 'javascripttostring';

or

var javaScriptToString = require("javascripttostring");

Convert JavaScript values into string values

javaScriptToString(value: any, options?: IJ2SOptions) => string

where

interface IJ2SOptions {
  includeFunctionProperties?: boolean; // default true
  includeFunctionPrototype?: boolean; // default true
  includeBuffers?: boolean; // default true
  nestedObjectsAmount?: number; // default Number.POSITIVE_INFINITY
  nestedArraysAmount?: number; // default Number.POSITIVE_INFINITY
  nestedFunctionsAmount?: number; // default Number.POSITIVE_INFINITY
}

Examples

let myStringOfString = javaScriptToString('Hello world');
console.log(myStringOfString);
/* expected myStringOfString value: "\"Hello world\"" */
let myStringOfArray = javaScriptToString(["Hello", "World", ".", "How", "do", "you", "do", "?"]);
console.log(myStringOfArray);
/* expected myStringOfArray value: "[\"Hello\",\"World\",\".\",\"How\",\"do\",\"you\",\"do\",\"?\"]" */
let myObjectString = javaScriptToString({
    friend1: "Shurik",
    friend2: "Alex",
    friends: {
        friend3: 123456,
        friend4: {},
        friend5: ["Hola", "amigo"],
        friend6: () => {
            console.log("How you doing?");
        }
    }
});

console.log(myObjectString);
/* expected myObjectString value:
"{friend1: \"Shurik\",friend2: \"Alex\",friends: {friend3: 123456,friend4: {},friend5: [\"Hola\",\"amigo\"],friend6: () => {
            console.log(\"How you doing?\");
        }}}"
*/
let myFunctionString = javaScriptToString(function(a,b) {
  console.log("Just a function");
})

console.log(myFunctionString);
/* expected myFunctionString:
"function(a,b) {
  console.log(\"Just a function\");
}"
*/
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));

/* Expected:

"(function(){
 var Simple = 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);
};

 return Simple;
}())"

*/

Demo

See, how it's working: https://runkit.com/lopatnov/javascripttostring-demo

Test it with a runkit: https://npm.runkit.com/javascripttostring

TBD

Resolve references to parent elements and itself

Rights and Agreements

License Apache-2.0

Copyright 2019 Oleksandr Lopatnov

JavaScriptToString 1.6.0

16 Nov 20:57
942101a
Compare
Choose a tag to compare

JavaScript value to string runtime converter. It converts a runtime value into string a value.