add timerel
This commit is contained in:
parent
808f1f7bc1
commit
1160611eb3
13
package-lock.json
generated
13
package-lock.json
generated
@ -31,6 +31,7 @@
|
||||
"server-destroy": "1.0.1",
|
||||
"tempy": "3.0.0",
|
||||
"text-table": "0.2.0",
|
||||
"timerel": "4.0.0",
|
||||
"versions": "9.3.0"
|
||||
},
|
||||
"engines": {
|
||||
@ -5729,6 +5730,12 @@
|
||||
"dev": true,
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/timerel": {
|
||||
"version": "4.0.0",
|
||||
"resolved": "https://registry.npmjs.org/timerel/-/timerel-4.0.0.tgz",
|
||||
"integrity": "sha512-1BqC1vqQcLNvvTm+27tfD4zSWrDZyhLhPurkjaeWg7bdWybzGN2ySzRAgUlwnlVkPzuu6TCA9nRvspRqIBB6RQ==",
|
||||
"dev": true
|
||||
},
|
||||
"node_modules/tmpl": {
|
||||
"version": "1.0.5",
|
||||
"resolved": "https://registry.npmjs.org/tmpl/-/tmpl-1.0.5.tgz",
|
||||
@ -10116,6 +10123,12 @@
|
||||
"version": "0.2.0",
|
||||
"dev": true
|
||||
},
|
||||
"timerel": {
|
||||
"version": "4.0.0",
|
||||
"resolved": "https://registry.npmjs.org/timerel/-/timerel-4.0.0.tgz",
|
||||
"integrity": "sha512-1BqC1vqQcLNvvTm+27tfD4zSWrDZyhLhPurkjaeWg7bdWybzGN2ySzRAgUlwnlVkPzuu6TCA9nRvspRqIBB6RQ==",
|
||||
"dev": true
|
||||
},
|
||||
"tmpl": {
|
||||
"version": "1.0.5",
|
||||
"resolved": "https://registry.npmjs.org/tmpl/-/tmpl-1.0.5.tgz",
|
||||
|
@ -44,6 +44,7 @@
|
||||
"server-destroy": "1.0.1",
|
||||
"tempy": "3.0.0",
|
||||
"text-table": "0.2.0",
|
||||
"timerel": "4.0.0",
|
||||
"versions": "9.3.0"
|
||||
}
|
||||
}
|
||||
|
38
updates.js
38
updates.js
@ -15,6 +15,7 @@ import {join, dirname} from "path";
|
||||
import {lstatSync, readFileSync, truncateSync, writeFileSync, accessSync} from "fs";
|
||||
import {platform} from "os";
|
||||
import {rootCertificates} from "tls";
|
||||
import {timerel} from "timerel";
|
||||
|
||||
const fetch = fetchEnhanced(nodeFetch);
|
||||
const MAX_SOCKETS = 96;
|
||||
@ -271,39 +272,6 @@ if (!Object.keys(deps).length && !Object.keys(maybeUrlDeps).length) {
|
||||
finish(new Error(`No packages ${include || exclude ? "match the given filters" : "found"}`));
|
||||
}
|
||||
|
||||
const timeData = [
|
||||
[1e3, 1, "ns"],
|
||||
[1e6, 1e3, "µs"],
|
||||
[1e9, 1e6, "ms"],
|
||||
[60e9, 1e9, "sec"],
|
||||
[3600e9, 60e9, "min"],
|
||||
[86400e9, 3600e9, "hour"],
|
||||
[2592e12, 86400e9, "day"],
|
||||
[31536e12, 2592e12, "month"],
|
||||
[Infinity, 31536e12, "year"],
|
||||
];
|
||||
|
||||
function getAge(isoDateString) {
|
||||
if (!isoDateString) return "";
|
||||
const unix = new Date(isoDateString).getTime() * 1e6;
|
||||
if (Number.isNaN(unix)) return "";
|
||||
const diff = (Date.now() * 1e6) - unix;
|
||||
if (diff <= 0) return "none";
|
||||
|
||||
let value, suffix;
|
||||
for (let i = 0; i <= timeData.length; i++) {
|
||||
const entry = timeData[i];
|
||||
const [end, start, unit] = entry || [];
|
||||
if (entry && end && diff < end) {
|
||||
value = Math.round(diff / start);
|
||||
suffix = `${unit}${(value > 1 && !unit.endsWith("s")) ? "s" : ""}`;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return `${value} ${suffix}`;
|
||||
}
|
||||
|
||||
function memoize(fn) {
|
||||
const cache = Object.create(null);
|
||||
return (arg, arg2) => arg in cache ? cache[arg] : cache[arg] = fn(arg, arg2);
|
||||
@ -764,7 +732,7 @@ async function main() {
|
||||
} else {
|
||||
deps[key].new = newRange;
|
||||
deps[key].info = getInfoUrl(data.versions[newVersion] || data, registry, data.name);
|
||||
if (data.time?.[newVersion]) deps[key].age = getAge(data.time[newVersion]);
|
||||
if (data.time?.[newVersion]) deps[key].age = timerel(data.time[newVersion], {noAffix: true});
|
||||
}
|
||||
}
|
||||
|
||||
@ -783,7 +751,7 @@ async function main() {
|
||||
oldPrint: hashRe.test(oldRef) ? oldRef.substring(0, 7) : oldRef,
|
||||
newPrint: hashRe.test(newRef) ? newRef.substring(0, 7) : newRef,
|
||||
info: `https://github.com/${user}/${repo}`,
|
||||
...(newDate ? {age: getAge(newDate)} : {}),
|
||||
...(newDate ? {age: timerel(newDate, {noAffix: true})} : {}),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user