Skip to content

A fully open source & end-to-end encrypted note taking alternative to Evernote.

web: use utils from @notesnook/common

Abdullah Atta9e2f54fd0baf
diff --git a/apps/web/src/common/db.ts b/apps/web/src/common/db.ts
index 327d76dad..00b21a003 100644
--- a/apps/web/src/common/db.ts
+++ b/apps/web/src/common/db.ts
@@ -35,10 +35,8 @@ async function initializeDatabase(persistence: DatabasePersistence) {
database.setup(
new NNStorage("Notesnook", persistence),
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
- // @ts-ignore
EventSource,
- null,
+ FS,
new Compressor()
);
diff --git a/apps/web/src/common/dialog-controller.tsx b/apps/web/src/common/dialog-controller.tsx
index e17702b5b..735c8149f 100644
--- a/apps/web/src/common/dialog-controller.tsx
+++ b/apps/web/src/common/dialog-controller.tsx
@@ -38,7 +38,7 @@ import { AuthenticatorType } from "../components/dialogs/mfa/types";
import { Suspense } from "react";
import { Reminder } from "@notesnook/core/collections/reminders";
import { ConfirmDialogProps } from "../components/dialogs/confirm";
-import { getFormattedDate } from "../utils/time";
+import { getFormattedDate } from "@notesnook/common";
import { downloadUpdate, installUpdate } from "../utils/updater";
type DialogTypes = typeof Dialogs;
diff --git a/apps/web/src/common/export.ts b/apps/web/src/common/export.ts
index 4ca6f0650..a23da7996 100644
--- a/apps/web/src/common/export.ts
+++ b/apps/web/src/common/export.ts
@@ -22,7 +22,7 @@ import { TaskManager } from "./task-manager";
import { zip } from "../utils/zip";
import { saveAs } from "file-saver";
import { showToast } from "../utils/toast";
-import { sanitizeFilename } from "../utils/filename";
+import { sanitizeFilename } from "@notesnook/common";
export async function exportToPDF(
title: string,
diff --git a/apps/web/src/common/index.js b/apps/web/src/common/index.js
index 3072a06d3..924bdda66 100644
--- a/apps/web/src/common/index.js
+++ b/apps/web/src/common/index.js
@@ -26,7 +26,7 @@ import {
import Config from "../utils/config";
import { hashNavigate, getCurrentHash } from "../navigation";
import { db } from "./db";
-import { sanitizeFilename } from "../utils/filename";
+import { sanitizeFilename } from "@notesnook/common";
import { isDesktop, isTesting } from "../utils/platform";
import { store as userstore } from "../stores/user-store";
import FileSaver from "file-saver";
@@ -37,7 +37,7 @@ import { logger } from "../utils/logger";
import { PATHS } from "@notesnook/desktop";
import { TaskManager } from "./task-manager";
import { EVENTS } from "@notesnook/core/common";
-import { getFormattedDate } from "../utils/time";
+import { getFormattedDate } from "@notesnook/common";
import { desktop } from "./desktop-bridge";
export const CREATE_BUTTON_MAP = {
@@ -172,10 +172,6 @@ export async function restoreBackupFile(backup) {
}
}
-export function getTotalNotes(notebook) {
- return db.notebooks.notebook(notebook)?.totalNotes;
-}
-
export async function verifyAccount() {
if (!(await db.user.getUser())) return true;
return showPasswordDialog("verify_account", ({ password }) => {
diff --git a/apps/web/src/common/multi-select.ts b/apps/web/src/common/multi-select.ts
index 3139b4b9a..348bbcfd3 100644
--- a/apps/web/src/common/multi-select.ts
+++ b/apps/web/src/common/multi-select.ts
@@ -26,7 +26,7 @@ import { db } from "./db";
import { showToast } from "../utils/toast";
import Vault from "./vault";
import { TaskManager } from "./task-manager";
-import { pluralize } from "../utils/string";
+import { pluralize } from "@notesnook/common";
type Item = {
id: string;
@@ -57,16 +57,13 @@ async function moveNotesToTrash(notes: Item[], confirm = true) {
id: "deleteNotes",
action: async (report) => {
report({
- text: `Deleting ${pluralize(items.length, "note", "notes")}...`
+ text: `Deleting ${pluralize(items.length, "note")}...`
});
await noteStore.delete(...items);
}
});
- showToast(
- "success",
- `${pluralize(items.length, "note", "notes")} moved to trash`
- );
+ showToast("success", `${pluralize(items.length, "note")} moved to trash`);
}
async function moveNotebooksToTrash(notebooks: Item[]) {
@@ -81,11 +78,7 @@ async function moveNotebooksToTrash(notebooks: Item[]) {
id: "deleteNotebooks",
action: async (report) => {
report({
- text: `Deleting ${pluralize(
- notebooks.length,
- "notebook",
- "notebooks"
- )}...`
+ text: `Deleting ${pluralize(notebooks.length, "notebook")}...`
});
await notebookStore.delete(...notebooks.map((i) => i.id));
}
@@ -93,7 +86,7 @@ async function moveNotebooksToTrash(notebooks: Item[]) {
showToast(
"success",
- `${pluralize(notebooks.length, "notebook", "notebooks")} moved to trash`
+ `${pluralize(notebooks.length, "notebook")} moved to trash`
);
}
@@ -103,7 +96,7 @@ async function deleteTopics(notebookId: string, topics: Item[]) {
id: "deleteTopics",
action: async (report) => {
report({
- text: `Deleting ${pluralize(topics.length, "topic", "topics")}...`
+ text: `Deleting ${pluralize(topics.length, "topic")}...`
});
await db.notebooks
?.notebook(notebookId)
@@ -112,10 +105,7 @@ async function deleteTopics(notebookId: string, topics: Item[]) {
noteStore.refresh();
}
});
- showToast(
- "success",
- `${pluralize(topics.length, "topic", "topics")} deleted`
- );
+ showToast("success", `${pluralize(topics.length, "topic")} deleted`);
}
async function deleteAttachments(attachments: Item[]) {
@@ -133,11 +123,7 @@ async function deleteAttachments(attachments: Item[]) {
for (let i = 0; i < attachments.length; ++i) {
const attachment = attachments[i];
report({
- text: `Deleting ${pluralize(
- attachments.length,
- "attachment",
- "attachments"
- )}...`,
+ text: `Deleting ${pluralize(attachments.length, "attachment")}...`,
current: i,
total: attachments.length
});
@@ -147,7 +133,7 @@ async function deleteAttachments(attachments: Item[]) {
});
showToast(
"success",
- `${pluralize(attachments.length, "attachment", "attachments")} deleted`
+ `${pluralize(attachments.length, "attachment")} deleted`
);
}
@@ -162,20 +148,13 @@ async function moveRemindersToTrash(reminders: Item[]) {
id: "deleteReminders",
action: async (report) => {
report({
- text: `Deleting ${pluralize(
- reminders.length,
- "reminder",
- "reminders"
- )}...`
+ text: `Deleting ${pluralize(reminders.length, "reminder")}...`
});
await reminderStore.delete(...reminders.map((i) => i.id));
}
});
- showToast(
- "success",
- `${pluralize(reminders.length, "reminder", "reminders")} deleted.`
- );
+ showToast("success", `${pluralize(reminders.length, "reminder")} deleted.`);
}
export const Multiselect = {
diff --git a/apps/web/src/common/task-manager.ts b/apps/web/src/common/task-manager.ts
index 80b10f9ef..2c5aca4d0 100644
--- a/apps/web/src/common/task-manager.ts
+++ b/apps/web/src/common/task-manager.ts
@@ -55,7 +55,7 @@ type TaskProgress = {
type ProgressReportCallback = (progress: TaskProgress) => void;
export class TaskManager {
- static async startTask<T>(task: TaskDefinition<T>): Promise<T | Error> {
+ static async startTask<T>(task: TaskDefinition<T>): Promise<T> {
switch (task.type) {
case "status": {
const statusTask = task;
diff --git a/apps/web/src/components/attachment/index.tsx b/apps/web/src/components/attachment/index.tsx
index f4deab84c..723da0c84 100644
--- a/apps/web/src/components/attachment/index.tsx
+++ b/apps/web/src/components/attachment/index.tsx
@@ -18,7 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import { Box, Checkbox, Flex, Label, Text } from "@theme-ui/components";
-import { formatBytes } from "../../utils/filename";
+import { formatBytes } from "@notesnook/common";
import {
AttachmentError,
Checkmark,
@@ -57,7 +57,7 @@ import {
} from "@notesnook/core/utils/filename";
import { useEffect, useState } from "react";
import { AppEventManager, AppEvents } from "../../common/app-events";
-import { getFormattedDate } from "../../utils/time";
+import { getFormattedDate } from "@notesnook/common";
const FILE_ICONS: Record<string, Icon> = {
"image/": FileImage,
diff --git a/apps/web/src/components/auth-container/index.jsx b/apps/web/src/components/auth-container/index.jsx
index b84c4ccf9..f1c23608a 100644
--- a/apps/web/src/components/auth-container/index.jsx
+++ b/apps/web/src/components/auth-container/index.jsx
@@ -23,7 +23,7 @@ import ThemeProvider from "../theme-provider";
import Logo from "../../assets/logo.svg";
import LogoDark from "../../assets/logo-dark.svg";
import { useStore as useThemeStore } from "../../stores/theme-store";
-import { getRandom } from "../../utils/random";
+import { getRandom } from "@notesnook/common";
import Grberk from "../../assets/testimonials/grberk.jpeg";
import Holenstein from "../../assets/testimonials/holenstein.jpg";
import Jason from "../../assets/testimonials/jason.jpg";
diff --git a/apps/web/src/components/dialogs/attachments-dialog.tsx b/apps/web/src/components/dialogs/attachments-dialog.tsx
index 34b9f7899..1b00d82aa 100644
--- a/apps/web/src/components/dialogs/attachments-dialog.tsx
+++ b/apps/web/src/components/dialogs/attachments-dialog.tsx
@@ -30,7 +30,7 @@ import {
} from "@theme-ui/components";
import { getTotalSize } from "../../common/attachments";
import { useStore, store } from "../../stores/attachment-store";
-import { formatBytes } from "../../utils/filename";
+import { formatBytes } from "@notesnook/common";
import Dialog from "./dialog";
import { TableVirtuoso } from "react-virtuoso";
import {
@@ -49,7 +49,7 @@ import {
Uploading
} from "../icons";
import NavigationItem from "../navigation-menu/navigation-item";
-import { pluralize } from "../../utils/string";
+import { pluralize } from "@notesnook/common";
import { db } from "../../common/db";
import { Perform } from "../../common/dialog-controller";
import { Multiselect } from "../../common/multi-select";
@@ -426,9 +426,7 @@ const Sidebar = memo(
<Flex sx={{ flexDirection: "column" }}>
<Flex sx={{ pl: 2, m: 2, mt: 1, justifyContent: "space-between" }}>
<Flex sx={{ flexDirection: "column" }}>
- <Text variant="body">
- {pluralize(counts.all, "file", "files")}
- </Text>
+ <Text variant="body">{pluralize(counts.all, "file")}</Text>
<Text variant="subBody">{formatBytes(totalSize)}</Text>
</Flex>
<Button
diff --git a/apps/web/src/components/dialogs/move-note-dialog.tsx b/apps/web/src/components/dialogs/move-note-dialog.tsx
index 7f1b086f8..e3b32b76c 100644
--- a/apps/web/src/components/dialogs/move-note-dialog.tsx
+++ b/apps/web/src/components/dialogs/move-note-dialog.tsx
@@ -26,7 +26,7 @@ import { useStore, store } from "../../stores/notebook-store";
import { store as notestore } from "../../stores/note-store";
import { Perform } from "../../common/dialog-controller";
import { showToast } from "../../utils/toast";
-import { pluralize } from "../../utils/string";
+import { pluralize } from "@notesnook/common";
import { isMac } from "../../utils/platform";
import { create } from "zustand";
import { FilteredList } from "../filtered-list";
@@ -160,7 +160,7 @@ function MoveDialog({ onClose, noteIds }: MoveDialogProps) {
if (stringified) {
showToast(
"success",
- `${pluralize(noteIds.length, "note", "notes")} ${stringified}`
+ `${pluralize(noteIds.length, "note")} ${stringified}`
);
}
@@ -290,7 +290,7 @@ function NotebookItem(props: {
{notebook.title}
<Text variant="subBody" sx={{ fontWeight: "body" }}>
{" "}
- ({pluralize(notebook.topics.length, "topic", "topics")})
+ ({pluralize(notebook.topics.length, "topic")})
</Text>
</Text>
</Flex>
diff --git a/apps/web/src/components/dialogs/settings/components/billing-history.tsx b/apps/web/src/components/dialogs/settings/components/billing-history.tsx
index c3445f19b..96dc7c0f7 100644
--- a/apps/web/src/components/dialogs/settings/components/billing-history.tsx
+++ b/apps/web/src/components/dialogs/settings/components/billing-history.tsx
@@ -20,7 +20,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
import { useEffect, useState } from "react";
import { Loading } from "../../../icons";
import { Box, Flex, Link, Text } from "@theme-ui/components";
-import { getFormattedDate } from "../../../../utils/time";
+import { getFormattedDate } from "@notesnook/common";
import { db } from "../../../../common/db";
type Transaction = {
diff --git a/apps/web/src/components/dialogs/settings/components/importer.tsx b/apps/web/src/components/dialogs/settings/components/importer.tsx
index 389b9275d..4c7a2fd88 100644
--- a/apps/web/src/components/dialogs/settings/components/importer.tsx
+++ b/apps/web/src/components/dialogs/settings/components/importer.tsx
@@ -21,7 +21,7 @@ import { useStore as useAppStore } from "../../../../stores/app-store";
import { useCallback, useRef, useState } from "react";
import { useDropzone } from "react-dropzone";
import { Button, Flex, Input, Link, Text } from "@theme-ui/components";
-import { pluralize } from "../../../../utils/string";
+import { pluralize } from "@notesnook/common";
import { db } from "../../../../common/db";
import { importFiles } from "../../../../utils/importer";
import { CheckCircleOutline } from "../../../icons";
@@ -109,11 +109,7 @@ export function Importer() {
<Flex sx={{ flexDirection: "column" }}>
<Text variant="title">
{files.length
- ? `${pluralize(
- files.length,
- "file",
- "files"
- )} ready for import`
+ ? `${pluralize(files.length, "file")} ready for import`
: "Select files to import"}
</Text>
<Text variant={"body"} sx={{ color: "fontTertiary" }}>
diff --git a/apps/web/src/components/dialogs/settings/components/user-profile.tsx b/apps/web/src/components/dialogs/settings/components/user-profile.tsx
index 5c3ded230..a3d590a1f 100644
--- a/apps/web/src/components/dialogs/settings/components/user-profile.tsx
+++ b/apps/web/src/components/dialogs/settings/components/user-profile.tsx
@@ -21,7 +21,7 @@ import { Flex, Text } from "@theme-ui/components";
import { User } from "../../../icons";
import { useStore as useUserStore } from "../../../../stores/user-store";
import ObjectID from "@notesnook/core/utils/object-id";
-import { getFormattedDate } from "../../../../utils/time";
+import { getFormattedDate } from "@notesnook/common";
import { SUBSCRIPTION_STATUS } from "../../../../common/constants";
import dayjs from "dayjs";
import { useMemo } from "react";
diff --git a/apps/web/src/components/dialogs/settings/index.tsx b/apps/web/src/components/dialogs/settings/index.tsx
index 40beec60d..053e006f0 100644
--- a/apps/web/src/components/dialogs/settings/index.tsx
+++ b/apps/web/src/components/dialogs/settings/index.tsx
@@ -63,7 +63,7 @@ import {
SupportSettings
} from "./other-settings";
import { AppearanceSettings } from "./appearance-settings";
-import { debounce } from "../../../utils/debounce";
+import { debounce } from "@notesnook/common";
import { SubscriptionSettings } from "./subscription-settings";
type SettingsDialogProps = { onClose: Perform };
diff --git a/apps/web/src/components/diff-viewer/content-toggle.jsx b/apps/web/src/components/diff-viewer/content-toggle.jsx
index b75f6df92..10ec07b39 100644
--- a/apps/web/src/components/diff-viewer/content-toggle.jsx
+++ b/apps/web/src/components/diff-viewer/content-toggle.jsx
@@ -18,7 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import { Flex, Button } from "@theme-ui/components";
-import { getFormattedDate } from "../../utils/time";
+import { getFormattedDate } from "@notesnook/common";
function ContentToggle(props) {
const {
diff --git a/apps/web/src/components/editor/footer.tsx b/apps/web/src/components/editor/footer.tsx
index 5fbcc9ff5..88df0ed5a 100644
--- a/apps/web/src/components/editor/footer.tsx
+++ b/apps/web/src/components/editor/footer.tsx
@@ -22,7 +22,7 @@ import { useMemo } from "react";
import { useStore } from "../../stores/editor-store";
import { Loading, Saved, NotSaved } from "../icons";
import { useNoteStatistics } from "./context";
-import { getFormattedDate } from "../../utils/time";
+import { getFormattedDate } from "@notesnook/common";
const SAVE_STATE_ICON_MAP = {
"-1": NotSaved,
diff --git a/apps/web/src/components/editor/index.tsx b/apps/web/src/components/editor/index.tsx
index 3a51f51d7..5c83233c4 100644
--- a/apps/web/src/components/editor/index.tsx
+++ b/apps/web/src/components/editor/index.tsx
@@ -55,7 +55,7 @@ import ThemeProviderWrapper from "../theme-provider";
import { Allotment } from "allotment";
// import { PdfPreview } from "";
import { showToast } from "../../utils/toast";
-import { getFormattedDate } from "../../utils/time";
+import { getFormattedDate } from "@notesnook/common";
const PDFPreview = React.lazy(() => import("../pdf-preview"));
diff --git a/apps/web/src/components/editor/tiptap.tsx b/apps/web/src/components/editor/tiptap.tsx
index d91592dc5..90adcf245 100644
--- a/apps/web/src/components/editor/tiptap.tsx
+++ b/apps/web/src/components/editor/tiptap.tsx
@@ -55,7 +55,7 @@ import { getCurrentPreset } from "../../common/toolbar-config";
import { useIsUserPremium } from "../../hooks/use-is-user-premium";
import { showBuyDialog } from "../../common/dialog-controller";
import { useStore as useSettingsStore } from "../../stores/setting-store";
-import { debounce, debounceWithId } from "../../utils/debounce";
+import { debounce, debounceWithId } from "@notesnook/common";
import { store as editorstore } from "../../stores/editor-store";
type OnChangeHandler = (
diff --git a/apps/web/src/components/editor/title-box.tsx b/apps/web/src/components/editor/title-box.tsx
index fa49dbd7d..fa3f31bad 100644
--- a/apps/web/src/components/editor/title-box.tsx
+++ b/apps/web/src/components/editor/title-box.tsx
@@ -20,7 +20,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
import React, { useCallback, useEffect, useMemo, useRef } from "react";
import { Input } from "@theme-ui/components";
import { useStore, store } from "../../stores/editor-store";
-import { debounceWithId } from "../../utils/debounce";
+import { debounceWithId } from "@notesnook/common";
import useMobile from "../../hooks/use-mobile";
import useTablet from "../../hooks/use-tablet";
import { useEditorConfig } from "./context";
diff --git a/apps/web/src/components/icons/resolver.tsx b/apps/web/src/components/icons/resolver.tsx
index 0ab1b7d51..70c700162 100644
--- a/apps/web/src/components/icons/resolver.tsx
+++ b/apps/web/src/components/icons/resolver.tsx
@@ -17,7 +17,7 @@ You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-import { toTitleCase, toCamelCase, KebabCase } from "../../utils/string";
+import { toTitleCase, toCamelCase, KebabCase } from "@notesnook/common";
import * as Icons from "./index";
export type IconAlias = KebabCase<keyof typeof Icons>;
diff --git a/apps/web/src/components/list-container/list-profiles.tsx b/apps/web/src/components/list-container/list-profiles.tsx
index 27563a17c..ec56375e3 100644
--- a/apps/web/src/components/list-container/list-profiles.tsx
+++ b/apps/web/src/components/list-container/list-profiles.tsx
@@ -24,7 +24,7 @@ import Tag from "../tag";
import Topic from "../topic";
import TrashItem from "../trash-item";
import { db } from "../../common/db";
-import { getTotalNotes } from "../../common";
+import { getTotalNotes } from "@notesnook/common";
import Reminder from "../reminder";
import type { Reminder as ReminderType } from "@notesnook/core/collections/reminders";
import { useMemo } from "react";
diff --git a/apps/web/src/components/loaders/list-loader.tsx b/apps/web/src/components/loaders/list-loader.tsx
index eb3fcf32f..dce53d871 100644
--- a/apps/web/src/components/loaders/list-loader.tsx
+++ b/apps/web/src/components/loaders/list-loader.tsx
@@ -21,7 +21,7 @@ import { memo } from "react";
import Skeleton from "react-loading-skeleton";
import { Box, Flex } from "@theme-ui/components";
import "react-loading-skeleton/dist/skeleton.css";
-import { getRandomArbitrary } from "../../utils/random";
+import { getRandomArbitrary } from "@notesnook/common";
const Lines = [1, 2].map(() => getRandomArbitrary(40, 90));
export const ListLoader = memo(function ListLoader() {
diff --git a/apps/web/src/components/notebook/index.jsx b/apps/web/src/components/notebook/index.jsx
index c32cce50e..15d6ab354 100644
--- a/apps/web/src/components/notebook/index.jsx
+++ b/apps/web/src/components/notebook/index.jsx
@@ -29,9 +29,9 @@ import { hashNavigate, navigate } from "../../navigation";
import IconTag from "../icon-tag";
import { showToast } from "../../utils/toast";
import { Multiselect } from "../../common/multi-select";
-import { pluralize } from "../../utils/string";
+import { pluralize } from "@notesnook/common";
import { confirm } from "../../common/dialog-controller";
-import { getFormattedDate } from "../../utils/time";
+import { getFormattedDate } from "@notesnook/common";
function Notebook(props) {
const { item, index, totalNotes, date, simplified } = props;
@@ -55,7 +55,7 @@ function Notebook(props) {
isCompact ? (
<>
<Text sx={{ fontSize: "subBody", color: "fontTertiary" }}>
- {pluralize(totalNotes, "note", "notes")}
+ {pluralize(totalNotes, "note")}
</Text>
</>
) : (
@@ -91,7 +91,7 @@ function Notebook(props) {
•
</Text>
<Text sx={{ color: "inherit" }}>
- {pluralize(totalNotes, "note", "notes")}
+ {pluralize(totalNotes, "note")}
</Text>
</Flex>
</>
@@ -175,7 +175,7 @@ const menuItems = [
icon: Icon.Trash,
onClick: async ({ items }) => {
const result = await confirm({
- title: `Delete ${pluralize(items.length, "notebook", "notebooks")}?`,
+ title: `Delete ${pluralize(items.length, "notebook")}?`,
positiveButtonText: `Yes`,
negativeButtonText: "No",
checks: {
diff --git a/apps/web/src/components/properties/index.jsx b/apps/web/src/components/properties/index.jsx
index 1509d6938..17cc5b766 100644
--- a/apps/web/src/components/properties/index.jsx
+++ b/apps/web/src/components/properties/index.jsx
@@ -32,12 +32,12 @@ import ScrollContainer from "../scroll-container";
import Vault from "../../common/vault";
import TimeAgo from "../time-ago";
import { Attachment } from "../attachment";
-import { formatBytes } from "../../utils/filename";
+import { formatBytes } from "@notesnook/common";
import { getTotalSize } from "../../common/attachments";
import Notebook from "../notebook";
-import { getTotalNotes } from "../../common";
+import { getTotalNotes } from "@notesnook/common";
import Reminder from "../reminder";
-import { getFormattedDate } from "../../utils/time";
+import { getFormattedDate } from "@notesnook/common";
const tools = [
{ key: "pin", property: "pinned", icon: Icon.Pin, label: "Pin" },
diff --git a/apps/web/src/components/reminder/index.tsx b/apps/web/src/components/reminder/index.tsx
index f44a2b9aa..5abc23c6a 100644
--- a/apps/web/src/components/reminder/index.tsx
+++ b/apps/web/src/components/reminder/index.tsx
@@ -24,7 +24,6 @@ import * as Icon from "../icons";
import IconTag from "../icon-tag";
import {
Reminder as ReminderType,
- formatReminderTime,
isReminderToday
} from "@notesnook/core/collections/reminders";
import { hashNavigate } from "../../navigation";
@@ -35,7 +34,8 @@ import {
confirm,
showEditReminderDialog
} from "../../common/dialog-controller";
-import { pluralize } from "../../utils/string";
+import { pluralize } from "@notesnook/common";
+import { getFormattedReminderTime } from "@notesnook/common";
const RECURRING_MODE_MAP = {
week: "Weekly",
@@ -86,7 +86,7 @@ function Reminder({
) : (
<IconTag
icon={Icon.Clock}
- text={formatReminderTime(reminder)}
+ text={getFormattedReminderTime(reminder)}
highlight={isReminderToday(reminder)}
testId={"reminder-time"}
/>
@@ -163,7 +163,7 @@ const menuItems: MenuItem[] = [
icon: Icon.Trash,
onClick: async ({ items }) => {
confirm({
- title: `Delete ${pluralize(items.length, "reminder", "reminders")}`,
+ title: `Delete ${pluralize(items.length, "reminder")}`,
message: `Are you sure you want to proceed? **This action is IRREVERSIBLE**.`,
positiveButtonText: "Yes",
negativeButtonText: "No"
diff --git a/apps/web/src/components/search/index.jsx b/apps/web/src/components/search/index.jsx
index 3a7646e3c..0d39ba56a 100644
--- a/apps/web/src/components/search/index.jsx
+++ b/apps/web/src/components/search/index.jsx
@@ -20,7 +20,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
import * as Icon from "../icons";
import "./search.css";
import Field from "../field";
-import { debounce } from "../../utils/debounce";
+import { debounce } from "@notesnook/common";
function SearchBox({ onSearch }) {
return (
<Field
diff --git a/apps/web/src/components/tag/index.jsx b/apps/web/src/components/tag/index.jsx
index dba5480d8..43ceefca5 100644
--- a/apps/web/src/components/tag/index.jsx
+++ b/apps/web/src/components/tag/index.jsx
@@ -27,7 +27,7 @@ import { store as editorStore } from "../../stores/editor-store";
import { db } from "../../common/db";
import * as Icon from "../icons";
import { showToast } from "../../utils/toast";
-import { pluralize } from "../../utils/string";
+import { pluralize } from "@notesnook/common";
const menuItems = [
{
@@ -58,7 +58,7 @@ const menuItems = [
await editorStore.clearSession();
await db.tags.remove(tag.id);
}
- showToast("success", `${pluralize(items.length, "tag", "tags")} deleted`);
+ showToast("success", `${pluralize(items.length, "tag")} deleted`);
tagStore.refresh();
noteStore.refresh();
},
diff --git a/apps/web/src/components/time-ago/index.jsx b/apps/web/src/components/time-ago/index.jsx
deleted file mode 100644
index 0e17eb964..000000000
--- a/apps/web/src/components/time-ago/index.jsx
+++ /dev/null
@@ -1,115 +0,0 @@
-/*
-This file is part of the Notesnook project (https://notesnook.com/)
-
-Copyright (C) 2023 Streetwriters (Private) Limited
-
-This program is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with this program. If not, see <http://www.gnu.org/licenses/>.
-*/
-
-import React, { useEffect, useRef } from "react";
-import { Text } from "@theme-ui/components";
-import { register, format, cancel, render } from "timeago.js";
-import { getFormattedDate } from "../../utils/time";
-
-const shortLocale = [
- ["now", "now"],
- ["%ss", "in %ss"],
- ["1m", "in 1m"],
- ["%sm", "in %sm"],
- ["1h", "in 1h"],
- ["%sh", "in %sh"],
- ["1d", "in 1d"],
- ["%sd", "in %sd"],
- ["1w", "in 1w"],
- ["%sw", "in %sw"],
- ["1mo", "in 1mo"],
- ["%smo", "in %smo"],
- ["1yr", "in 1yr"],
- ["%syr", "in %syr"]
-];
-
-const enShortLocale = [
- ["now", "now"],
- ["%ss ago", "in %ss"],
- ["1m ago", "in 1m"],
- ["%sm ago", "in %sm"],
- ["1h ago", "in 1h"],
- ["%sh ago", "in %sh"],
- ["1d ago", "in 1d"],
- ["%sd ago", "in %sd"],
- ["1w ago", "in 1w"],
- ["%sw ago", "in %sw"],
- ["1mo ago", "in 1mo"],
- ["%smo ago", "in %smo"],
- ["1yr ago", "in 1yr"],
- ["%syr ago", "in %syr"]
-];
-register("short", (_n, index) => shortLocale[index]);
-register("en_short", (_n, index) => enShortLocale[index]);
-
-function TimeAgo({ datetime, live, locale, opts, sx, ...restProps }) {
- const timeRef = useRef();
- useEffect(() => {
- const element = timeRef.current;
- if (!element) return;
-
- // cancel all the interval
- cancel(element);
- // if is live
- if (live !== false) {
- // live render
- element.setAttribute("datetime", toDate(datetime).toISOString());
- render(element, locale, opts);
- }
-
- return () => {
- cancel(element);
- };
- }, [datetime, live, locale, opts]);
-
- return (
- <Text
- ref={timeRef}
- {...restProps}
- sx={{
- fontFamily: "body",
- ...sx,
- color: sx?.color || "inherit"
- }}
- title={getFormattedDate(datetime)}
- as="time"
- data-test-id="time"
- dateTime={toDate(datetime).toISOString()}
- >
- {format(datetime, locale, opts)}
- </Text>
- );
-}
-
-export default React.memo(TimeAgo);
-
-/**
- * Convert input to a valid datetime string of <time> tag
- * https://developer.mozilla.org/en-US/docs/Web/HTML/Element/time
- * @param input
- * @returns datetime string
- */
-const toDate = (input) => {
- let date = null; // new Date();
- if (input instanceof Date) {
- date = input;
- } else date = new Date(input);
-
- return date;
-};
diff --git a/apps/web/src/components/time-ago/index.tsx b/apps/web/src/components/time-ago/index.tsx
new file mode 100644
index 000000000..0fef52f39
--- /dev/null
+++ b/apps/web/src/components/time-ago/index.tsx
@@ -0,0 +1,60 @@
+/*
+This file is part of the Notesnook project (https://notesnook.com/)
+
+Copyright (C) 2023 Streetwriters (Private) Limited
+
+This program is free software: you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation, either version 3 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+import React, { useRef } from "react";
+import { Text, TextProps } from "@theme-ui/components";
+import { type TDate } from "timeago.js";
+import { useTimeAgo } from "@notesnook/common";
+
+type TimeAgoProps = {
+ datetime: TDate;
+ locale?: "short" | "en_short";
+ live?: boolean;
+ interval?: number;
+};
+function TimeAgo({
+ datetime,
+ live,
+ locale,
+ interval,
+ sx,
+ ...restProps
+}: TimeAgoProps & TextProps) {
+ const timeRef = useRef<HTMLDivElement>(null);
+
+ const time = useTimeAgo(datetime, { live, locale, interval });
+
+ return (
+ <Text
+ {...restProps}
+ ref={timeRef}
+ sx={{
+ fontFamily: "body",
+ ...sx,
+ color: (sx && (sx as any)["color"]) || "inherit"
+ }}
+ as="time"
+ data-test-id="time"
+ >
+ {time}
+ </Text>
+ );
+}
+
+export default React.memo(TimeAgo);
diff --git a/apps/web/src/components/topic/index.jsx b/apps/web/src/components/topic/index.jsx
index c43f89030..b4449c92a 100644
--- a/apps/web/src/components/topic/index.jsx
+++ b/apps/web/src/components/topic/index.jsx
@@ -17,7 +17,7 @@ You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-import React, { useMemo } from "react";
+import React from "react";
import ListItem from "../list-item";
import { db } from "../../common/db";
import { store as appStore } from "../../stores/app-store";
@@ -27,19 +27,15 @@ import * as Icon from "../icons";
import { Multiselect } from "../../common/multi-select";
import { confirm } from "../../common/dialog-controller";
import { useStore as useNotesStore } from "../../stores/note-store";
-import { pluralize } from "../../utils/string";
+import { pluralize } from "@notesnook/common";
+import { getTotalNotes } from "@notesnook/common";
function Topic({ item, index, onClick }) {
- const { id, notebookId } = item;
const topic = item;
const isOpened = useNotesStore(
(store) => store.context?.value?.topic === item.id
);
- const totalNotes = useMemo(() => {
- return db.notebooks.notebook(notebookId)?.topics.topic(id)?.totalNotes || 0;
- }, [id, notebookId]);
-
return (
<ListItem
selectable
@@ -56,7 +52,7 @@ function Topic({ item, index, onClick }) {
alignItems: "center"
}}
>
- <Text variant="subBody">{totalNotes}</Text>
+ <Text variant="subBody">{getTotalNotes(topic)}</Text>
</Flex>
}
index={index}
@@ -118,7 +114,7 @@ const menuItems = [
iconColor: "error",
onClick: async ({ items, notebookId }) => {
const result = await confirm({
- title: `Delete ${pluralize(items.length, "topic", "topics")}?`,
+ title: `Delete ${pluralize(items.length, "topic")}?`,
positiveButtonText: `Yes`,
negativeButtonText: "No",
checks: {
diff --git a/apps/web/src/components/trash-item/index.jsx b/apps/web/src/components/trash-item/index.jsx
index 36030b020..d37bdb9b3 100644
--- a/apps/web/src/components/trash-item/index.jsx
+++ b/apps/web/src/components/trash-item/index.jsx
@@ -23,7 +23,7 @@ import * as Icon from "../icons";
import { store } from "../../stores/trash-store";
import { Flex, Text } from "@theme-ui/components";
import TimeAgo from "../time-ago";
-import { pluralize, toTitleCase } from "../../utils/string";
+import { pluralize, toTitleCase } from "@notesnook/common";
import { showUndoableToast } from "../../common/toasts";
import { showToast } from "../../utils/toast";
import { hashNavigate } from "../../navigation";
@@ -66,10 +66,7 @@ const menuItems = [
icon: Icon.Restore,
onClick: ({ items }) => {
store.restore(items.map((i) => i.id));
- showToast(
- "success",
- `${pluralize(items.length, "item", "items")} restored`
- );
+ showToast("success", `${pluralize(items.length, "item")} restored`);
},
multiSelect: true
},
@@ -83,7 +80,7 @@ const menuItems = [
if (!(await showMultiPermanentDeleteConfirmation(items.length))) return;
const ids = items.map((i) => i.id);
showUndoableToast(
- `${pluralize(items.length, "item", "items")} permanently deleted`,
+ `${pluralize(items.length, "item")} permanently deleted`,
() => store.delete(ids),
() => store.delete(ids, true),
() => store.refresh()
diff --git a/apps/web/src/utils/color.ts b/apps/web/src/utils/color.ts
deleted file mode 100644
index a0c71466e..000000000
--- a/apps/web/src/utils/color.ts
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
-This file is part of the Notesnook project (https://notesnook.com/)
-
-Copyright (C) 2023 Streetwriters (Private) Limited
-
-This program is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with this program. If not, see <http://www.gnu.org/licenses/>.
-*/
-
-function hexToRGB(hex:string, alpha = 1) {
- let parseString = hex;
- if (hex.startsWith("#")) {
- parseString = hex.slice(1, 7);
- }
- if (parseString.length !== 6) {
- return null;
- }
- const r = parseInt(parseString.slice(0, 2), 16);
- const g = parseInt(parseString.slice(2, 4), 16);
- const b = parseInt(parseString.slice(4, 6), 16);
- if (isNaN(r) || isNaN(g) || isNaN(b)) {
- return null;
- }
- return `rgba(${r}, ${g}, ${b}, ${alpha})`;
- }
-
- export { hexToRGB };
-
\ No newline at end of file
diff --git a/apps/web/src/utils/css.ts b/apps/web/src/utils/css.ts
deleted file mode 100644
index 7e11fe7dc..000000000
--- a/apps/web/src/utils/css.ts
+++ /dev/null
@@ -1,65 +0,0 @@
-/*
-This file is part of the Notesnook project (https://notesnook.com/)
-
-Copyright (C) 2023 Streetwriters (Private) Limited
-
-This program is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with this program. If not, see <http://www.gnu.org/licenses/>.
-*/
-
-export function removeCss(id: string) {
- const link = document.getElementById(id);
- if(link){
- link.remove();
- }
-}
-
-export function injectCssSrc(id: string, src: string) {
- const head = document.head;
- const link = document.createElement("link");
-
- link.id = id;
- link.type = "text/css";
- link.rel = "stylesheet";
- link.href = src;
-
- head.appendChild(link);
-}
-
-export function injectCss(rule: string) {
- const variableCss = document.getElementById("variables");
- const head = document.getElementsByTagName("head")[0];
- if (variableCss) {
- head.removeChild(variableCss);
- }
- const css = document.createElement("style");
- css.type = "text/css";
- css.id = "variables";
- css.appendChild(document.createTextNode(rule));
- head.insertBefore(css, getRootStylesheet());
-}
-
-function getRootStylesheet() {
- for (const sty of document.getElementsByTagName("style")) {
- if (sty.innerHTML.includes("#root")) {
- return sty;
- }
- }
- return null;
-}
-
-export function changeSvgTheme(newAccent: string) {
- const nodes = document.querySelectorAll('*[fill="#0560ff"]');
- for (let n = 0; n < nodes.length; ++n)
- nodes[n].setAttribute("fill", newAccent);
-}
diff --git a/apps/web/src/utils/debounce.ts b/apps/web/src/utils/debounce.ts
deleted file mode 100644
index 6656a4e53..000000000
--- a/apps/web/src/utils/debounce.ts
+++ /dev/null
@@ -1,69 +0,0 @@
-/*
-This file is part of the Notesnook project (https://notesnook.com/)
-
-Copyright (C) 2023 Streetwriters (Private) Limited
-
-This program is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with this program. If not, see <http://www.gnu.org/licenses/>.
-*/
-interface DebouncedFunction<
- Args extends any[],
- F extends (...args: Args) => any
-> {
- (this: ThisParameterType<F>, ...args: Args & Parameters<F>): void;
-}
-
-interface DebouncedFunctionWithId<
- Args extends any[],
- F extends (...args: Args) => any
-> {
- (
- this: ThisParameterType<F>,
- id: string | number,
- ...args: Args & Parameters<F>
- ): void;
-}
-
-export function debounce<Args extends any[], F extends (...args: Args) => void>(
- func: F,
- waitFor: number
-): DebouncedFunction<Args, F> {
- let timeout: number | null;
-
- return (...args: Args) => {
- if (timeout) clearTimeout(timeout);
- timeout = setTimeout(() => func(...args), waitFor) as unknown as number;
- };
-}
-
-export function debounceWithId<
- Args extends any[],
- F extends (...args: Args) => void
->(func: F, waitFor: number): DebouncedFunctionWithId<Args, F> {
- let timeout: number | null;
- let debounceId: string | number | null = null;
-
- return (id: string | number, ...args: Parameters<F>) => {
- if (timeout && id === debounceId) clearTimeout(timeout);
- debounceId = id;
- timeout = setTimeout(() => {
- func(...args);
- }, waitFor) as unknown as number;
- };
-}
-
-const DEBOUNCE_TIMEOUTS: Record<string, NodeJS.Timeout> = {};
-export function inlineDebounce(id: string, func: () => void, waitFor: number) {
- clearTimeout(DEBOUNCE_TIMEOUTS[id]);
- DEBOUNCE_TIMEOUTS[id] = setTimeout(func, waitFor);
-}
diff --git a/apps/web/src/utils/filename.ts b/apps/web/src/utils/filename.ts
deleted file mode 100644
index 0c650c676..000000000
--- a/apps/web/src/utils/filename.ts
+++ /dev/null
@@ -1,96 +0,0 @@
-/*
-This file is part of the Notesnook project (https://notesnook.com/)
-
-Copyright (C) 2023 Streetwriters (Private) Limited
-
-This program is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with this program. If not, see <http://www.gnu.org/licenses/>.
-*/
-
-/*jshint node:true*/
-/**
- * Replaces characters in strings that are illegal/unsafe for filenames.
- * Unsafe characters are either removed or replaced by a substitute set
- * in the optional `options` object.
- *
- * Illegal Characters on Various Operating Systems
- * / ? < > \ : * | "
- * https://kb.acronis.com/content/39790
- *
- * Unicode Control codes
- * C0 0x00-0x1f & C1 (0x80-0x9f)
- * http://en.wikipedia.org/wiki/C0_and_C1_control_codes
- *
- * Reserved filenames on Unix-based systems (".", "..")
- * Reserved filenames in Windows ("CON", "PRN", "AUX", "NUL", "COM1",
- * "COM2", "COM3", "COM4", "COM5", "COM6", "COM7", "COM8", "COM9",
- * "LPT1", "LPT2", "LPT3", "LPT4", "LPT5", "LPT6", "LPT7", "LPT8", and
- * "LPT9") case-insesitively and with or without filename extensions.
- *
- * Capped at 255 characters in length.
- * http://unix.stackexchange.com/questions/32795/what-is-the-maximum-allowed-filename-and-folder-size-with-ecryptfs
- *
- * @param {String} input Original filename
- * @param {Object} options {replacement: String | Function }
- * @return {String} Sanitized filename
- */
-const illegalRe = /[/?<>\\:*|"]/g;
-// var controlRe = /[x00-x1f\x80-\x9f]/g;
-const reservedRe = /^\.+$/;
-const windowsReservedRe = /^(con|prn|aux|nul|com[0-9]|lpt[0-9])(\..*)?$/i;
-const windowsTrailingRe = /[. ]+$/;
-const whitespace = /\s+/g;
-
-function sanitize(input: string, replacement: string) {
- if (typeof input !== "string") {
- throw new Error("Input must be string");
- }
- const sanitized = input
- .replace(whitespace, replacement)
- //.replace(controlRe, replacement)
- .replace(illegalRe, replacement)
- .replace(reservedRe, replacement)
- .replace(windowsReservedRe, replacement)
- .replace(windowsTrailingRe, replacement);
-
- return sanitized.slice(0, 254).toLowerCase();
-}
-
-export function sanitizeFilename(input: string) {
- const replacement = "-";
- return sanitize(input, replacement);
-}
-
-export function formatBytes(bytes: number, decimals = 2) {
- if (bytes === 0) return "0 B";
-
- const k = 1024;
- const dm = decimals < 0 ? 0 : decimals;
- const sizes = ["B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"];
-
- const i = Math.floor(Math.log(bytes) / Math.log(k));
-
- return parseFloat((bytes / Math.pow(k, i)).toFixed(dm)) + " " + sizes[i];
-}
-
-export function truncateFilename(filename: string) {
- const MAX_LENGTH = 38;
- if (filename.length > MAX_LENGTH) {
- return (
- filename.substr(0, MAX_LENGTH / 2) +
- "..." +
- filename.substr(filename.lastIndexOf(".") - 4)
- );
- }
- return filename;
-}
diff --git a/apps/web/src/utils/object.ts b/apps/web/src/utils/object.ts
deleted file mode 100644
index 16164d3b2..000000000
--- a/apps/web/src/utils/object.ts
+++ /dev/null
@@ -1,25 +0,0 @@
-/*
-This file is part of the Notesnook project (https://notesnook.com/)
-
-Copyright (C) 2023 Streetwriters (Private) Limited
-
-This program is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with this program. If not, see <http://www.gnu.org/licenses/>.
-*/
-
-export function objectMap<T, U>(
- obj: Record<string, T>,
- fn: (k: string, v: T, i: number) => U
-) {
- return Object.entries(obj).map(([k, v], i) => fn(k, v, i));
-}
diff --git a/apps/web/src/utils/random.ts b/apps/web/src/utils/random.ts
deleted file mode 100644
index f7949e4f5..000000000
--- a/apps/web/src/utils/random.ts
+++ /dev/null
@@ -1,27 +0,0 @@
-/*
-This file is part of the Notesnook project (https://notesnook.com/)
-
-Copyright (C) 2023 Streetwriters (Private) Limited
-
-This program is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with this program. If not, see <http://www.gnu.org/licenses/>.
-*/
-
-function getRandom(min: number, max: number) {
- return Math.round(Math.random() * (max - min) + min);
-}
-
-function getRandomArbitrary(min: number, max: number) {
- return Math.random() * (max - min) + min;
-}
-export { getRandom, getRandomArbitrary };
diff --git a/apps/web/src/utils/string.ts b/apps/web/src/utils/string.ts
deleted file mode 100644
index a0cb5ab12..000000000
--- a/apps/web/src/utils/string.ts
+++ /dev/null
@@ -1,72 +0,0 @@
-/*
-This file is part of the Notesnook project (https://notesnook.com/)
-
-Copyright (C) 2023 Streetwriters (Private) Limited
-
-This program is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with this program. If not, see <http://www.gnu.org/licenses/>.
-*/
-
-type TitleCase<T extends string, D extends string = " "> = string extends T
- ? never
- : T extends `${infer F}${D}${infer R}`
- ? `${Capitalize<F>}${D}${TitleCase<R, D>}`
- : Capitalize<T>;
-
-type Separator = " " | "-" | "_";
-
-type CamelCase<T extends string> = T extends `${Separator}${infer Suffix}`
- ? CamelCase<Suffix>
- : T extends `${infer Prefix}${Separator}`
- ? CamelCase<Prefix>
- : T extends `${infer Prefix}${Separator}${infer Suffix}`
- ? CamelCase<`${Prefix}${Capitalize<Suffix>}`>
- : T;
-
-type KebabCaseHelper<
- S,
- Acc extends string = ""
-> = S extends `${infer C}${infer T}`
- ? KebabCaseHelper<
- T extends Uncapitalize<T> ? T : Uncapitalize<T>,
- `${Acc}${Lowercase<C>}${T extends Uncapitalize<T> ? "" : "-"}`
- >
- : Acc;
-export type KebabCase<S extends string> = KebabCaseHelper<S>;
-
-export function toTitleCase<T extends string>(str: T): TitleCase<T> | "" {
- if (!str || !str[0]) {
- return "";
- }
- return (str[0].toUpperCase() + str.substring(1)) as TitleCase<T>;
-}
-
-export function toCamelCase<T extends string>(str: T): CamelCase<T> {
- return str.replaceAll(/-(.{1})/gm, (_str, letter) => {
- return letter.toUpperCase();
- }) as CamelCase<T>;
-}
-
-export function countWords(str: string): number {
- str = str.trim();
- if (!str.length) return 0;
- return str.split(/\W+\S/).length;
-}
-
-export function pluralize(
- count: number,
- singular: string,
- plural: string
-): string {
- return !count || count > 1 ? `${count} ${plural}` : `${count} ${singular}`;
-}
diff --git a/apps/web/src/utils/time.ts b/apps/web/src/utils/time.ts
deleted file mode 100644
index d198e07d2..000000000
--- a/apps/web/src/utils/time.ts
+++ /dev/null
@@ -1,34 +0,0 @@
-/*
-This file is part of the Notesnook project (https://notesnook.com/)
-
-Copyright (C) 2023 Streetwriters (Private) Limited
-
-This program is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with this program. If not, see <http://www.gnu.org/licenses/>.
-*/
-
-import { formatDate } from "@notesnook/core/utils/date";
-import { db } from "../common/db";
-
-export function getFormattedDate(
- date: string | number | Date | null | undefined,
- type: "time" | "date-time" | "date" = "date-time"
-) {
- if (!db.settings) return "";
-
- return formatDate(date, {
- dateFormat: db.settings.getDateFormat(),
- timeFormat: db.settings.getTimeFormat(),
- type
- });
-}
diff --git a/apps/web/src/utils/web-extension-server.ts b/apps/web/src/utils/web-extension-server.ts
index 5e122619d..187c57904 100644
--- a/apps/web/src/utils/web-extension-server.ts
+++ b/apps/web/src/utils/web-extension-server.ts
@@ -28,9 +28,9 @@ import { isUserPremium } from "../hooks/use-is-user-premium";
import { store as themestore } from "../stores/theme-store";
import { store as appstore } from "../stores/app-store";
import { h } from "./html";
-import { sanitizeFilename } from "./filename";
+import { sanitizeFilename } from "@notesnook/common";
import { attachFile } from "../components/editor/picker";
-import { getFormattedDate } from "./time";
+import { getFormattedDate } from "@notesnook/common";
export class WebExtensionServer implements Server {
async login() {
diff --git a/apps/web/src/utils/zip.ts b/apps/web/src/utils/zip.ts
index 6ebcdd5a5..10331e209 100644
--- a/apps/web/src/utils/zip.ts
+++ b/apps/web/src/utils/zip.ts
@@ -18,7 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import { Unzipped } from "fflate";
-import { sanitizeFilename } from "./filename";
+import { sanitizeFilename } from "@notesnook/common";
const textEncoder = new TextEncoder();
type File = { filename: string; content: string };
diff --git a/apps/web/src/views/topics.jsx b/apps/web/src/views/topics.jsx
index 2fe9ae4d1..235d559aa 100644
--- a/apps/web/src/views/topics.jsx
+++ b/apps/web/src/views/topics.jsx
@@ -31,8 +31,8 @@ import {
ShortcutLink,
SortAsc
} from "../components/icons";
-import { getTotalNotes } from "../common";
-import { pluralize } from "../utils/string";
+import { getTotalNotes } from "@notesnook/common";
+import { pluralize } from "@notesnook/common";
import { Allotment } from "allotment";
import { Plus } from "../components/icons";
import { useStore as useNotesStore } from "../stores/note-store";
@@ -40,7 +40,7 @@ import Placeholder from "../components/placeholders";
import { showSortMenu } from "../components/group-header";
import { db } from "../common/db";
import { groupArray } from "@notesnook/core/utils/grouping";
-import { getFormattedDate } from "../utils/time";
+import { getFormattedDate } from "@notesnook/common";
function Notebook() {
const [isCollapsed, setIsCollapsed] = useState(false);
@@ -323,8 +323,7 @@ function NotebookHeader({ notebook }) {
</Text>
)}
<Text as="em" variant="subBody" mt={2}>
- {pluralize(topics.length, "topic", "topics")},{" "}
- {pluralize(totalNotes, "note", "notes")}
+ {pluralize(topics.length, "topic")}, {pluralize(totalNotes, "note")}
</Text>
</Flex>
);
diff --git a/apps/web/tsconfig.json b/apps/web/tsconfig.json
index fbec448cc..67547d720 100644
--- a/apps/web/tsconfig.json
+++ b/apps/web/tsconfig.json
@@ -7,5 +7,10 @@
"maxNodeModuleJsDepth": 5,
"noEmit": true
},
- "include": ["src", "global.d.ts", "__e2e__"]
+ "include": [
+ "src",
+ "global.d.ts",
+ "__e2e__",
+ "../../packages/common/src/utils/debounce.ts"
+ ]
}