object-inspect
Advanced tools
Comparing version 1.13.2 to 1.13.3
@@ -8,2 +8,14 @@ # Changelog | ||
## [v1.13.3](https://github.com/inspect-js/object-inspect/compare/v1.13.2...v1.13.3) - 2024-11-09 | ||
### Commits | ||
- [actions] split out node 10-20, and 20+ [`44395a8`](https://github.com/inspect-js/object-inspect/commit/44395a8fc1deda6718a5e125e86b9ffcaa1c7580) | ||
- [Fix] `quoteStyle`: properly escape only the containing quotes [`5137f8f`](https://github.com/inspect-js/object-inspect/commit/5137f8f7bea69a7fc671bb683fd35f244f38fc52) | ||
- [Refactor] clean up `quoteStyle` code [`450680c`](https://github.com/inspect-js/object-inspect/commit/450680cd50de4e689ee3b8e1d6db3a1bcf3fc18c) | ||
- [Tests] add `quoteStyle` escaping tests [`e997c59`](https://github.com/inspect-js/object-inspect/commit/e997c595aeaea84fd98ca35d7e1c3b5ab3ae26e0) | ||
- [Dev Deps] update `auto-changelog`, `es-value-fixtures`, `tape` [`d5a469c`](https://github.com/inspect-js/object-inspect/commit/d5a469c99ec07ccaeafc36ac4b36a93285086d48) | ||
- [Tests] replace `aud` with `npm audit` [`fb7815f`](https://github.com/inspect-js/object-inspect/commit/fb7815f9b72cae277a04f65bbb0543f85b88be62) | ||
- [Dev Deps] update `mock-property` [`11c817b`](https://github.com/inspect-js/object-inspect/commit/11c817bf10392aa017755962ba6bc89d731359ee) | ||
## [v1.13.2](https://github.com/inspect-js/object-inspect/compare/v1.13.1...v1.13.2) - 2024-06-21 | ||
@@ -10,0 +22,0 @@ |
20
index.js
@@ -72,6 +72,17 @@ var hasMap = typeof Map === 'function' && Map.prototype; | ||
var quotes = { | ||
__proto__: null, | ||
'double': '"', | ||
single: "'" | ||
}; | ||
var quoteREs = { | ||
__proto__: null, | ||
'double': /(["\\])/g, | ||
single: /(['\\])/g | ||
}; | ||
module.exports = function inspect_(obj, options, depth, seen) { | ||
var opts = options || {}; | ||
if (has(opts, 'quoteStyle') && (opts.quoteStyle !== 'single' && opts.quoteStyle !== 'double')) { | ||
if (has(opts, 'quoteStyle') && !has(quotes, opts.quoteStyle)) { | ||
throw new TypeError('option "quoteStyle" must be "single" or "double"'); | ||
@@ -271,3 +282,4 @@ } | ||
function wrapQuotes(s, defaultStyle, opts) { | ||
var quoteChar = (opts.quoteStyle || defaultStyle) === 'double' ? '"' : "'"; | ||
var style = opts.quoteStyle || defaultStyle; | ||
var quoteChar = quotes[style]; | ||
return quoteChar + s + quoteChar; | ||
@@ -430,4 +442,6 @@ } | ||
} | ||
var quoteRE = quoteREs[opts.quoteStyle || 'single']; | ||
quoteRE.lastIndex = 0; | ||
// eslint-disable-next-line no-control-regex | ||
var s = $replace.call($replace.call(str, /(['\\])/g, '\\$1'), /[\x00-\x1f]/g, lowbyte); | ||
var s = $replace.call($replace.call(str, quoteRE, '\\$1'), /[\x00-\x1f]/g, lowbyte); | ||
return wrapQuotes(s, 'single', opts); | ||
@@ -434,0 +448,0 @@ } |
{ | ||
"name": "object-inspect", | ||
"version": "1.13.2", | ||
"version": "1.13.3", | ||
"description": "string representations of objects in node and the browser", | ||
@@ -10,6 +10,6 @@ "main": "index.js", | ||
"@pkgjs/support": "^0.0.6", | ||
"auto-changelog": "^2.4.0", | ||
"auto-changelog": "^2.5.0", | ||
"core-js": "^2.6.12", | ||
"error-cause": "^1.0.8", | ||
"es-value-fixtures": "^1.4.2", | ||
"es-value-fixtures": "^1.5.0", | ||
"eslint": "=8.8.0", | ||
@@ -25,3 +25,3 @@ "for-each": "^0.3.3", | ||
"make-arrow-function": "^1.2.0", | ||
"mock-property": "^1.0.3", | ||
"mock-property": "^1.1.0", | ||
"npmignore": "^0.3.1", | ||
@@ -32,3 +32,3 @@ "nyc": "^10.3.2", | ||
"string.prototype.repeat": "^1.0.0", | ||
"tape": "^5.8.1" | ||
"tape": "^5.9.0" | ||
}, | ||
@@ -45,3 +45,3 @@ "scripts": { | ||
"test:corejs": "nyc tape test-core-js.js 'test/*.js'", | ||
"posttest": "npx aud --production", | ||
"posttest": "npx npm@'>=10.2' audit --production", | ||
"version": "auto-changelog && git add CHANGELOG.md", | ||
@@ -48,0 +48,0 @@ "postversion": "auto-changelog && git add CHANGELOG.md && git commit --no-edit --amend && git tag -f \"v$(node -e \"console.log(require('./package.json').version)\")\"" |
@@ -16,3 +16,12 @@ 'use strict'; | ||
t.equal(inspect('"', { quoteStyle: 'single' }), '\'"\'', 'double quote, quoteStyle: "single"'); | ||
t.equal(inspect('"', { quoteStyle: 'double' }), '"\\""', 'double quote, quoteStyle: "double"'); | ||
t.equal(inspect('\'', { quoteStyle: 'single' }), '\'\\\'\'', 'single quote, quoteStyle: "single"'); | ||
t.equal(inspect('\'', { quoteStyle: 'double' }), '"\'"', 'single quote, quoteStyle: "double"'); | ||
t.equal(inspect('`', { quoteStyle: 'single' }), '\'`\'', 'backtick, quoteStyle: "single"'); | ||
t.equal(inspect('`', { quoteStyle: 'double' }), '"`"', 'backtick, quoteStyle: "double"'); | ||
t.end(); | ||
}); |
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
101090
1516