From a08a85df098c6cc0811aa1e97e06342063ed80c6 Mon Sep 17 00:00:00 2001 From: uzlopak Date: Tue, 18 Jan 2022 03:33:16 +0100 Subject: [PATCH] remove sliced --- lib/aggregate.js | 4 ++-- lib/document.js | 6 +++--- lib/drivers/node-mongodb-native/collection.js | 3 +-- lib/model.js | 6 +++--- lib/query.js | 9 ++++----- lib/schematype.js | 2 +- lib/statemachine.js | 9 ++++----- lib/utils.js | 8 -------- package.json | 3 +-- 9 files changed, 19 insertions(+), 31 deletions(-) diff --git a/lib/aggregate.js b/lib/aggregate.js index 4d93251855f..2f95c2e3b22 100644 --- a/lib/aggregate.js +++ b/lib/aggregate.js @@ -140,7 +140,7 @@ Aggregate.prototype.model = function(model) { Aggregate.prototype.append = function() { const args = (arguments.length === 1 && util.isArray(arguments[0])) ? arguments[0] - : utils.args(arguments); + : [...arguments]; if (!args.every(isOperator)) { throw new Error('Arguments must be aggregate pipeline operators'); @@ -372,7 +372,7 @@ Aggregate.prototype.near = function(arg) { */ Aggregate.prototype.unwind = function() { - const args = utils.args(arguments); + const args = [...arguments]; const res = []; for (const arg of args) { diff --git a/lib/document.js b/lib/document.js index 9561be78aa1..8c50229bca2 100644 --- a/lib/document.js +++ b/lib/document.js @@ -885,7 +885,7 @@ function init(self, obj, doc, opts, prefix) { */ Document.prototype.update = function update() { - const args = utils.args(arguments); + const args = [...arguments]; args.unshift({ _id: this._id }); const query = this.constructor.update.apply(this.constructor, args); @@ -962,7 +962,7 @@ Document.prototype.updateOne = function updateOne(doc, options, callback) { */ Document.prototype.replaceOne = function replaceOne() { - const args = utils.args(arguments); + const args = [...arguments]; args.unshift({ _id: this._id }); return this.constructor.replaceOne.apply(this.constructor, args); }; @@ -4136,7 +4136,7 @@ Document.prototype.equals = function(doc) { Document.prototype.populate = function populate() { const pop = {}; - const args = utils.args(arguments); + const args = [...arguments]; let fn; if (args.length > 0) { diff --git a/lib/drivers/node-mongodb-native/collection.js b/lib/drivers/node-mongodb-native/collection.js index 7fa28780d9b..4f129b72a81 100644 --- a/lib/drivers/node-mongodb-native/collection.js +++ b/lib/drivers/node-mongodb-native/collection.js @@ -10,7 +10,6 @@ const Collection = require('mongodb').Collection; const ObjectId = require('./objectid'); const get = require('../../helpers/get'); const getConstructorName = require('../../helpers/getConstructorName'); -const sliced = require('sliced'); const stream = require('stream'); const util = require('util'); @@ -173,7 +172,7 @@ function iter(i) { if (debug) { if (typeof debug === 'function') { debug.apply(_this, - [_this.name, i].concat(sliced(args, 0, args.length - 1))); + [_this.name, i].concat(args.slice(0, args.length - 1))); } else if (debug instanceof stream.Writable) { this.$printToStream(_this.name, i, args, debug); } else { diff --git a/lib/model.js b/lib/model.js index af90e9601cb..db8ee5ee49d 100644 --- a/lib/model.js +++ b/lib/model.js @@ -3065,10 +3065,10 @@ Model.create = function create(doc, options, callback) { options = {}; // Handle falsy callbacks re: #5061 if (typeof last === 'function' || (arguments.length > 1 && !last)) { - cb = last; - args = utils.args(arguments, 0, arguments.length - 1); + args = [...arguments]; + cb = args.pop(); } else { - args = utils.args(arguments); + args = [...arguments]; } if (args.length === 2 && diff --git a/lib/query.js b/lib/query.js index c8fdfbcccd0..2df2148f445 100644 --- a/lib/query.js +++ b/lib/query.js @@ -34,7 +34,6 @@ const sanitizeFilter = require('./helpers/query/sanitizeFilter'); const sanitizeProjection = require('./helpers/query/sanitizeProjection'); const selectPopulatedFields = require('./helpers/query/selectPopulatedFields'); const setDefaultsOnInsert = require('./helpers/setDefaultsOnInsert'); -const slice = require('sliced'); const updateValidators = require('./helpers/updateValidators'); const util = require('util'); const utils = require('./utils'); @@ -379,14 +378,14 @@ Query.prototype.slice = function() { if ('number' === typeof arguments[0]) { this._ensurePath('slice'); path = this._path; - val = slice(arguments); + val = [arguments[0], arguments[1]]; } else { path = arguments[0]; val = arguments[1]; } } else if (arguments.length === 3) { path = arguments[0]; - val = slice(arguments, 1); + val = [arguments[1], arguments[2]]; } const p = {}; @@ -680,10 +679,10 @@ Query.prototype.mod = function() { path = this._path; } else if (arguments.length === 2 && !Array.isArray(arguments[1])) { this._ensurePath('mod'); - val = slice(arguments); + val = [arguments[0], arguments[1]]; path = this._path; } else if (arguments.length === 3) { - val = slice(arguments, 1); + val = [arguments[1], arguments[2]]; path = arguments[0]; } else { val = arguments[1]; diff --git a/lib/schematype.js b/lib/schematype.js index 77b9b4c8154..6cd76ecea7b 100644 --- a/lib/schematype.js +++ b/lib/schematype.js @@ -326,7 +326,7 @@ SchemaType.prototype.default = function(val) { this.defaultValue = val; return this.defaultValue; } else if (arguments.length > 1) { - this.defaultValue = utils.args(arguments); + this.defaultValue = [...arguments]; } return this.defaultValue; }; diff --git a/lib/statemachine.js b/lib/statemachine.js index 7e36dc1ced2..27cf329ce99 100644 --- a/lib/statemachine.js +++ b/lib/statemachine.js @@ -5,7 +5,7 @@ 'use strict'; -const utils = require('./utils'); +const utils = require('./utils'); // eslint-disable-line no-unused-vars /*! * StateMachine represents a minimal `interface` for the @@ -32,7 +32,7 @@ const StateMachine = module.exports = exports = function StateMachine() { */ StateMachine.ctor = function() { - const states = utils.args(arguments); + const states = [...arguments]; const ctor = function() { StateMachine.apply(this, arguments); @@ -122,9 +122,8 @@ StateMachine.prototype.some = function some() { StateMachine.prototype._iter = function _iter(iterMethod) { return function() { - const numArgs = arguments.length; - let states = utils.args(arguments, 0, numArgs - 1); - const callback = arguments[numArgs - 1]; + let states = [...arguments]; + const callback = states.pop(); if (!states.length) states = this.stateNames; diff --git a/lib/utils.js b/lib/utils.js index 6b40c3d24fb..fd6f4692e0d 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -6,7 +6,6 @@ const ms = require('ms'); const mpath = require('mpath'); -const sliced = require('sliced'); const Decimal = require('./types/decimal128'); const ObjectId = require('./types/objectid'); const PopulateOptions = require('./options/PopulateOptions'); @@ -441,13 +440,6 @@ exports.hasKey = function hasKey(obj, key) { return false; }; -/*! - * A faster Array.prototype.slice.call(arguments) alternative - * @api private - */ - -exports.args = sliced; - /*! * process.nextTick helper. * diff --git a/package.json b/package.json index cc8d86661fb..04e97c3bb2c 100644 --- a/package.json +++ b/package.json @@ -27,8 +27,7 @@ "mquery": "4.0.0", "ms": "2.1.2", "regexp-clone": "1.0.0", - "sift": "13.5.2", - "sliced": "1.0.1" + "sift": "13.5.2" }, "devDependencies": { "@babel/core": "7.10.5",