From 49e9aca1a5f525571d07e18d2af46b5fd8d630e5 Mon Sep 17 00:00:00 2001 From: Punit Soni Date: Wed, 12 Apr 2023 15:37:06 +0530 Subject: [PATCH] fix: plain javascript code added for `once` method resolves #900 --- lib/utils.js | 11 +++++++++++ sign.js | 3 ++- 2 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 lib/utils.js diff --git a/lib/utils.js b/lib/utils.js new file mode 100644 index 0000000..ca94a1b --- /dev/null +++ b/lib/utils.js @@ -0,0 +1,11 @@ +const once = (fn) => { + let called = false; + return (...args) => { + if (!called) { + called = true; + return fn(...args); + } + }; +}; + +module.exports = { once } diff --git a/sign.js b/sign.js index 1aeeabc..d552cfd 100644 --- a/sign.js +++ b/sign.js @@ -1,8 +1,9 @@ const timespan = require('./lib/timespan'); const PS_SUPPORTED = require('./lib/psSupported'); const validateAsymmetricKey = require('./lib/validateAsymmetricKey'); +const { once } = require('./lib/utils'); const jws = require('jws'); -const {includes, isBoolean, isInteger, isNumber, isPlainObject, isString, once} = require('lodash') +const {includes, isBoolean, isInteger, isNumber, isPlainObject, isString} = require('lodash') const { KeyObject, createSecretKey, createPrivateKey } = require('crypto') const SUPPORTED_ALGS = ['RS256', 'RS384', 'RS512', 'ES256', 'ES384', 'ES512', 'HS256', 'HS384', 'HS512', 'none'];