Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

node-stringify

Package Overview
Dependencies
Maintainers
1
Versions
20
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

node-stringify - npm Package Compare versions

Comparing version 0.0.9 to 0.0.10

7

node-stringify.js

@@ -6,5 +6,10 @@ var _ = require('underscore')

if (_.isUndefined(obj)) { return 'undefined' }
if (_.isRegExp(obj) || _.isFunction(obj) || _.isNumber(obj) || _.isBoolean(obj)) {
if (_.isRegExp(obj) || _.isNumber(obj) || _.isBoolean(obj)) {
return obj.toString()
}
if (_.isFunction(obj)) {
return '(' + obj.toString() + ')';
}
if (_.isString(obj)) { return "'" + obj.replace(/'/g, "\\'") + "'" }

@@ -11,0 +16,0 @@

2

package.json
{
"name": "node-stringify",
"version": "0.0.9",
"version": "0.0.10",
"author": {

@@ -5,0 +5,0 @@ "name": "Chiang Fu",

var stringify = require('../node-stringify.js')
describe('node-stringify test', function () {
var testEval = function (obj) {
expect(eval(stringify(obj))).toEqual(obj)
}
it('should stringify null', function () {
expect(stringify(null)).toBe('null')
testEval(null)
})

@@ -11,2 +15,3 @@

expect(stringify(undefined)).toBe('undefined')
testEval(undefined)
})

@@ -16,6 +21,7 @@

expect(stringify(/test/gi)).toBe('/test/gi')
testEval(/test/gi)
})
it('should stringify a function', function () {
expect(stringify(function (x, y, z) {})).toBe('function (x, y, z) {}')
expect(stringify(function (x, y, z) {})).toBe('(function (x, y, z) {})')
})

@@ -25,7 +31,8 @@

expect(stringify(100)).toBe('100')
testEval(100)
})
it('should stringify a date', function () {
expect(stringify(new Date(1000))).toBe('new Date(1000)');
expect(eval(stringify(new Date(1000)))).toEqual(new Date(1000));
expect(stringify(new Date(1000))).toBe('new Date(1000)')
testEval(new Date(1000))
})

@@ -35,2 +42,3 @@

expect(stringify('abc')).toBe("'abc'")
testEval('abc')
})

@@ -40,3 +48,3 @@

expect(stringify("a'bc")).toBe("'a\\'bc'")
expect(eval(stringify("a'bc"))).toBe("a'bc")
testEval("a'bc")
})

@@ -46,25 +54,25 @@

expect(stringify([])).toBe('[]')
testEval([])
})
it('should stringify an array containning simple objects', function () {
expect(eval(stringify([77, null, undefined, "a'bc"]))).toEqual([77, null, undefined, "a'bc"])
testEval([77, null, undefined, "a'bc"])
})
it('should stringify an empty object', function () {
expect(eval(stringify({}))).toEqual({})
expect(stringify({})).toBe('({})')
testEval({})
})
it('should stringify an object with some fields', function () {
expect(eval(stringify({a: 123, b: 'abc'}))).toEqual({a: 123, b: 'abc'})
testEval({a: 123, b: 'abc'})
})
it('should stringify an array containning objects', function () {
expect(eval(stringify([{a: 123}, ['abc', {}]])))
.toEqual([{a: 123}, ['abc', {}]])
testEval([{a: 123}, ['abc', {}]])
})
it('should stringify an object containning arrays', function () {
expect(eval(stringify({a: [1, 2, 3], b: /foo$/i})))
.toEqual({a: [1, 2, 3], b: /foo$/i})
testEval({a: [1, 2, 3], b: /foo$/i})
})
})
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc