mirror of
https://github.com/streetwriters/notesnook.git
synced 2025-12-22 22:49:45 +01:00
feat: move he to lean-he, remove transfun & jshashes
This commit is contained in:
@@ -1,9 +1,5 @@
|
|||||||
import fuzzysearch from "fuzzysearch";
|
import fuzzysearch from "fuzzysearch";
|
||||||
import { getContentFromData } from "../content-types";
|
import { getContentFromData } from "../content-types";
|
||||||
var tfun = require("transfun/transfun.js").tfun;
|
|
||||||
if (!tfun) {
|
|
||||||
tfun = global.tfun;
|
|
||||||
}
|
|
||||||
|
|
||||||
export default class Lookup {
|
export default class Lookup {
|
||||||
/**
|
/**
|
||||||
@@ -33,11 +29,11 @@ export default class Lookup {
|
|||||||
}
|
}
|
||||||
|
|
||||||
notebooks(array, query) {
|
notebooks(array, query) {
|
||||||
return tfun.filter(
|
return array.filter(
|
||||||
(nb) =>
|
(nb) =>
|
||||||
fzs(query, nb.title + " " + nb.description) ||
|
fzs(query, nb.title + " " + nb.description) ||
|
||||||
nb.topics.some((topic) => fuzzysearch(query, topic.title))
|
nb.topics.some((topic) => fuzzysearch(query, topic.title))
|
||||||
)(array);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
topics(array, query) {
|
topics(array, query) {
|
||||||
@@ -53,7 +49,7 @@ export default class Lookup {
|
|||||||
}
|
}
|
||||||
|
|
||||||
_byTitle(array, query) {
|
_byTitle(array, query) {
|
||||||
return tfun.filter((item) => fzs(query, item.title))(array);
|
return array.filter((item) => fzs(query, item.title));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +1,5 @@
|
|||||||
import { CURRENT_DATABASE_VERSION } from "../../common";
|
import { CURRENT_DATABASE_VERSION } from "../../common";
|
||||||
import Database from "../index";
|
import Database from "../index";
|
||||||
var tfun = require("transfun/transfun.js").tfun;
|
|
||||||
if (!tfun) {
|
|
||||||
tfun = global.tfun;
|
|
||||||
}
|
|
||||||
|
|
||||||
class Collector {
|
class Collector {
|
||||||
/**
|
/**
|
||||||
@@ -57,14 +53,14 @@ class Collector {
|
|||||||
|
|
||||||
_collect(array) {
|
_collect(array) {
|
||||||
if (this.force) {
|
if (this.force) {
|
||||||
return Promise.all(tfun.map(this._map)(array));
|
return Promise.all(array.map(this._map));
|
||||||
}
|
}
|
||||||
return Promise.all(
|
return Promise.all(
|
||||||
tfun
|
array.reduce((prev, item) => {
|
||||||
.filter(
|
if (item.dateEdited > this._lastSyncedTimestamp || item.migrated)
|
||||||
(item) => item.dateEdited > this._lastSyncedTimestamp || item.migrated
|
prev.push(this._map(item));
|
||||||
)
|
return prev;
|
||||||
.map(this._map)(array)
|
}, [])
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,11 +31,6 @@ import http from "../../utils/http";
|
|||||||
import TokenManager from "../token-manager";
|
import TokenManager from "../token-manager";
|
||||||
import Collector from "./collector";
|
import Collector from "./collector";
|
||||||
import Merger from "./merger";
|
import Merger from "./merger";
|
||||||
var tfun = require("transfun/transfun.js").tfun;
|
|
||||||
if (!tfun) {
|
|
||||||
tfun = global.tfun;
|
|
||||||
}
|
|
||||||
|
|
||||||
export default class Sync {
|
export default class Sync {
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -1,14 +1,9 @@
|
|||||||
import Collection from "./collection";
|
import Collection from "./collection";
|
||||||
import fuzzysearch from "fuzzysearch";
|
|
||||||
import Notebook from "../models/notebook";
|
import Notebook from "../models/notebook";
|
||||||
import sort from "fast-sort";
|
import sort from "fast-sort";
|
||||||
import getId from "../utils/id";
|
import getId from "../utils/id";
|
||||||
import { CHECK_IDS, sendCheckUserStatusEvent } from "../common";
|
import { CHECK_IDS, sendCheckUserStatusEvent } from "../common";
|
||||||
import { qclone } from "qclone";
|
import { qclone } from "qclone";
|
||||||
var tfun = require("transfun/transfun.js").tfun;
|
|
||||||
if (!tfun) {
|
|
||||||
tfun = global.tfun;
|
|
||||||
}
|
|
||||||
|
|
||||||
export default class Notebooks extends Collection {
|
export default class Notebooks extends Collection {
|
||||||
async add(notebookArg) {
|
async add(notebookArg) {
|
||||||
@@ -72,11 +67,11 @@ export default class Notebooks extends Collection {
|
|||||||
}
|
}
|
||||||
|
|
||||||
get pinned() {
|
get pinned() {
|
||||||
return tfun.filter(".pinned === true")(this.all);
|
return this.all.filter((item) => item.pinned === true);
|
||||||
}
|
}
|
||||||
|
|
||||||
get deleted() {
|
get deleted() {
|
||||||
return tfun.filter(".dateDeleted > 0")(this.raw);
|
return this.raw.filter((item) => item.dateDeleted > 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -101,11 +96,4 @@ export default class Notebooks extends Collection {
|
|||||||
await this._db.trash.add(notebookData);
|
await this._db.trash.add(notebookData);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
filter(query) {
|
|
||||||
if (!query) return [];
|
|
||||||
let queryFn = (v) => fuzzysearch(query, v.title + " " + v.description);
|
|
||||||
if (query instanceof Function) queryFn = query;
|
|
||||||
return tfun.filter(queryFn)(this.all);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,10 +11,6 @@ import getId from "../utils/id";
|
|||||||
import { EV, EVENTS } from "../common";
|
import { EV, EVENTS } from "../common";
|
||||||
import { getContentFromData } from "../content-types";
|
import { getContentFromData } from "../content-types";
|
||||||
import qclone from "qclone/src/qclone";
|
import qclone from "qclone/src/qclone";
|
||||||
var tfun = require("transfun/transfun.js").tfun;
|
|
||||||
if (!tfun) {
|
|
||||||
tfun = global.tfun;
|
|
||||||
}
|
|
||||||
|
|
||||||
export default class Notes extends Collection {
|
export default class Notes extends Collection {
|
||||||
async add(noteArg) {
|
async add(noteArg) {
|
||||||
@@ -134,19 +130,19 @@ export default class Notes extends Collection {
|
|||||||
}
|
}
|
||||||
|
|
||||||
get pinned() {
|
get pinned() {
|
||||||
return tfun.filter(".pinned === true")(this.all);
|
return this.all.filter((item) => item.pinned === true);
|
||||||
}
|
}
|
||||||
|
|
||||||
get conflicted() {
|
get conflicted() {
|
||||||
return tfun.filter(".conflicted === true")(this.all);
|
return this.all.filter((item) => item.conflicted === true);
|
||||||
}
|
}
|
||||||
|
|
||||||
get favorites() {
|
get favorites() {
|
||||||
return tfun.filter(".favorite === true")(this.all);
|
return this.all.filter((item) => item.favorite === true);
|
||||||
}
|
}
|
||||||
|
|
||||||
get deleted() {
|
get deleted() {
|
||||||
return tfun.filter(".dateDeleted > 0")(this.raw);
|
return this.raw.filter((item) => item.dateDeleted > 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
tagged(tagId) {
|
tagged(tagId) {
|
||||||
|
|||||||
@@ -1,8 +1,9 @@
|
|||||||
import TurndownService from "turndown";
|
import TurndownService from "turndown";
|
||||||
|
import decode from "lean-he/decode";
|
||||||
|
|
||||||
var turndownService = new TurndownService();
|
var turndownService = new TurndownService();
|
||||||
|
|
||||||
const splitter = /\W+/gm;
|
const splitter = /\W+/gm;
|
||||||
var he;
|
|
||||||
class Tiny {
|
class Tiny {
|
||||||
constructor(data) {
|
constructor(data) {
|
||||||
this.data = data;
|
this.data = data;
|
||||||
@@ -18,10 +19,7 @@ class Tiny {
|
|||||||
let doc = new DOMParser().parseFromString(this.data, "text/html");
|
let doc = new DOMParser().parseFromString(this.data, "text/html");
|
||||||
return doc.body.textContent || "";
|
return doc.body.textContent || "";
|
||||||
} else {
|
} else {
|
||||||
if (!he) {
|
return decode(
|
||||||
he = require("he");
|
|
||||||
}
|
|
||||||
return he.decode(
|
|
||||||
this.data.replace(/<br[^>]*>/gi, "\n").replace(/<[^>]+>/g, "")
|
this.data.replace(/<br[^>]*>/gi, "\n").replace(/<[^>]+>/g, "")
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,11 +1,10 @@
|
|||||||
import { MD5 } from "jshashes";
|
|
||||||
import Migrator from "./migrator.js";
|
import Migrator from "./migrator.js";
|
||||||
import {
|
import {
|
||||||
CHECK_IDS,
|
CHECK_IDS,
|
||||||
sendCheckUserStatusEvent,
|
sendCheckUserStatusEvent,
|
||||||
CURRENT_DATABASE_VERSION,
|
CURRENT_DATABASE_VERSION,
|
||||||
} from "../common.js";
|
} from "../common.js";
|
||||||
const md5 = new MD5();
|
import SparkMD5 from "spark-md5";
|
||||||
|
|
||||||
const invalidKeys = ["user", "t", "lastBackupTime"];
|
const invalidKeys = ["user", "t", "lastBackupTime"];
|
||||||
const validTypes = ["mobile", "web", "node"];
|
const validTypes = ["mobile", "web", "node"];
|
||||||
@@ -54,7 +53,7 @@ export default class Backup {
|
|||||||
type,
|
type,
|
||||||
date: Date.now(),
|
date: Date.now(),
|
||||||
data,
|
data,
|
||||||
hash: md5.hex(JSON.stringify(data)),
|
hash: SparkMD5.hash(JSON.stringify(data)),
|
||||||
hash_type: "md5",
|
hash_type: "md5",
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -154,7 +153,7 @@ export default class Backup {
|
|||||||
const { hash, hash_type, data: db } = backup;
|
const { hash, hash_type, data: db } = backup;
|
||||||
switch (hash_type) {
|
switch (hash_type) {
|
||||||
case "md5": {
|
case "md5": {
|
||||||
return hash === md5.hex(JSON.stringify(db));
|
return hash === SparkMD5.hash(JSON.stringify(db));
|
||||||
}
|
}
|
||||||
default: {
|
default: {
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -23,13 +23,11 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"fast-sort": "^2.0.1",
|
"fast-sort": "^2.0.1",
|
||||||
"fuzzysearch": "^1.0.3",
|
"fuzzysearch": "^1.0.3",
|
||||||
"he": "^1.2.0",
|
"lean-he": "^2.1.2",
|
||||||
"jshashes": "^1.0.8",
|
|
||||||
"no-internet": "^1.5.2",
|
"no-internet": "^1.5.2",
|
||||||
"qclone": "^1.0.4",
|
"qclone": "^1.0.4",
|
||||||
"quill-delta-to-html": "^0.12.0",
|
"quill-delta-to-html": "^0.12.0",
|
||||||
"spark-md5": "^3.0.1",
|
"spark-md5": "^3.0.1",
|
||||||
"transfun": "^1.0.2",
|
|
||||||
"turndown": "^7.0.0"
|
"turndown": "^7.0.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2674,11 +2674,6 @@ has@^1.0.3:
|
|||||||
dependencies:
|
dependencies:
|
||||||
function-bind "^1.1.1"
|
function-bind "^1.1.1"
|
||||||
|
|
||||||
he@^1.2.0:
|
|
||||||
version "1.2.0"
|
|
||||||
resolved "https://registry.yarnpkg.com/he/-/he-1.2.0.tgz#84ae65fa7eafb165fddb61566ae14baf05664f0f"
|
|
||||||
integrity sha512-F/1DnUGPopORZi0ni+CvrCgHQ5FyEAHRLSApuYWMmrbSwoN2Mn/7k+Gl38gJnR7yyDZk6WLXwiGod1JOWNDKGw==
|
|
||||||
|
|
||||||
home-or-tmp@^2.0.0:
|
home-or-tmp@^2.0.0:
|
||||||
version "2.0.0"
|
version "2.0.0"
|
||||||
resolved "https://registry.yarnpkg.com/home-or-tmp/-/home-or-tmp-2.0.0.tgz#e36c3f2d2cae7d746a857e38d18d5f32a7882db8"
|
resolved "https://registry.yarnpkg.com/home-or-tmp/-/home-or-tmp-2.0.0.tgz#e36c3f2d2cae7d746a857e38d18d5f32a7882db8"
|
||||||
@@ -3412,11 +3407,6 @@ jsesc@~0.5.0:
|
|||||||
resolved "https://registry.yarnpkg.com/jsesc/-/jsesc-0.5.0.tgz#e7dee66e35d6fc16f710fe91d5cf69f70f08911d"
|
resolved "https://registry.yarnpkg.com/jsesc/-/jsesc-0.5.0.tgz#e7dee66e35d6fc16f710fe91d5cf69f70f08911d"
|
||||||
integrity sha1-597mbjXW/Bb3EP6R1c9p9w8IkR0=
|
integrity sha1-597mbjXW/Bb3EP6R1c9p9w8IkR0=
|
||||||
|
|
||||||
jshashes@^1.0.8:
|
|
||||||
version "1.0.8"
|
|
||||||
resolved "https://registry.yarnpkg.com/jshashes/-/jshashes-1.0.8.tgz#f60d837428383abf73ab022e1542e6614bd75514"
|
|
||||||
integrity sha512-btmQZ/w1rj8Lb6nEwvhjM7nBYoj54yaEFo2PWh3RkxZ8qNwuvOxvQYN/JxVuwoMmdIluL+XwYVJ+pEEZoSYybQ==
|
|
||||||
|
|
||||||
json-parse-better-errors@^1.0.1:
|
json-parse-better-errors@^1.0.1:
|
||||||
version "1.0.2"
|
version "1.0.2"
|
||||||
resolved "https://registry.yarnpkg.com/json-parse-better-errors/-/json-parse-better-errors-1.0.2.tgz#bb867cfb3450e69107c131d1c514bab3dc8bcaa9"
|
resolved "https://registry.yarnpkg.com/json-parse-better-errors/-/json-parse-better-errors-1.0.2.tgz#bb867cfb3450e69107c131d1c514bab3dc8bcaa9"
|
||||||
@@ -3493,6 +3483,11 @@ kleur@^3.0.3:
|
|||||||
resolved "https://registry.yarnpkg.com/kleur/-/kleur-3.0.3.tgz#a79c9ecc86ee1ce3fa6206d1216c501f147fc07e"
|
resolved "https://registry.yarnpkg.com/kleur/-/kleur-3.0.3.tgz#a79c9ecc86ee1ce3fa6206d1216c501f147fc07e"
|
||||||
integrity sha512-eTIzlVOSUR+JxdDFepEYcBMtZ9Qqdef+rnzWdRZuMbOywu5tO2w2N7rqjoANZ5k9vywhL6Br1VRjUIgTQx4E8w==
|
integrity sha512-eTIzlVOSUR+JxdDFepEYcBMtZ9Qqdef+rnzWdRZuMbOywu5tO2w2N7rqjoANZ5k9vywhL6Br1VRjUIgTQx4E8w==
|
||||||
|
|
||||||
|
lean-he@^2.1.2:
|
||||||
|
version "2.1.2"
|
||||||
|
resolved "https://registry.yarnpkg.com/lean-he/-/lean-he-2.1.2.tgz#50c2422f0ca42f6737c9c1988b555cf00ebc712f"
|
||||||
|
integrity sha512-g/cq01j/rnv7JWoxFmeLgJdd/CucksyDtS+pyepO89EdT0O4KfHJokOVz/xQ4mvjKJzcrj87Q3/s2ESou90WCQ==
|
||||||
|
|
||||||
left-pad@^1.3.0:
|
left-pad@^1.3.0:
|
||||||
version "1.3.0"
|
version "1.3.0"
|
||||||
resolved "https://registry.yarnpkg.com/left-pad/-/left-pad-1.3.0.tgz#5b8a3a7765dfe001261dde915589e782f8c94d1e"
|
resolved "https://registry.yarnpkg.com/left-pad/-/left-pad-1.3.0.tgz#5b8a3a7765dfe001261dde915589e782f8c94d1e"
|
||||||
@@ -4776,11 +4771,6 @@ tr46@^1.0.1:
|
|||||||
dependencies:
|
dependencies:
|
||||||
punycode "^2.1.0"
|
punycode "^2.1.0"
|
||||||
|
|
||||||
transfun@^1.0.2:
|
|
||||||
version "1.0.2"
|
|
||||||
resolved "https://registry.yarnpkg.com/transfun/-/transfun-1.0.2.tgz#14a3116296a8d921cbf9678ebd5eee1c5bb77b98"
|
|
||||||
integrity sha1-FKMRYpao2SHL+WeOvV7uHFu3e5g=
|
|
||||||
|
|
||||||
trim-right@^1.0.1:
|
trim-right@^1.0.1:
|
||||||
version "1.0.1"
|
version "1.0.1"
|
||||||
resolved "https://registry.yarnpkg.com/trim-right/-/trim-right-1.0.1.tgz#cb2e1203067e0c8de1f614094b9fe45704ea6003"
|
resolved "https://registry.yarnpkg.com/trim-right/-/trim-right-1.0.1.tgz#cb2e1203067e0c8de1f614094b9fe45704ea6003"
|
||||||
|
|||||||
Reference in New Issue
Block a user