mirror of
https://github.com/Alamantus/Lexiconga.git
synced 2025-06-18 07:06:39 +02:00
Add timestamp to createdOn and lastUpdated
This commit is contained in:
parent
22f8c0885a
commit
6d27f40874
3 changed files with 29 additions and 20 deletions
|
@ -1,3 +1,6 @@
|
||||||
|
import { getTimestampInSeconds } from "./helpers";
|
||||||
|
|
||||||
|
export const MIGRATE_VERSION = '2.0.0';
|
||||||
export const DEFAULT_DICTIONARY = {
|
export const DEFAULT_DICTIONARY = {
|
||||||
name: 'New',
|
name: 'New',
|
||||||
specification: 'Dictionary',
|
specification: 'Dictionary',
|
||||||
|
@ -47,7 +50,8 @@ export const DEFAULT_DICTIONARY = {
|
||||||
isPublic: false,
|
isPublic: false,
|
||||||
},
|
},
|
||||||
lastUpdated: null,
|
lastUpdated: null,
|
||||||
createdOn: 0,
|
createdOn: getTimestampInSeconds(),
|
||||||
|
version: MIGRATE_VERSION,
|
||||||
};
|
};
|
||||||
|
|
||||||
export const DEFAULT_PAGE_SIZE = 50;
|
export const DEFAULT_PAGE_SIZE = 50;
|
||||||
|
|
|
@ -4,6 +4,28 @@ export function cloneObject(object) {
|
||||||
return JSON.parse(JSON.stringify(object));
|
return JSON.parse(JSON.stringify(object));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function getIndicesOf(searchStr, findIn, caseSensitive) {
|
||||||
|
// https://stackoverflow.com/a/3410557
|
||||||
|
const searchStrLen = searchStr.length;
|
||||||
|
if (searchStrLen == 0) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
let startIndex = 0, index, indices = [];
|
||||||
|
if (!caseSensitive) {
|
||||||
|
findIn = findIn.toLowerCase();
|
||||||
|
searchStr = searchStr.toLowerCase();
|
||||||
|
}
|
||||||
|
while ((index = findIn.indexOf(searchStr, startIndex)) > -1) {
|
||||||
|
indices.push(index);
|
||||||
|
startIndex = index + searchStrLen;
|
||||||
|
}
|
||||||
|
return indices;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getTimestampInSeconds() {
|
||||||
|
return Math.round(Date.now() / 1000);
|
||||||
|
}
|
||||||
|
|
||||||
export function removeTags(html) {
|
export function removeTags(html) {
|
||||||
if (html) {
|
if (html) {
|
||||||
var tagBody = '(?:[^"\'>]|"[^"]*"|\'[^\']*\')*';
|
var tagBody = '(?:[^"\'>]|"[^"]*"|\'[^\']*\')*';
|
||||||
|
@ -32,21 +54,3 @@ export function removeTags(html) {
|
||||||
export function slugify(string) {
|
export function slugify(string) {
|
||||||
return removeDiacritics(string).replace(/[!a-zA-Z0-9-_]/g, '-');
|
return removeDiacritics(string).replace(/[!a-zA-Z0-9-_]/g, '-');
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getIndicesOf(searchStr, findIn, caseSensitive) {
|
|
||||||
// https://stackoverflow.com/a/3410557
|
|
||||||
const searchStrLen = searchStr.length;
|
|
||||||
if (searchStrLen == 0) {
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
let startIndex = 0, index, indices = [];
|
|
||||||
if (!caseSensitive) {
|
|
||||||
findIn = findIn.toLowerCase();
|
|
||||||
searchStr = searchStr.toLowerCase();
|
|
||||||
}
|
|
||||||
while ((index = findIn.indexOf(searchStr, startIndex)) > -1) {
|
|
||||||
indices.push(index);
|
|
||||||
startIndex = index + searchStrLen;
|
|
||||||
}
|
|
||||||
return indices;
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import { renderDictionaryDetails, renderPartsOfSpeech } from "./render";
|
import { renderDictionaryDetails, renderPartsOfSpeech } from "./render";
|
||||||
import { removeTags, cloneObject } from "../helpers";
|
import { removeTags, cloneObject, getTimestampInSeconds } from "../helpers";
|
||||||
import { LOCAL_STORAGE_KEY, DEFAULT_DICTIONARY } from "../constants";
|
import { LOCAL_STORAGE_KEY, DEFAULT_DICTIONARY } from "../constants";
|
||||||
|
|
||||||
export function updateDictionary () {
|
export function updateDictionary () {
|
||||||
|
@ -73,6 +73,7 @@ export function saveAndCloseEditModal() {
|
||||||
}
|
}
|
||||||
|
|
||||||
export function saveDictionary() {
|
export function saveDictionary() {
|
||||||
|
window.currentDictionary.lastUpdated = getTimestampInSeconds();
|
||||||
window.localStorage.setItem(LOCAL_STORAGE_KEY, JSON.stringify(window.currentDictionary));
|
window.localStorage.setItem(LOCAL_STORAGE_KEY, JSON.stringify(window.currentDictionary));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue