Skip to content

Commit 06e7c0f

Browse files
committed
fix: Use Object.hasOwn instead of Object.prototype.hasOwnProperty
BREAKING CHANGE: The minimum supported version of Node.js is 16.9 now.
1 parent 8d6d34e commit 06e7c0f

File tree

4 files changed

+13
-12
lines changed

4 files changed

+13
-12
lines changed

lib/sorter.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,19 @@
66
'use strict'
77

88
// from http://stackoverflow.com/questions/1359761/sorting-a-json-object-in-javascript
9-
const ownsProperty = Object.prototype.hasOwnProperty
9+
const ownsProperty = Object.hasOwn
10+
const formatString = Object.prototype.toString
1011
function sortObject (o, { ignoreCase, locale, caseFirst, numeric } = {}) {
1112
if (Array.isArray(o)) {
1213
return o.map(sortObject)
13-
}if (Object.prototype.toString.call(o) !== '[object Object]') {
14+
}if (formatString.call(o) !== '[object Object]') {
1415
return o
1516
}
1617
const sorted = {}
1718
let key
1819
const a = []
1920
for (key in o) {
20-
if (ownsProperty.call(o, key)) {
21+
if (ownsProperty(o, key)) {
2122
a.push(key)
2223
}
2324
}

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
"web"
3737
],
3838
"engines": {
39-
"node": ">= 14"
39+
"node": ">=16.9"
4040
},
4141
"scripts": {
4242
"build": "npm run compile:jsonlint && rollup -c && npm run minify && npm run compile:tests",
@@ -67,7 +67,7 @@
6767
"@rollup/plugin-commonjs": "26.0.1",
6868
"@rollup/plugin-json": "6.1.0",
6969
"@rollup/plugin-node-resolve": "15.2.3",
70-
"@types/node": "22.1.0",
70+
"@types/node": "22.2.0",
7171
"@unixcompat/cat.js": "2.0.0",
7272
"@unixcompat/mv.js": "2.0.0",
7373
"c8": "10.1.2",

pnpm-lock.yaml

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/custom-parser.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ const unescapeMap = {
3535
'/': '/'
3636
}
3737

38-
const ownsProperty = Object.prototype.hasOwnProperty
38+
const ownsProperty = Object.hasOwn
3939

4040
const emptyObject = {}
4141

@@ -323,7 +323,7 @@ function parseInternal (input, options) {
323323
while (position < inputLength) {
324324
skipWhiteSpace()
325325
const key = parseKey()
326-
if (allowDuplicateObjectKeys === false && ownsProperty.call(result, key)) {
326+
if (allowDuplicateObjectKeys === false && ownsProperty(result, key)) {
327327
fail(`Duplicate key: "${key}"`)
328328
}
329329
skipWhiteSpace()

0 commit comments

Comments
 (0)