Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/pugjs/js-stringify
Stringify an object so it can be safely inlined in JavaScript code
https://github.com/pugjs/js-stringify
Last synced: 4 months ago
JSON representation
Stringify an object so it can be safely inlined in JavaScript code
- Host: GitHub
- URL: https://github.com/pugjs/js-stringify
- Owner: pugjs
- License: mit
- Created: 2014-12-19T15:45:17.000Z (about 10 years ago)
- Default Branch: master
- Last Pushed: 2024-08-16T09:37:26.000Z (6 months ago)
- Last Synced: 2024-10-01T06:30:58.213Z (4 months ago)
- Language: JavaScript
- Homepage:
- Size: 5.86 KB
- Stars: 19
- Watchers: 10
- Forks: 4
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Security: SECURITY.md
Awesome Lists containing this project
README
# js-stringify
Stringify an object so it can be safely inlined in JavaScript code
[![Build Status](https://img.shields.io/travis/jadejs/js-stringify/master.svg)](https://travis-ci.org/jadejs/js-stringify)
[![Dependency Status](https://img.shields.io/gemnasium/jadejs/js-stringify.svg)](https://gemnasium.com/jadejs/js-stringify)
[![NPM version](https://img.shields.io/npm/v/js-stringify.svg)](https://www.npmjs.org/package/js-stringify)## Installation
npm install js-stringify
## Usage
```js
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: "alert('bad actor')"}) ===
'{"val":"\\u003C\\u002Fscript\\u003E\\u003Cscript\\u003Ealert(\'bad actor\')\\u003C\\u002Fscript\\u003E"}'
);
```## License
MIT