Comparing version 1.2.1 to 1.3.0
43
jsesc.js
@@ -1,2 +0,2 @@ | ||
/*! https://mths.be/jsesc v1.2.1 by @mathias */ | ||
/*! https://mths.be/jsesc v1.3.0 by @mathias */ | ||
;(function(root) { | ||
@@ -61,2 +61,6 @@ | ||
}; | ||
var isNumber = function(value) { | ||
return typeof value == 'number' || | ||
toString.call(value) == '[object Number]'; | ||
}; | ||
var isFunction = function(value) { | ||
@@ -107,4 +111,7 @@ // In a perfect world, the `typeof` check would be sufficient. However, | ||
'lowercaseHex': false, | ||
'numbers': 'decimal', | ||
'indent': '\t', | ||
'__indent__': '' | ||
'__indent__': '', | ||
'__inline1__': false, | ||
'__inline2__': false | ||
}; | ||
@@ -123,2 +130,3 @@ var json = options && options.json; | ||
var indent = options.indent; | ||
var lowercaseHex = options.lowercaseHex; | ||
var oldIndent = ''; | ||
@@ -130,2 +138,6 @@ var inline1 = options.__inline1__; | ||
var isEmpty = true; | ||
var useBinNumbers = options.numbers == 'binary'; | ||
var useOctNumbers = options.numbers == 'octal'; | ||
var useDecNumbers = options.numbers == 'decimal'; | ||
var useHexNumbers = options.numbers == 'hexadecimal'; | ||
@@ -181,2 +193,23 @@ if (json && argument && isFunction(argument.toJSON)) { | ||
(compact ? '' : oldIndent) + ']'; | ||
} else if (isNumber(argument)) { | ||
if (json) { | ||
// Some number values (e.g. `Infinity`) cannot be represented in JSON. | ||
return JSON.stringify(argument); | ||
} | ||
if (useDecNumbers) { | ||
return String(argument); | ||
} | ||
if (useHexNumbers) { | ||
var tmp = argument.toString(16); | ||
if (!lowercaseHex) { | ||
tmp = tmp.toUpperCase(); | ||
} | ||
return '0x' + tmp; | ||
} | ||
if (useBinNumbers) { | ||
return '0b' + argument.toString(2); | ||
} | ||
if (useOctNumbers) { | ||
return '0o' + argument.toString(8); | ||
} | ||
} else if (!isObject(argument)) { | ||
@@ -234,3 +267,3 @@ if (json) { | ||
var hexadecimal = codePoint.toString(16); | ||
if (!options.lowercaseHex) { | ||
if (!lowercaseHex) { | ||
hexadecimal = hexadecimal.toUpperCase(); | ||
@@ -275,3 +308,3 @@ } | ||
var hexadecimal = charCode.toString(16); | ||
if (!options.lowercaseHex) { | ||
if (!lowercaseHex) { | ||
hexadecimal = hexadecimal.toUpperCase(); | ||
@@ -295,3 +328,3 @@ } | ||
jsesc.version = '1.2.1'; | ||
jsesc.version = '1.3.0'; | ||
@@ -298,0 +331,0 @@ /*--------------------------------------------------------------------------*/ |
{ | ||
"name": "jsesc", | ||
"version": "1.2.1", | ||
"version": "1.3.0", | ||
"description": "A JavaScript library for escaping JavaScript strings while generating the shortest possible valid output.", | ||
@@ -5,0 +5,0 @@ "homepage": "https://mths.be/jsesc", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
18234
326