Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX]:NodeJS 20 Deprecation Warning DEP0170 #218 #296

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions lib/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* @author 0@39.yt (Yurij Mikhalevich)
*/
'use strict';
const ObjectID = require('mongodb').ObjectID;
const { ObjectId } = require('mongodb');


/**
Expand All @@ -26,30 +26,33 @@
* @param {Array} optParents Object's parents
* @returns {Object} Adjusted clone of object
*/
// eslint-disable-next-line max-statements, complexity
function cloneMeta(node, optParents) {
if (!((node !== null && typeof node === 'object') || typeof node === 'function')
|| (node instanceof ObjectID) || (node instanceof Buffer)) {
if (typeof node !== 'object' || typeof node === 'function' || node === null) {
return node;
}
if (node instanceof ObjectId || node instanceof Buffer) {
return node;
}
let copy = Array.isArray(node) ? [] : {};
if (node instanceof Date) {
return new Date(node.getTime());
} else if (node instanceof Error) {
// This is needed because Error's message, name and stack isn't accessible when cycling through properties
// This is needed because Error's message, name, and stack aren't accessible when cycling through properties
copy = { message: node.message, name: node.name, stack: node.stack };
}
optParents = optParents || [];
optParents.push(node);
for (const key in node) {
if (!Object.prototype.hasOwnProperty.call(node, key)) {
continue;

Check warning on line 48 in lib/helpers.js

View workflow job for this annotation

GitHub Actions / unit-tests (16, v6.0-latest)

Unexpected use of continue statement

Check warning on line 48 in lib/helpers.js

View workflow job for this annotation

GitHub Actions / unit-tests (18, v6.0-latest)

Unexpected use of continue statement

Check warning on line 48 in lib/helpers.js

View workflow job for this annotation

GitHub Actions / unit-tests (18, v5.0-latest)

Unexpected use of continue statement

Check warning on line 48 in lib/helpers.js

View workflow job for this annotation

GitHub Actions / unit-tests (20, v6.0-latest)

Unexpected use of continue statement

Check warning on line 48 in lib/helpers.js

View workflow job for this annotation

GitHub Actions / unit-tests (20, v5.0-latest)

Unexpected use of continue statement

Check warning on line 48 in lib/helpers.js

View workflow job for this annotation

GitHub Actions / unit-tests (20, v4.4-latest)

Unexpected use of continue statement
}
const value = node[key];
let newKey = key;
if (newKey.includes('.') || newKey.includes('$')) {
newKey = newKey.replace(/\./g, '[dot]').replace(/\$/g, '[$]');
}
if ((value !== null && typeof value === 'object') || typeof value === 'function') {
if (typeof value === 'object' || typeof value === 'function') {
if (optParents.indexOf(value) === -1) {
copy[newKey] = cloneMeta(value, optParents);
} else {
Expand Down
Loading
Loading