Skip to content

Commit

Permalink
Merge pull request #248 from FlowFuse/remove-hasOwn
Browse files Browse the repository at this point in the history
Remove Object.hasOwn
  • Loading branch information
Steve-Mcl authored Mar 28, 2024
2 parents 96610b5 + b461a4f commit d9dad46
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 13 deletions.
9 changes: 5 additions & 4 deletions lib/logging/log.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const LogBuffer = require('./logBuffer')
const { hasProperty } = require('../utils')

let buffer
let mqtt
Expand All @@ -21,13 +22,13 @@ function NRlog (msg) {
let jsMsg
try {
jsMsg = JSON.parse(msg)
if (!hasProperty(jsMsg, 'ts') && !hasProperty(jsMsg, 'level')) {
// not a NR log message
jsMsg = { ts: Date.now(), level: '', msg }
}
} catch (eee) {
jsMsg = { ts: Date.now(), level: '', msg }
}
if (!Object.hasOwn(jsMsg, 'ts') && !Object.hasOwn(jsMsg, 'level')) {
// not a NR log message
jsMsg = { ts: Date.now(), level: '', msg }
}
const date = new Date(jsMsg.ts)
if (typeof jsMsg.msg !== 'string') {
jsMsg.msg = JSON.stringify(jsMsg.msg)
Expand Down
2 changes: 1 addition & 1 deletion lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ function isObject (object) {
}

/**
* Test if an object has a property
* Test if an object has a property - Node 14 friendly version of Object.hasOwn
* @param {Object} object - an object to check for a property
* @param {String} property - the name of the property to check for
* @returns `true` if the object has the property, `false` otherwise
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
"lint": "eslint -c .eslintrc \"*.js\" \"lib/**/*.js\" \"frontend/**/*.js\" \"frontend/**/*.html\" \"test/**/*.js\"",
"lint:fix": "eslint -c .eslintrc \"*.js\" \"lib/**/*.js\" \"frontend/**/*.js\" \"frontend/**/*.html\" \"test/**/*.js\" --fix",
"test": "npm run test:lib && npm run test:frontend",
"test:lib": "mocha test/unit/**/*_spec.js",
"test:frontend": "mocha test/unit/frontend/**/*.spec.js"
"test:lib": "mocha 'test/unit/**/*_spec.js'",
"test:frontend": "mocha 'test/unit/frontend/**/*.spec.js'"
},
"bin": {
"flowforge-device-agent": "./index.js",
Expand Down
7 changes: 1 addition & 6 deletions test/unit/lib/logging/log_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,7 @@ describe('Log', function () {
msg: 'm5'
}))
Log.info('m6')
Log.NRlog(JSON.stringify({
level: 'info',
ts: Date.now(),
msg: 'm7'
}))

Log.NRlog('m7')
const bufferedMessages = Log.getBufferedMessages()
// Verify we buffered the last 5
bufferedMessages.should.have.length(5)
Expand Down

0 comments on commit d9dad46

Please sign in to comment.