-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
site: fix type errors in JS files (#9354)
- Loading branch information
Showing
20 changed files
with
164 additions
and
85 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,28 @@ | ||
// adapted from https://github.com/digplan/time-ago | ||
// https://github.com/digplan/time-ago/blob/master/license.txt | ||
const o = { | ||
second: 1000, | ||
minute: 60 * 1000, | ||
hour: 60 * 1000 * 60, | ||
day: 24 * 60 * 1000 * 60, | ||
week: 7 * 24 * 60 * 1000 * 60, | ||
month: 30 * 24 * 60 * 1000 * 60, | ||
year: 365 * 24 * 60 * 1000 * 60 | ||
const formatter = new Intl.RelativeTimeFormat(undefined, { | ||
numeric: 'auto' | ||
}); | ||
|
||
const DIVISIONS = { | ||
seconds: 60, | ||
minutes: 60, | ||
hours: 24, | ||
days: 7, | ||
weeks: 4.34524, | ||
months: 12, | ||
years: Number.POSITIVE_INFINITY | ||
}; | ||
|
||
export const ago = (nd, s) => { | ||
var r = Math.round, | ||
dir = ' ago', | ||
pl = function (v, n) { | ||
return s === undefined ? n + ' ' + v + (n > 1 ? 's' : '') + dir : n + v.substring(0, 1); | ||
}, | ||
ts = Date.now() - new Date(nd).getTime(), | ||
ii; | ||
if (ts < 0) { | ||
ts *= -1; | ||
dir = ' from now'; | ||
} | ||
for (var i in o) { | ||
if (r(ts) < o[i]) return pl(ii || 'm', r(ts / (o[ii] || 1))); | ||
ii = i; | ||
/** | ||
* @param {Date} date | ||
*/ | ||
export const ago = (date) => { | ||
let duration = (date.getTime() - new Date().getTime()) / 1000; | ||
|
||
for (const [name, amount] of Object.entries(DIVISIONS)) { | ||
if (Math.abs(duration) < amount) { | ||
const format = /** @type {keyof(DIVISIONS)} */ (name); | ||
return formatter.format(Math.round(duration), format); | ||
} | ||
duration /= amount; | ||
} | ||
return pl(i, r(ts / o[i])); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
sites/svelte.dev/src/routes/(authed)/repl/[id]/downloadBlob.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.