diff --git a/lib/application.js b/lib/application.js index cf6d78c741e..fc9fbe2c162 100644 --- a/lib/application.js +++ b/lib/application.js @@ -22,7 +22,7 @@ var compileETag = require('./utils').compileETag; var compileQueryParser = require('./utils').compileQueryParser; var compileTrust = require('./utils').compileTrust; var resolve = require('node:path').resolve; -var once = require('once') +var once = require('./utils').once; var Router = require('router'); /** diff --git a/lib/utils.js b/lib/utils.js index d53c5a13374..5dbc1544db2 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -267,3 +267,23 @@ function parseExtendedQueryString(str) { allowPrototypes: true }); } + +/** + * Wraps a function so that it can only be called once. + * Subsequent calls return the result of the first invocation. + * + * @param {Function} fn - The function to wrap. + * @returns {Function} A new function that will only call `fn` once. + * @private + */ +exports.once = function once(fn) { + let called = false; + let result; + return function (...args) { + if (!called) { + called = true; + result = fn.apply(this, args); + } + return result; + }; +} diff --git a/package.json b/package.json index bdcd25e60fa..fd3c3750a24 100644 --- a/package.json +++ b/package.json @@ -48,7 +48,6 @@ "merge-descriptors": "^2.0.0", "mime-types": "^3.0.0", "on-finished": "^2.4.1", - "once": "^1.4.0", "parseurl": "^1.3.3", "proxy-addr": "^2.0.7", "qs": "^6.14.0",