From b36f737db4e153cfa8f789be187ff5c78481ffa7 Mon Sep 17 00:00:00 2001 From: Roman Date: Sat, 11 Apr 2026 01:17:06 +0100 Subject: [PATCH] fix(deps): remove lodash dependencies --- package.json | 6 ------ sign.js | 24 +++++++++++++++--------- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/package.json b/package.json index d85f183..6563c38 100644 --- a/package.json +++ b/package.json @@ -38,12 +38,6 @@ }, "dependencies": { "jws": "^4.0.1", - "lodash.includes": "^4.3.0", - "lodash.isboolean": "^3.0.3", - "lodash.isinteger": "^4.0.4", - "lodash.isnumber": "^3.0.3", - "lodash.isplainobject": "^4.0.6", - "lodash.isstring": "^4.0.1", "lodash.once": "^4.0.0", "ms": "^2.1.1", "semver": "^7.5.4" diff --git a/sign.js b/sign.js index 82bf526..061ac80 100644 --- a/sign.js +++ b/sign.js @@ -2,12 +2,7 @@ const timespan = require('./lib/timespan'); const PS_SUPPORTED = require('./lib/psSupported'); const validateAsymmetricKey = require('./lib/validateAsymmetricKey'); const jws = require('jws'); -const includes = require('lodash.includes'); -const isBoolean = require('lodash.isboolean'); -const isInteger = require('lodash.isinteger'); -const isNumber = require('lodash.isnumber'); -const isPlainObject = require('lodash.isplainobject'); -const isString = require('lodash.isstring'); + const once = require('lodash.once'); const { KeyObject, createSecretKey, createPrivateKey } = require('crypto') @@ -16,11 +11,22 @@ if (PS_SUPPORTED) { SUPPORTED_ALGS.splice(3, 0, 'PS256', 'PS384', 'PS512'); } +const isBoolean = (value) => value === true || value === false; +const isNumber = (value) => typeof value === 'number'; +const isString = (value) => typeof value === 'string'; + +function isPlainObject(obj) { + if (!obj) return false; + if (typeof obj !== "object") return false; + const proto = Object.getPrototypeOf(obj); + return (proto === null || proto === Object.prototype); +} + const sign_options_schema = { - expiresIn: { isValid: function(value) { return isInteger(value) || (isString(value) && value); }, message: '"expiresIn" should be a number of seconds or string representing a timespan' }, - notBefore: { isValid: function(value) { return isInteger(value) || (isString(value) && value); }, message: '"notBefore" should be a number of seconds or string representing a timespan' }, + expiresIn: { isValid: function(value) { return Number.isInteger(value) || (isString(value) && value); }, message: '"expiresIn" should be a number of seconds or string representing a timespan' }, + notBefore: { isValid: function(value) { return Number.isInteger(value) || (isString(value) && value); }, message: '"notBefore" should be a number of seconds or string representing a timespan' }, audience: { isValid: function(value) { return isString(value) || Array.isArray(value); }, message: '"audience" must be a string or array' }, - algorithm: { isValid: includes.bind(null, SUPPORTED_ALGS), message: '"algorithm" must be a valid string enum value' }, + algorithm: { isValid: (val) => SUPPORTED_ALGS.includes(val), message: '"algorithm" must be a valid string enum value' }, header: { isValid: isPlainObject, message: '"header" must be an object' }, encoding: { isValid: isString, message: '"encoding" must be a string' }, issuer: { isValid: isString, message: '"issuer" must be a string' },