Package Exports
- js2txt
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (js2txt) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
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'}}