diff --git a/src/js/dictionaryManagement.js b/src/js/dictionaryManagement.js
index ff008f8..e48252b 100644
--- a/src/js/dictionaryManagement.js
+++ b/src/js/dictionaryManagement.js
@@ -1,9 +1,10 @@
import papa from 'papaparse';
import { renderDictionaryDetails, renderPartsOfSpeech, renderAll, renderTheme } from "./render";
import { removeTags, cloneObject, getTimestampInSeconds, download, slugify } from "../helpers";
-import { LOCAL_STORAGE_KEY, DEFAULT_DICTIONARY, MIGRATE_VERSION } from "../constants";
+import { LOCAL_STORAGE_KEY, DEFAULT_DICTIONARY } from "../constants";
import { addMessage, getNextId, hasToken } from "./utilities";
import { addWord, sortWords } from "./wordManagement";
+import { migrateDictionary } from './migration';
export function updateDictionary () {
@@ -285,39 +286,3 @@ export function exportWords() {
download(csv, fileName, 'text/csv;charset=utf-8');
}, 1);
}
-
-export function migrateDictionary() {
- let migrated = false;
- if (!window.currentDictionary.hasOwnProperty('version')) {
- const fixStupidOldNonsense = string => string.replace(/"/g, '"').replace(/'/g, "'").replace(/\/g, '\\').replace(/
/g, '\n');
- window.currentDictionary.description = fixStupidOldNonsense(window.currentDictionary.description);
- const timestamp = getTimestampInSeconds();
- window.currentDictionary.words = window.currentDictionary.words.map(word => {
- word.definition = word.simpleDefinition;
- delete word.simpleDefinition;
- word.details = fixStupidOldNonsense(word.longDefinition);
- delete word.longDefinition;
- word.lastUpdated = timestamp;
- word.createdOn = timestamp;
- return word;
- });
- window.currentDictionary = Object.assign({}, DEFAULT_DICTIONARY, window.currentDictionary);
- window.currentDictionary.partsOfSpeech = window.currentDictionary.settings.partsOfSpeech.split(',').map(val => val.trim()).filter(val => val !== '');
- delete window.currentDictionary.settings.partsOfSpeech;
- delete window.currentDictionary.nextWordId;
- window.currentDictionary.settings.sortByDefinition = window.currentDictionary.settings.sortByEquivalent;
- delete window.currentDictionary.settings.sortByEquivalent;
- window.currentDictionary.settings.theme = 'default';
- delete window.currentDictionary.settings.isComplete;
-
- migrated = true;
- } else if (window.currentDictionary.version !== MIGRATE_VERSION) {
- switch (window.currentDictionary.version) {
- default: console.error('Unknown version'); break;
- }
- }
-
- if (migrated) {
- saveDictionary();
- }
-}
diff --git a/src/js/migration.js b/src/js/migration.js
index bdb3170..6709b5c 100644
--- a/src/js/migration.js
+++ b/src/js/migration.js
@@ -1,4 +1,4 @@
-import { LOCAL_STORAGE_KEY } from "../constants";
+import { LOCAL_STORAGE_KEY, DEFAULT_DICTIONARY, MIGRATE_VERSION } from "../constants";
export default function migrate() {
if (window.location.pathname === '/') {
@@ -74,4 +74,40 @@ function checkForReceived() {
delete window.dictionaryImportedFromHTTP;
}
}
+}
+
+export function migrateDictionary() {
+ let migrated = false;
+ if (!window.currentDictionary.hasOwnProperty('version')) {
+ const fixStupidOldNonsense = string => string.replace(/"/g, '"').replace(/'/g, "'").replace(/\/g, '\\').replace(/
/g, '\n');
+ window.currentDictionary.description = fixStupidOldNonsense(window.currentDictionary.description);
+ const timestamp = getTimestampInSeconds();
+ window.currentDictionary.words = window.currentDictionary.words.map(word => {
+ word.definition = word.simpleDefinition;
+ delete word.simpleDefinition;
+ word.details = fixStupidOldNonsense(word.longDefinition);
+ delete word.longDefinition;
+ word.lastUpdated = timestamp;
+ word.createdOn = timestamp;
+ return word;
+ });
+ window.currentDictionary = Object.assign({}, DEFAULT_DICTIONARY, window.currentDictionary);
+ window.currentDictionary.partsOfSpeech = window.currentDictionary.settings.partsOfSpeech.split(',').map(val => val.trim()).filter(val => val !== '');
+ delete window.currentDictionary.settings.partsOfSpeech;
+ delete window.currentDictionary.nextWordId;
+ window.currentDictionary.settings.sortByDefinition = window.currentDictionary.settings.sortByEquivalent;
+ delete window.currentDictionary.settings.sortByEquivalent;
+ window.currentDictionary.settings.theme = 'default';
+ delete window.currentDictionary.settings.isComplete;
+
+ migrated = true;
+ } else if (window.currentDictionary.version !== MIGRATE_VERSION) {
+ switch (window.currentDictionary.version) {
+ default: console.error('Unknown version'); break;
+ }
+ }
+
+ if (migrated) {
+ saveDictionary();
+ }
}
\ No newline at end of file