Files
flagnote-web/src/libs/noteStorage.js
2022-11-22 14:58:24 +08:00

46 lines
1.0 KiB
JavaScript

import { wrap } from "@/libs/secret";
import storage from "@/libs/storage";
import escapeHtml from "escape-html";
export function setStoreText(noteForm, state, secret) {
let text = noteForm.text;
let storeText = "";
if (text) {
storeText = wrap(text, secret.secretKey);
}
storage.local.setText(
secret.storeKey,
state.lock +
"|" +
secret.cipher +
"|" +
state.commited +
"|" +
state.initTime +
"|" +
storeText
);
}
export function clearStoreText(key) {
if (!key) {
return;
}
storage.local.delete(key);
}
export function getEscapeText(text) {
let textEscape = escapeHtml(text);
textEscape = textEscape.replace(new RegExp(" ", "gm"), " ");
textEscape = textEscape.replace(new RegExp("\\r\\n", "gm"), "<br/>");
textEscape = textEscape.replace(new RegExp("\\r", "gm"), "<br/>");
textEscape = textEscape.replace(new RegExp("\\n", "gm"), "<br/>");
textEscape = textEscape.replace(
new RegExp("\\t", "gm"),
'<pre class="tab_pre">&#9;</pre>'
);
return textEscape;
}