Skip to content

Commit

Permalink
Remove usage of deprecated utils to fix warnings in Node 22
Browse files Browse the repository at this point in the history
  • Loading branch information
KidkArolis authored and lorenwest committed Jun 25, 2024
1 parent fb5033d commit fbcc02e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
7 changes: 3 additions & 4 deletions lib/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
const DeferredConfig = require('../defer').DeferredConfig;
const RawConfig = require('../raw').RawConfig;
let Parser = require('../parser');
const Utils = require('util');
const Path = require('path');
const FileSystem = require('fs');

Expand Down Expand Up @@ -1003,12 +1002,12 @@ util.cloneDeep = function cloneDeep(parent, depth, circular, prototype) {
return parent;
}

if (Utils.isArray(parent)) {
if (Array.isArray(parent)) {
child = [];
} else if (Utils.isRegExp(parent)) {
} else if (parent instanceof RegExp) {
child = new RegExp(parent.source, util.getRegExpFlags(parent));
if (parent.lastIndex) child.lastIndex = parent.lastIndex;
} else if (Utils.isDate(parent)) {
} else if (parent instanceof Date) {
child = new Date(parent.getTime());
} else if (useBuffer && Buffer.isBuffer(parent)) {
child = Buffer.alloc(parent.length);
Expand Down
7 changes: 5 additions & 2 deletions parser.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// External libraries are lazy-loaded only if these file types exist.
const util = require("util");

// webpack can't solve dynamic module
// @see https://github.com/node-config/node-config/issues/755
Expand Down Expand Up @@ -61,7 +60,7 @@ Parser.xmlParser = function(filename, content) {
Parser.jsParser = function(filename, content) {
var configObject = require(filename);

if (configObject.__esModule && util.isObject(configObject.default)) {
if (configObject.__esModule && isObject(configObject.default)) {
return configObject.default
}
return configObject;
Expand Down Expand Up @@ -366,3 +365,7 @@ Parser.setFilesOrder = function(name, newIndex) {
}
return order;
};

function isObject(arg) {
return (arg !== null) && (typeof arg === 'object');
}

0 comments on commit fbcc02e

Please sign in to comment.