README
js2txt
‘js2txt’ works just like JSON.stringify
, but it also supports functions.
Works in both Node.js and the browser.
Lightweight. No dependencies.
Install
NPM
npm install js2txt
CDN
<script type="text/javascript" src="https://cdn.rawgit.com/jackens/js2txt/master/js2txt.js"></script>
or
<script type="text/javascript" src="https://cdn.rawgit.com/jackens/js2txt/master/js2txt.min.js"></script>
or
<script type="text/javascript" src="https://unpkg.com/js2txt/js2txt.js"></script>
or
<script type="text/javascript" src="https://unpkg.com/js2txt/js2txt.min.js"></script>
Usage
var js2txt = require('js2txt')
var js = {
array: ['a', 'r', 'r', 'a', 'y'],
function: function (arg) {
console.log(arg)
},
null: null,
number: 42,
object: {
string: 'string'
}
}
console.log(JSON.stringify(js))
console.log(js2txt(js))
generates the following output:
{"array":["a","r","r","a","y"],"null":null,"number":42,"object":{"string":"string"}}
{array:['a','r','r','a','y'],function:function (arg) {
console.log(arg)
},null:null,number:42,object:{string:'string'}}