Merge branch 'main' into static
This commit is contained in:
commit
655fb63e8c
3
.vscode/settings.json
vendored
3
.vscode/settings.json
vendored
@ -41,7 +41,8 @@
|
||||
"WRHGZC",
|
||||
"wxyz",
|
||||
"zadd",
|
||||
"zrange"
|
||||
"zrange",
|
||||
"datetime"
|
||||
],
|
||||
"files.associations": {
|
||||
"*.css": "tailwindcss"
|
||||
|
||||
@ -30,4 +30,18 @@ describe('Date utility', () => {
|
||||
.toBe('2023-12-02 16:38:36');
|
||||
});
|
||||
});
|
||||
it('Malformed date string', () => {
|
||||
const timestamp = '2024/01a/01 Z';
|
||||
expect(convertTimestampWithOffsetToPostgresString(timestamp))
|
||||
.toBe(convertTimestampWithOffsetToPostgresString(
|
||||
new Date().toISOString(),
|
||||
));
|
||||
});
|
||||
it('Empty string', () => {
|
||||
const timestamp = ' ';
|
||||
expect(convertTimestampWithOffsetToPostgresString(timestamp))
|
||||
.toBe(convertTimestampWithOffsetToPostgresString(
|
||||
new Date().toISOString(),
|
||||
));
|
||||
});
|
||||
});
|
||||
|
||||
@ -2,10 +2,12 @@ import { parameterize } from '@/utility/string';
|
||||
|
||||
describe('String', () => {
|
||||
it('parameterizes', () => {
|
||||
expect(parameterize('my-tag')).toBe('my-tag');
|
||||
expect(parameterize('my tag')).toBe('my-tag');
|
||||
expect(parameterize('My Tag')).toBe('my-tag');
|
||||
expect(parameterize('my_tag')).toBe('my-tag');
|
||||
expect(parameterize('person\'s tag')).toBe('persons-tag');
|
||||
expect(parameterize('"person\'s tag"')).toBe('persons-tag');
|
||||
expect(parameterize('宿宿宿宿')).toBe('宿宿宿宿');
|
||||
});
|
||||
});
|
||||
|
||||
@ -18,14 +18,16 @@ export const formatDateForPostgres = (date: Date) =>
|
||||
'$1-$2-$3 $4',
|
||||
);
|
||||
|
||||
const dateFromTimestamp = (timestamp?: AmbiguousTimestamp): Date =>
|
||||
typeof timestamp === 'number'
|
||||
const dateFromTimestamp = (timestamp?: AmbiguousTimestamp): Date => {
|
||||
const date = typeof timestamp === 'number'
|
||||
? new Date(timestamp * 1000)
|
||||
: typeof timestamp === 'string'
|
||||
? /.+Z/i.test(timestamp)
|
||||
? new Date(timestamp)
|
||||
: new Date(`${timestamp}Z`)
|
||||
: new Date();
|
||||
: undefined;
|
||||
return date && !isNaN(date.getTime()) ? date : new Date();
|
||||
};
|
||||
|
||||
const createNaiveDateWithOffset = (
|
||||
timestamp?: AmbiguousTimestamp,
|
||||
|
||||
@ -24,6 +24,8 @@ export const parameterize = (
|
||||
.trim()
|
||||
// Replaces spaces, underscores, and dashes with dashes
|
||||
.replaceAll(/[\s_–—]/gi, '-')
|
||||
// Removes punctuation
|
||||
.replaceAll(/['"!@#$%^&*()_+=[\]{};:/?,.<>\\|`~]/gi, '')
|
||||
// Removes all non-alphanumeric characters
|
||||
.replaceAll(
|
||||
shouldRemoveNonAlphanumeric
|
||||
|
||||
Loading…
Reference in New Issue
Block a user