Skip to content

Stringify an object so it can be safely inlined in JavaScript code

License

Notifications You must be signed in to change notification settings

pugjs/js-stringify

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

js-stringify

Stringify an object so it can be safely inlined in JavaScript code

Build Status Dependency Status NPM version

Installation

npm install js-stringify

Usage

var assert = require('assert');
var stringify = require('js-stringify');

assert(stringify('foo') === '"foo"');
assert(stringify('foo\u2028bar\u2029baz') === '"foo\\u2028bar\\u2029baz"');
assert(stringify(new Date('2014-12-19T03:42:00.000Z')) === 'new Date("2014-12-19T03:42:00.000Z")');
assert(stringify({foo: 'bar'}) === '{"foo":"bar"}');
assert(stringify(undefined) === 'undefined');
assert(stringify(null) === 'null');
assert(
  stringify({val: "</script><script>alert('bad actor')</script>"}) ===
  '{"val":"\\u003C\\u002Fscript\\u003E\\u003Cscript\\u003Ealert(\'bad actor\')\\u003C\\u002Fscript\\u003E"}'
);

License

MIT

About

Stringify an object so it can be safely inlined in JavaScript code

Resources

License

Security policy

Stars

Watchers

Forks

Packages

No packages published