Skip to content

Commit

Permalink
Remove dayjs dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
soulgalore committed Oct 5, 2024
1 parent 8f4b71b commit 54cac1e
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 17 deletions.
5 changes: 2 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ const { name, version, homepage } = require('./package');

const urlParser = require('url');
const crypto = require('crypto');
const dayjs = require('dayjs');
const debug = require('debug')(name);
const ignoredEvents = require('./lib/ignoredEvents');
const { parseRequestCookies, formatCookie } = require('./lib/cookies');
Expand All @@ -28,7 +27,7 @@ function addFromFirstRequest(page, params) {
if (!page.__timestamp) {
page.__wallTime = params.wallTime;
page.__timestamp = params.timestamp;
page.startedDateTime = dayjs.unix(params.wallTime).toISOString(); //epoch float64, eg 1440589909.59248
page.startedDateTime = new Date(params.wallTime * 1000).toISOString();
// URL is better than blank, and it's what devtools uses.
page.title = page.title === '' ? params.request.url : page.title;
}
Expand Down Expand Up @@ -245,7 +244,7 @@ module.exports = {
// (see https://cs.chromium.org/chromium/src/third_party/WebKit/Source/platform/network/ResourceLoadTiming.h?q=requestTime+package:%5Echromium$&dr=CSs&l=84)
const entrySecs =
page.__wallTime + (params.timestamp - page.__timestamp);
entry.startedDateTime = dayjs.unix(entrySecs).toISOString();
entry.startedDateTime = new Date(entrySecs * 1000).toISOString();
}
break;

Expand Down
21 changes: 16 additions & 5 deletions lib/cookies.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,27 @@
const Cookie = require('tough-cookie').Cookie;
const dayjs = require('dayjs');

function formatCookie(cookie) {
let expiresISO;

if (cookie.expires instanceof Date) {
expiresISO = cookie.expires.toISOString();
} else if (cookie.expires === 'Infinity' || cookie.expires === null) {
expiresISO = null;
} else {
const date = new Date(cookie.expires);
if (!isNaN(date)) {
expiresISO = date.toISOString();
} else {
// There's no date
expiresISO = null;
}
}
return {
name: cookie.key || cookie.name,
value: cookie.value,
path: cookie.path || undefined, // must be undefined, not null, to exclude empty path
domain: cookie.domain || undefined, // must be undefined, not null, to exclude empty domain
expires:
cookie.expires === 'Infinity'
? undefined
: dayjs(cookie.expires).toISOString(),
expires: expiresISO,
httpOnly: cookie.httpOnly,
secure: cookie.secure
};
Expand Down
3 changes: 1 addition & 2 deletions lib/entryFromResponse.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
'use strict';
const dayjs = require('dayjs');
const max = Math.max;

const {
Expand Down Expand Up @@ -186,7 +185,7 @@ module.exports = function(entry, response, page, options) {
// (see https://cs.chromium.org/chromium/src/third_party/WebKit/Source/platform/network/ResourceLoadTiming.h?q=requestTime+package:%5Echromium$&dr=CSs&l=84)
const entrySecs =
page.__wallTime + (timing.requestTime - page.__timestamp);
entry.startedDateTime = dayjs.unix(entrySecs).toISOString();
entry.startedDateTime = new Date(entrySecs * 1000).toISOString();

const queuedMillis =
(timing.requestTime - entry.__requestWillBeSentTime) * 1000;
Expand Down
6 changes: 0 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
"prettier": "~1.11.1"
},
"dependencies": {
"dayjs": "1.11.7",
"debug": "4.3.4",
"tough-cookie": "5.0.0"
}
Expand Down

0 comments on commit 54cac1e

Please sign in to comment.