From 77acc334b6d9c35b6e7327a8ee0384fd28557a17 Mon Sep 17 00:00:00 2001 From: Anatole Paine Date: Tue, 21 Apr 2015 19:27:21 -0700 Subject: [PATCH] Support (finite) numerical literals --- index.js | 1 + test/index.js | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/index.js b/index.js index 184d762..efa3bec 100644 --- a/index.js +++ b/index.js @@ -81,6 +81,7 @@ exports.ident = function(val){ exports.literal = function(val){ if (null == val) return 'NULL'; + if (Number.isFinite(val)) return val.toString(); if (Array.isArray(val)) { var vals = val.map(exports.literal) return "(" + vals.join(", ") + ")" diff --git a/test/index.js b/test/index.js index 720d091..37a6771 100644 --- a/test/index.js +++ b/test/index.js @@ -95,5 +95,10 @@ describe('escape.literal(val)', function(){ it('should escape backslashes', function(){ escape.literal('\\whoop\\').should.equal("E'\\\\whoop\\\\'"); }) + + it('should accept numbers', function(){ + escape.literal(9001).should.equal('9001'); + escape.literal(5.50).should.equal('5.5'); + }) })