test: common-utils

This commit is contained in:
DIYgod
2024-02-24 22:30:29 +08:00
parent a6888c4653
commit cb17e72f31
3 changed files with 5 additions and 4 deletions
+1 -1
View File
@@ -1,5 +1,5 @@
.DS_Store
.env
.env*
.eslintcache
.idea
.log
@@ -1,4 +1,5 @@
const utils = require('../../lib/utils/common-utils');
import { describe, expect, it } from '@jest/globals';
import utils from './common-utils';
describe('common-utils', () => {
it('toTitleCase', () => {
+2 -2
View File
@@ -8,14 +8,14 @@ const rWhiteSpace = /\s+/;
const rAllWhiteSpace = /\s+/g;
// collapse all whitespaces into a single space (like "white-space: normal;" would do), and trim
const collapseWhitespace = (str: string) => {
const collapseWhitespace = (str?: string | null) => {
if (str && rWhiteSpace.test(str)) {
return str.replaceAll(rAllWhiteSpace, ' ').trim();
}
return str;
};
const convertDateToISO8601 = (date: string | Date | number) => {
const convertDateToISO8601 = (date?: string | Date | number | null) => {
if (!date) {
return date;
}