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'];