From 6c9f745292c47c0b8d96b97ab47e5189f375e8b5 Mon Sep 17 00:00:00 2001 From: Ofer Shapira <2589702+ofershap@users.noreply.github.com> Date: Thu, 26 Feb 2026 22:48:26 +0200 Subject: [PATCH] replace ms with ms-tiny ms-tiny is API-compatible and ships ESM + CJS with TypeScript types. 833 bytes gzipped, zero dependencies. Wrapped ms() call in try-catch in timespan.js since ms-tiny throws on invalid input instead of returning undefined. Made-with: Cursor --- lib/timespan.js | 8 +++++--- package.json | 2 +- test/jwt.asymmetric_signing.tests.js | 2 +- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/lib/timespan.js b/lib/timespan.js index e5098690..b13a1ba1 100644 --- a/lib/timespan.js +++ b/lib/timespan.js @@ -1,11 +1,13 @@ -var ms = require('ms'); +var ms = require('ms-tiny'); module.exports = function (time, iat) { var timestamp = iat || Math.floor(Date.now() / 1000); if (typeof time === 'string') { - var milliseconds = ms(time); - if (typeof milliseconds === 'undefined') { + var milliseconds; + try { + milliseconds = ms(time); + } catch (e) { return; } return Math.floor(timestamp + milliseconds / 1000); diff --git a/package.json b/package.json index eab30c0a..0c07f173 100644 --- a/package.json +++ b/package.json @@ -44,7 +44,7 @@ "lodash.isplainobject": "^4.0.6", "lodash.isstring": "^4.0.1", "lodash.once": "^4.0.0", - "ms": "^2.1.1", + "ms-tiny": "^1.1.0", "semver": "^7.5.4" }, "devDependencies": { diff --git a/test/jwt.asymmetric_signing.tests.js b/test/jwt.asymmetric_signing.tests.js index a8472d52..08064ef5 100644 --- a/test/jwt.asymmetric_signing.tests.js +++ b/test/jwt.asymmetric_signing.tests.js @@ -5,7 +5,7 @@ const path = require('path'); const expect = require('chai').expect; const assert = require('chai').assert; -const ms = require('ms'); +const ms = require('ms-tiny'); function loadKey(filename) { return fs.readFileSync(path.join(__dirname, filename));