JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 5
  • Score
    100M100P100Q42066F
  • License ISC

‘js2txt’ works just like ‘JSON.stringify’, but it also supports functions. Works in both Node.js and the browser. No dependencies.

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. No dependencies.

Install

NPM

npm install js2txt

CDN

<script type="text/javascript" src="https://cdn.rawgit.com/jackens/js2txt/master/js2txt.js"></script>

Usage

const js2txt = require('js2txt')
const 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'}}