From 757e4ebc5146784ebd00664545c6d37231610a61 Mon Sep 17 00:00:00 2001 From: Matthieu Tabarin Date: Thu, 20 Jun 2024 05:26:12 +0100 Subject: [PATCH] deps: make "only" package inside (#1824) closes https://github.com/koajs/koa/issues/1802 --- lib/application.js | 2 +- lib/only.js | 11 +++++++++++ lib/request.js | 2 +- lib/response.js | 2 +- package-lock.json | 6 ------ package.json | 1 - 6 files changed, 14 insertions(+), 10 deletions(-) create mode 100644 lib/only.js diff --git a/lib/application.js b/lib/application.js index bbee69067..ec7524dac 100644 --- a/lib/application.js +++ b/lib/application.js @@ -16,7 +16,7 @@ const Emitter = require('events') const util = require('util') const Stream = require('stream') const http = require('http') -const only = require('only') +const only = require('./only.js') const { HttpError } = require('http-errors') /** @typedef {typeof import ('./context') & { diff --git a/lib/only.js b/lib/only.js new file mode 100644 index 000000000..0551a3354 --- /dev/null +++ b/lib/only.js @@ -0,0 +1,11 @@ +module.exports = (obj, keys) => { + obj = obj || {} + if (typeof keys === 'string') keys = keys.split(/ +/) + const ret = {} + for (let i = 0; i < keys.length; i++) { + const key = keys[i] + if (obj[key] == null) continue + ret[key] = obj[key] + } + return ret +} diff --git a/lib/request.js b/lib/request.js index 7a1a07c12..b756a7a06 100644 --- a/lib/request.js +++ b/lib/request.js @@ -13,7 +13,7 @@ const parse = require('parseurl') const qs = require('querystring') const typeis = require('type-is') const fresh = require('fresh') -const only = require('only') +const only = require('./only.js') const util = require('util') const IP = Symbol('context#ip') diff --git a/lib/response.js b/lib/response.js index cbe587142..e6601569c 100644 --- a/lib/response.js +++ b/lib/response.js @@ -14,7 +14,7 @@ const destroy = require('destroy') const assert = require('assert') const extname = require('path').extname const vary = require('vary') -const only = require('only') +const only = require('./only.js') const util = require('util') const encodeUrl = require('encodeurl') const Stream = require('stream') diff --git a/package-lock.json b/package-lock.json index e9a7c684e..676339fa7 100644 --- a/package-lock.json +++ b/package-lock.json @@ -24,7 +24,6 @@ "http-errors": "^1.6.3", "koa-compose": "^4.1.0", "on-finished": "^2.3.0", - "only": "~0.0.2", "parseurl": "^1.3.2", "statuses": "^1.5.0", "type-is": "^1.6.16", @@ -5380,11 +5379,6 @@ "url": "https://github.com/sponsors/sindresorhus" } }, - "node_modules/only": { - "version": "0.0.2", - "resolved": "https://registry.npmjs.org/only/-/only-0.0.2.tgz", - "integrity": "sha1-Kv3oTQPlC5qO3EROMGEKcCle37Q=" - }, "node_modules/optionator": { "version": "0.9.3", "resolved": "https://registry.npmjs.org/optionator/-/optionator-0.9.3.tgz", diff --git a/package.json b/package.json index a8e3378e4..820ca40cc 100644 --- a/package.json +++ b/package.json @@ -51,7 +51,6 @@ "http-errors": "^1.6.3", "koa-compose": "^4.1.0", "on-finished": "^2.3.0", - "only": "~0.0.2", "parseurl": "^1.3.2", "statuses": "^1.5.0", "type-is": "^1.6.16",