Skip to content

Commit

Permalink
fix: Use Object.hasOwn instead of Object.prototype.hasOwnProperty
Browse files Browse the repository at this point in the history
BREAKING CHANGE: The minimum supported version of Node.js is 16.9 now.
  • Loading branch information
prantlf committed Aug 9, 2024
1 parent 8d6d34e commit 06e7c0f
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 12 deletions.
7 changes: 4 additions & 3 deletions lib/sorter.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,19 @@
'use strict'

// from http://stackoverflow.com/questions/1359761/sorting-a-json-object-in-javascript
const ownsProperty = Object.prototype.hasOwnProperty
const ownsProperty = Object.hasOwn
const formatString = Object.prototype.toString
function sortObject (o, { ignoreCase, locale, caseFirst, numeric } = {}) {
if (Array.isArray(o)) {
return o.map(sortObject)
}if (Object.prototype.toString.call(o) !== '[object Object]') {
}if (formatString.call(o) !== '[object Object]') {
return o
}
const sorted = {}
let key
const a = []
for (key in o) {
if (ownsProperty.call(o, key)) {
if (ownsProperty(o, key)) {
a.push(key)
}
}
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"web"
],
"engines": {
"node": ">= 14"
"node": ">=16.9"
},
"scripts": {
"build": "npm run compile:jsonlint && rollup -c && npm run minify && npm run compile:tests",
Expand Down Expand Up @@ -67,7 +67,7 @@
"@rollup/plugin-commonjs": "26.0.1",
"@rollup/plugin-json": "6.1.0",
"@rollup/plugin-node-resolve": "15.2.3",
"@types/node": "22.1.0",
"@types/node": "22.2.0",
"@unixcompat/cat.js": "2.0.0",
"@unixcompat/mv.js": "2.0.0",
"c8": "10.1.2",
Expand Down
10 changes: 5 additions & 5 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/custom-parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const unescapeMap = {
'/': '/'
}

const ownsProperty = Object.prototype.hasOwnProperty
const ownsProperty = Object.hasOwn

const emptyObject = {}

Expand Down Expand Up @@ -323,7 +323,7 @@ function parseInternal (input, options) {
while (position < inputLength) {
skipWhiteSpace()
const key = parseKey()
if (allowDuplicateObjectKeys === false && ownsProperty.call(result, key)) {
if (allowDuplicateObjectKeys === false && ownsProperty(result, key)) {
fail(`Duplicate key: "${key}"`)
}
skipWhiteSpace()
Expand Down

0 comments on commit 06e7c0f

Please sign in to comment.