mirror of
https://github.com/fluxerapp/fluxer
synced 2026-10-18 05:25:40 +09:00
refactor(pkgs): share vitest config and dedupe helpers (#3384)
This commit is contained in:
1 parent
5695510980
commit
575a5adbef
43 files changed
+172
-874
No files matched your search
@@ -16,7 +16,11 @@ function toClampedTimestamp(timestamp: number): number {
|
||||
}
|
||||
|
||||
export function extractTimestamp(snowflake: string): number {
|
||||
return extractTimestampFromSnowflake(snowflake);
|
||||
try {
|
||||
return extractTimestampWithEpoch(BigInt(snowflake), FLUXER_EPOCH);
|
||||
} catch (_error) {
|
||||
return Number.NaN;
|
||||
}
|
||||
}
|
||||
|
||||
export function extractTimestampBigInt(snowflake: bigint): number {
|
||||
@@ -86,17 +90,8 @@ export function age(snowflake: string): number {
|
||||
return Date.now() - timestamp;
|
||||
}
|
||||
|
||||
export function extractTimestampFromSnowflake(snowflake: string, epoch?: string | bigint): number {
|
||||
try {
|
||||
const epochBigInt = epoch != null ? (typeof epoch === 'string' ? BigInt(epoch) : epoch) : FLUXER_EPOCH;
|
||||
return extractTimestampWithEpoch(BigInt(snowflake), epochBigInt);
|
||||
} catch (_error) {
|
||||
return Number.NaN;
|
||||
}
|
||||
}
|
||||
|
||||
export function extractTimestampFromSnowflakeAsDate(snowflake: string, epoch?: string | bigint): Date {
|
||||
const timestamp = extractTimestampFromSnowflake(snowflake, epoch);
|
||||
export function extractTimestampFromSnowflakeAsDate(snowflake: string): Date {
|
||||
const timestamp = extractTimestamp(snowflake);
|
||||
if (Number.isNaN(timestamp)) {
|
||||
return new Date();
|
||||
}
|
||||
|
||||
@@ -1,18 +1,3 @@
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
import {defineConfig} from 'vitest/config';
|
||||
|
||||
export default defineConfig({
|
||||
resolve: {tsconfigPaths: true},
|
||||
test: {
|
||||
globals: true,
|
||||
environment: 'node',
|
||||
include: ['**/*.{test,spec}.{ts,tsx}'],
|
||||
exclude: ['node_modules', 'dist'],
|
||||
coverage: {
|
||||
provider: 'v8',
|
||||
reporter: ['text', 'json', 'html'],
|
||||
exclude: ['**/*.test.tsx', '**/*.spec.tsx', 'node_modules/'],
|
||||
},
|
||||
},
|
||||
});
|
||||
export {default} from '../../tsconfigs/vitest.base.mts';
|
||||
Reference in new issue
Block a user