Skip to content

Commit e1a5ca3

Browse files
author
Forbes Lindesay
committed
Initial code
0 parents  commit e1a5ca3

File tree

7 files changed

+89
-0
lines changed

7 files changed

+89
-0
lines changed

.gitignore

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
lib-cov
2+
*.seed
3+
*.log
4+
*.csv
5+
*.dat
6+
*.out
7+
*.pid
8+
*.gz
9+
pids
10+
logs
11+
results
12+
npm-debug.log
13+
node_modules

.travis.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
language: node_js
2+
node_js:
3+
- "0.10"

LICENSE

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Copyright (c) 2014 Forbes Lindesay
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy
4+
of this software and associated documentation files (the "Software"), to deal
5+
in the Software without restriction, including without limitation the rights
6+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7+
copies of the Software, and to permit persons to whom the Software is
8+
furnished to do so, subject to the following conditions:
9+
10+
The above copyright notice and this permission notice shall be included in
11+
all copies or substantial portions of the Software.
12+
13+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19+
THE SOFTWARE.

README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# js-stringify
2+
3+
Stringify an object so it can be safely inlined in JavaScript code
4+
5+
[![Build Status](https://img.shields.io/travis/jadejs/js-stringify/master.svg)](https://travis-ci.org/jadejs/js-stringify)
6+
[![Dependency Status](https://img.shields.io/gemnasium/jadejs/js-stringify.svg)](https://gemnasium.com/jadejs/js-stringify)
7+
[![NPM version](https://img.shields.io/npm/v/js-stringify.svg)](https://www.npmjs.org/package/js-stringify)
8+
9+
## Installation
10+
11+
npm install js-stringify
12+
13+
## License
14+
15+
MIT

index.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
'use strict';
2+
3+
module.exports = stringify;
4+
function stringify(obj) {
5+
if (obj instanceof Date) {
6+
return 'new Date(' + stringify(obj.toISOString()) + ')';
7+
}
8+
return JSON.stringify(obj)
9+
.replace(/\u2028/g, '\\u2028')
10+
.replace(/\u2029/g, '\\u2029');
11+
}

package.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"name": "js-stringify",
3+
"version": "0.0.0",
4+
"description": "Stringify an object so it can be safely inlined in JavaScript code",
5+
"keywords": [],
6+
"dependencies": {},
7+
"devDependencies": {},
8+
"scripts": {
9+
"test": "node test"
10+
},
11+
"repository": {
12+
"type": "git",
13+
"url": "https://github.com/jadejs/js-stringify.git"
14+
},
15+
"author": "ForbesLindesay",
16+
"license": "MIT"
17+
}

test/index.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
'use strict';
2+
3+
var assert = require('assert');
4+
var stringify = require('../');
5+
6+
assert(stringify('foo') === '"foo"');
7+
assert(stringify('foo\u2028bar\u2029baz') === '"foo\\u2028bar\\u2029baz"');
8+
assert(stringify(new Date('2014-12-19T03:42:00.000Z')) === 'new Date("2014-12-19T03:42:00.000Z")');
9+
assert(stringify({foo: 'bar'}) === '{"foo":"bar"}');
10+
11+
console.log('tests passed');

0 commit comments

Comments
 (0)