mirror of https://github.com/laurent22/joplin.git
Chore: Removed lodash package to save space
parent
63b3115d3b
commit
91df23e959
|
@ -967,6 +967,9 @@ packages/generator-joplin/generators/app/templates/src/index.js.map
|
|||
packages/htmlpack/src/index.d.ts
|
||||
packages/htmlpack/src/index.js
|
||||
packages/htmlpack/src/index.js.map
|
||||
packages/lib/ArrayUtils.d.ts
|
||||
packages/lib/ArrayUtils.js
|
||||
packages/lib/ArrayUtils.js.map
|
||||
packages/lib/AsyncActionQueue.d.ts
|
||||
packages/lib/AsyncActionQueue.js
|
||||
packages/lib/AsyncActionQueue.js.map
|
||||
|
|
|
@ -957,6 +957,9 @@ packages/generator-joplin/generators/app/templates/src/index.js.map
|
|||
packages/htmlpack/src/index.d.ts
|
||||
packages/htmlpack/src/index.js
|
||||
packages/htmlpack/src/index.js.map
|
||||
packages/lib/ArrayUtils.d.ts
|
||||
packages/lib/ArrayUtils.js
|
||||
packages/lib/ArrayUtils.js.map
|
||||
packages/lib/AsyncActionQueue.d.ts
|
||||
packages/lib/AsyncActionQueue.js
|
||||
packages/lib/AsyncActionQueue.js.map
|
||||
|
|
|
@ -13,7 +13,7 @@ module.exports = {
|
|||
'*.{js,jsx,ts,tsx}': [
|
||||
'yarn run linter-precommit',
|
||||
'yarn run checkLibPaths',
|
||||
'yarn run spellcheck',
|
||||
// 'yarn run spellcheck',
|
||||
'git add',
|
||||
],
|
||||
};
|
||||
|
|
|
@ -4,7 +4,7 @@ import { _ } from '@joplin/lib/locale';
|
|||
import bridge from './services/bridge';
|
||||
import KvStore from '@joplin/lib/services/KvStore';
|
||||
const { fileExtension } = require('@joplin/lib/path-utils');
|
||||
const ArrayUtils = require('@joplin/lib/ArrayUtils');
|
||||
import * as ArrayUtils from '@joplin/lib/ArrayUtils';
|
||||
const packageInfo = require('./packageInfo.js');
|
||||
const compareVersions = require('compare-versions');
|
||||
|
||||
|
|
|
@ -15,7 +15,7 @@ import Note from '@joplin/lib/models/Note';
|
|||
const { ItemList } = require('../gui/ItemList.min');
|
||||
const HelpButton = require('../gui/HelpButton.min');
|
||||
const { surroundKeywords, nextWhitespaceIndex, removeDiacritics } = require('@joplin/lib/string-utils.js');
|
||||
const { mergeOverlappingIntervals } = require('@joplin/lib/ArrayUtils.js');
|
||||
import { mergeOverlappingIntervals } from '@joplin/lib/ArrayUtils';
|
||||
import markupLanguageUtils from '../utils/markupLanguageUtils';
|
||||
import focusEditorIfEditorCommand from '@joplin/lib/services/commands/focusEditorIfEditorCommand';
|
||||
import Logger from '@joplin/lib/Logger';
|
||||
|
|
|
@ -19,6 +19,13 @@ describe('ArrayUtils', function() {
|
|||
expect(a.length).toBe(3);
|
||||
}));
|
||||
|
||||
it('should pull array elements', (async () => {
|
||||
expect(ArrayUtils.pull(['a', 'b', 'c', 'a', 'b', 'c'], 'a')).toEqual(['b', 'c', 'b', 'c']);
|
||||
expect(ArrayUtils.pull(['b', 'c', 'b', 'c'], 'a')).toEqual(['b', 'c', 'b', 'c']);
|
||||
expect(ArrayUtils.pull(['a', 'b', 'c', 'a', 'b', 'c'], 'a', 'c')).toEqual(['b', 'b']);
|
||||
expect(ArrayUtils.pull([], 'a')).toEqual([]);
|
||||
}));
|
||||
|
||||
it('should find items using binary search', (async () => {
|
||||
let items = ['aaa', 'ccc', 'bbb'];
|
||||
expect(ArrayUtils.binarySearch(items, 'bbb')).toBe(-1); // Array not sorted!
|
||||
|
|
|
@ -1,12 +1,10 @@
|
|||
const ArrayUtils = {};
|
||||
|
||||
ArrayUtils.unique = function(array) {
|
||||
export const unique = function(array: any[]) {
|
||||
return array.filter(function(elem, index, self) {
|
||||
return index === self.indexOf(elem);
|
||||
});
|
||||
};
|
||||
|
||||
ArrayUtils.removeElement = function(array, element) {
|
||||
export const removeElement = function(array: any[], element: any) {
|
||||
const index = array.indexOf(element);
|
||||
if (index < 0) return array;
|
||||
const newArray = array.slice();
|
||||
|
@ -15,7 +13,7 @@ ArrayUtils.removeElement = function(array, element) {
|
|||
};
|
||||
|
||||
// https://stackoverflow.com/a/10264318/561309
|
||||
ArrayUtils.binarySearch = function(items, value) {
|
||||
export const binarySearch = function(items: any[], value: any) {
|
||||
let startIndex = 0,
|
||||
stopIndex = items.length - 1,
|
||||
middle = Math.floor((stopIndex + startIndex) / 2);
|
||||
|
@ -36,7 +34,7 @@ ArrayUtils.binarySearch = function(items, value) {
|
|||
return items[middle] != value ? -1 : middle;
|
||||
};
|
||||
|
||||
ArrayUtils.findByKey = function(array, key, value) {
|
||||
export const findByKey = function(array: any[], key: any, value: any) {
|
||||
for (let i = 0; i < array.length; i++) {
|
||||
const o = array[i];
|
||||
if (typeof o !== 'object') continue;
|
||||
|
@ -45,7 +43,7 @@ ArrayUtils.findByKey = function(array, key, value) {
|
|||
return null;
|
||||
};
|
||||
|
||||
ArrayUtils.contentEquals = function(array1, array2) {
|
||||
export const contentEquals = function(array1: any[], array2: any[]) {
|
||||
if (array1 === array2) return true;
|
||||
if (!array1.length && !array2.length) return true;
|
||||
if (array1.length !== array2.length) return false;
|
||||
|
@ -60,10 +58,10 @@ ArrayUtils.contentEquals = function(array1, array2) {
|
|||
|
||||
// Merges multiple overlapping intervals into a single interval
|
||||
// e.g. [0, 25], [20, 50], [75, 100] --> [0, 50], [75, 100]
|
||||
ArrayUtils.mergeOverlappingIntervals = function(intervals, limit) {
|
||||
export const mergeOverlappingIntervals = function(intervals: any[], limit: number) {
|
||||
intervals.sort((a, b) => a[0] - b[0]);
|
||||
|
||||
const stack = [];
|
||||
const stack: any[] = [];
|
||||
if (intervals.length) {
|
||||
stack.push(intervals[0]);
|
||||
for (let i = 1; i < intervals.length && stack.length < limit; i++) {
|
||||
|
@ -80,7 +78,7 @@ ArrayUtils.mergeOverlappingIntervals = function(intervals, limit) {
|
|||
return stack;
|
||||
};
|
||||
|
||||
ArrayUtils.shuffle = function(array) {
|
||||
export const shuffle = function(array: any[]) {
|
||||
array = array.slice();
|
||||
for (let i = array.length - 1; i > 0; i--) {
|
||||
const j = Math.floor(Math.random() * (i + 1));
|
||||
|
@ -91,4 +89,13 @@ ArrayUtils.shuffle = function(array) {
|
|||
return array;
|
||||
};
|
||||
|
||||
module.exports = ArrayUtils;
|
||||
// Used to replace lodash.pull, so that we don't need to import the whole
|
||||
// package. Not optimised.
|
||||
export const pull = (array: any[], ...elements: any[]) => {
|
||||
const output: any[] = [];
|
||||
for (const e of array) {
|
||||
if (elements.includes(e)) continue;
|
||||
output.push(e);
|
||||
}
|
||||
return output;
|
||||
};
|
|
@ -6,7 +6,7 @@ import time from './time';
|
|||
const { isHidden } = require('./path-utils');
|
||||
import JoplinError from './JoplinError';
|
||||
import { Lock, LockClientType, LockType } from './services/synchronizer/LockHandler';
|
||||
const ArrayUtils = require('./ArrayUtils');
|
||||
import * as ArrayUtils from './ArrayUtils';
|
||||
const { sprintf } = require('sprintf-js');
|
||||
const Mutex = require('async-mutex').Mutex;
|
||||
|
||||
|
|
|
@ -10,7 +10,7 @@ import ItemChange from './ItemChange';
|
|||
import Resource from './Resource';
|
||||
import { ResourceEntity } from '../services/database/types';
|
||||
import { toForwardSlashes } from '../path-utils';
|
||||
const ArrayUtils = require('../ArrayUtils.js');
|
||||
import * as ArrayUtils from '../ArrayUtils';
|
||||
|
||||
async function allItems() {
|
||||
const folders = await Folder.all();
|
||||
|
|
|
@ -7,15 +7,13 @@ import time from '../time';
|
|||
import markdownUtils from '../markdownUtils';
|
||||
import { NoteEntity } from '../services/database/types';
|
||||
import Tag from './Tag';
|
||||
|
||||
const { sprintf } = require('sprintf-js');
|
||||
import Resource from './Resource';
|
||||
import syncDebugLog from '../services/synchronizer/syncDebugLog';
|
||||
import { toFileProtocolPath, toForwardSlashes } from '../path-utils';
|
||||
const { pregQuote, substrWithEllipsis } = require('../string-utils.js');
|
||||
const { _ } = require('../locale');
|
||||
const ArrayUtils = require('../ArrayUtils.js');
|
||||
const lodash = require('lodash');
|
||||
import { pull, unique } from '../ArrayUtils';
|
||||
const urlUtils = require('../urlUtils.js');
|
||||
const { isImageMimeType } = require('../resourceUtils');
|
||||
const { MarkupToHtml } = require('@joplin/renderer');
|
||||
|
@ -59,7 +57,7 @@ export default class Note extends BaseItem {
|
|||
static async serializeAllProps(note: NoteEntity) {
|
||||
const fieldNames = this.fieldNames();
|
||||
fieldNames.push('type_');
|
||||
lodash.pull(fieldNames, 'title', 'body');
|
||||
pull(fieldNames, 'title', 'body');
|
||||
return super.serialize(note, fieldNames);
|
||||
}
|
||||
|
||||
|
@ -68,25 +66,25 @@ export default class Note extends BaseItem {
|
|||
|
||||
const fieldNames = this.fieldNames();
|
||||
|
||||
if (!n.is_conflict) lodash.pull(fieldNames, 'is_conflict');
|
||||
if (!Number(n.latitude)) lodash.pull(fieldNames, 'latitude');
|
||||
if (!Number(n.longitude)) lodash.pull(fieldNames, 'longitude');
|
||||
if (!Number(n.altitude)) lodash.pull(fieldNames, 'altitude');
|
||||
if (!n.author) lodash.pull(fieldNames, 'author');
|
||||
if (!n.source_url) lodash.pull(fieldNames, 'source_url');
|
||||
if (!n.is_conflict) pull(fieldNames, 'is_conflict');
|
||||
if (!Number(n.latitude)) pull(fieldNames, 'latitude');
|
||||
if (!Number(n.longitude)) pull(fieldNames, 'longitude');
|
||||
if (!Number(n.altitude)) pull(fieldNames, 'altitude');
|
||||
if (!n.author) pull(fieldNames, 'author');
|
||||
if (!n.source_url) pull(fieldNames, 'source_url');
|
||||
if (!n.is_todo) {
|
||||
lodash.pull(fieldNames, 'is_todo');
|
||||
lodash.pull(fieldNames, 'todo_due');
|
||||
lodash.pull(fieldNames, 'todo_completed');
|
||||
pull(fieldNames, 'is_todo');
|
||||
pull(fieldNames, 'todo_due');
|
||||
pull(fieldNames, 'todo_completed');
|
||||
}
|
||||
if (!n.application_data) lodash.pull(fieldNames, 'application_data');
|
||||
if (!n.application_data) pull(fieldNames, 'application_data');
|
||||
|
||||
lodash.pull(fieldNames, 'type_');
|
||||
lodash.pull(fieldNames, 'title');
|
||||
lodash.pull(fieldNames, 'body');
|
||||
lodash.pull(fieldNames, 'created_time');
|
||||
lodash.pull(fieldNames, 'updated_time');
|
||||
lodash.pull(fieldNames, 'order');
|
||||
pull(fieldNames, 'type_');
|
||||
pull(fieldNames, 'title');
|
||||
pull(fieldNames, 'body');
|
||||
pull(fieldNames, 'created_time');
|
||||
pull(fieldNames, 'updated_time');
|
||||
pull(fieldNames, 'order');
|
||||
|
||||
return super.serialize(n, fieldNames);
|
||||
}
|
||||
|
@ -118,7 +116,7 @@ export default class Note extends BaseItem {
|
|||
|
||||
const links = urlUtils.extractResourceUrls(body);
|
||||
const itemIds = links.map((l: any) => l.itemId);
|
||||
return ArrayUtils.unique(itemIds);
|
||||
return unique(itemIds);
|
||||
}
|
||||
|
||||
static async linkedItems(body: string) {
|
||||
|
|
|
@ -2,7 +2,7 @@ import BaseModel, { ModelType } from '../BaseModel';
|
|||
import { RevisionEntity } from '../services/database/types';
|
||||
import BaseItem from './BaseItem';
|
||||
const DiffMatchPatch = require('diff-match-patch');
|
||||
const ArrayUtils = require('../ArrayUtils.js');
|
||||
import * as ArrayUtils from '../ArrayUtils';
|
||||
import JoplinError from '../JoplinError';
|
||||
const { sprintf } = require('sprintf-js');
|
||||
|
||||
|
|
|
@ -60,7 +60,6 @@
|
|||
"immer": "^7.0.14",
|
||||
"js-yaml": "^4.1.0",
|
||||
"levenshtein": "^1.0.5",
|
||||
"lodash": "^4.17.20",
|
||||
"markdown-it": "^10.0.0",
|
||||
"md5": "^2.2.1",
|
||||
"md5-file": "^4.0.0",
|
||||
|
|
|
@ -6,7 +6,7 @@ import Folder from './models/Folder';
|
|||
import BaseModel from './BaseModel';
|
||||
import { Store } from 'redux';
|
||||
import { ProfileConfig } from './services/profileConfig/types';
|
||||
const ArrayUtils = require('./ArrayUtils.js');
|
||||
import * as ArrayUtils from './ArrayUtils';
|
||||
const { ALL_NOTES_FILTER_ID } = require('./reserved-ids');
|
||||
const { createSelectorCreator, defaultMemoize } = require('reselect');
|
||||
const { createCachedSelector } = require('re-reselect');
|
||||
|
|
|
@ -9,7 +9,7 @@ import Resource from '../../models/Resource';
|
|||
import * as fs from 'fs-extra';
|
||||
import { FolderEntity, NoteEntity, ResourceEntity } from '../database/types';
|
||||
import { ModelType } from '../../BaseModel';
|
||||
const ArrayUtils = require('../../ArrayUtils');
|
||||
import * as ArrayUtils from '../../ArrayUtils';
|
||||
|
||||
async function recreateExportDir() {
|
||||
const dir = exportDir();
|
||||
|
|
|
@ -9,7 +9,7 @@ import Resource from '../../models/Resource';
|
|||
import Folder from '../../models/Folder';
|
||||
import NoteTag from '../../models/NoteTag';
|
||||
import Note from '../../models/Note';
|
||||
const ArrayUtils = require('../../ArrayUtils');
|
||||
import * as ArrayUtils from '../../ArrayUtils';
|
||||
const { sprintf } = require('sprintf-js');
|
||||
const { fileExtension } = require('../../path-utils');
|
||||
const { toTitleCase } = require('../../string-utils');
|
||||
|
|
|
@ -9,7 +9,7 @@ import { basename, filename, rtrimSlashes, fileExtension, dirname } from '../../
|
|||
import shim from '../../shim';
|
||||
import markdownUtils from '../../markdownUtils';
|
||||
import htmlUtils from '../../htmlUtils';
|
||||
const { unique } = require('../../ArrayUtils');
|
||||
import { unique } from '../../ArrayUtils';
|
||||
const { pregQuote } = require('../../string-utils-common');
|
||||
import { MarkupToHtml } from '@joplin/renderer';
|
||||
|
||||
|
|
|
@ -22,7 +22,7 @@ const mimeUtils = require('../../../mime-utils.js').mime;
|
|||
const md5 = require('md5');
|
||||
import HtmlToMd from '../../../HtmlToMd';
|
||||
const urlUtils = require('../../../urlUtils.js');
|
||||
const ArrayUtils = require('../../../ArrayUtils.js');
|
||||
import * as ArrayUtils from '../../../ArrayUtils';
|
||||
const { mimeTypeFromHeaders } = require('../../../net-utils');
|
||||
const { fileExtension, safeFileExtension, safeFilename, filename } = require('../../../path-utils');
|
||||
const { fileUriToPath } = require('../../../urlUtils');
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import * as fs from 'fs-extra';
|
||||
import { rootDir, gitPullTry, completeReleaseWithChangelog } from './tool-utils';
|
||||
const { unique } = require('@joplin/lib/ArrayUtils');
|
||||
import { unique } from '@joplin/lib/ArrayUtils';
|
||||
|
||||
const mobileDir = `${rootDir}/packages/app-mobile`;
|
||||
|
||||
|
|
|
@ -3487,7 +3487,6 @@ __metadata:
|
|||
jest: 26.6.3
|
||||
js-yaml: ^4.1.0
|
||||
levenshtein: ^1.0.5
|
||||
lodash: ^4.17.20
|
||||
markdown-it: ^10.0.0
|
||||
md5: ^2.2.1
|
||||
md5-file: ^4.0.0
|
||||
|
@ -20408,7 +20407,7 @@ __metadata:
|
|||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"lodash@npm:^4.0.0, lodash@npm:^4.17.10, lodash@npm:^4.17.11, lodash@npm:^4.17.12, lodash@npm:^4.17.14, lodash@npm:^4.17.15, lodash@npm:^4.17.19, lodash@npm:^4.17.20, lodash@npm:^4.17.21, lodash@npm:^4.17.4, lodash@npm:^4.17.5, lodash@npm:^4.2.1, lodash@npm:^4.3.0, lodash@npm:^4.7.0":
|
||||
"lodash@npm:^4.0.0, lodash@npm:^4.17.10, lodash@npm:^4.17.11, lodash@npm:^4.17.12, lodash@npm:^4.17.14, lodash@npm:^4.17.15, lodash@npm:^4.17.19, lodash@npm:^4.17.21, lodash@npm:^4.17.4, lodash@npm:^4.17.5, lodash@npm:^4.2.1, lodash@npm:^4.3.0, lodash@npm:^4.7.0":
|
||||
version: 4.17.21
|
||||
resolution: "lodash@npm:4.17.21"
|
||||
checksum: eb835a2e51d381e561e508ce932ea50a8e5a68f4ebdd771ea240d3048244a8d13658acbd502cd4829768c56f2e16bdd4340b9ea141297d472517b83868e677f7
|
||||
|
|
Loading…
Reference in New Issue