Skip to content

Instantly share code, notes, and snippets.

Avatar

tofusoup429 tofusoup429

View GitHub Profile
View putDataInObjectStore1.js
const mutateDatabase = (_store, _data) => {
return new Promise((res,rej)=> {
let openRequest = indexedDB.open('testIDB', 1);
openRequest.onsuccess = () => {
let db = openRequest.result;
let transaction = db.transaction(_store,'readwrite');
let store = transaction.objectStore(_store)
let request = store.put(_data);
request.onerror = ()=> console.error('error', request.error)
request.onsuccess = () => res({status:200, data:_data});
View createObjectStores1.js
let DB_NAME = 'testIDB' // Name of database => one origin can have as many databases as it wants.
let OBJECT_STORE_NAME = 'testObjectStore' // Name of object store. => one database can have as many object store as it wants.
let request = indexedDB.open(DB_NAME, 1) // fire to open DB named 'testIDB' version 1.
request.onupgradeneeded = (e) => {
let db = request.result;
let objectStore = db.createObjectStore(OBJECT_STORE_NAME,{keyPath:"id"});
console.info('database and object store created');
};
View openIndexeddb1.js
let DB_NAME = 'testIDB' // Name of database => one origin can have as many databases as it wants.
let OBJECT_STORE_NAME = 'testObjectStore' // Name of object store. => one database can have as many object store as it wants.
let request = indexedDB.open(DB_NAME, 1) // fire to open DB named 'testIDB' version 1.
request.onupgradeneeded = (e) => {
//when the database named 'testIDB' does not exist.
//Or need to update to the latest version.(not discussing here)
console.log(e);
}
View removeItemLocalStorage2.js
let dataFetchedFromRemoteForCompanyInfo = {
name:"ABC corp",
address: "4090 Shady Pines Drive Independence VA",
postalCode: 24348
}
let dataFetchedFromRemoteForUserInfo = {
name:"ABC corp",
title: "manager",
}
localStorage.setItem('companyInfo', JSON.stringify(dataFetchedFromRemoteForCompanyInfo))
View removeItemLocalStorage1.js
let dataFetchedFromRemoteForCompanyInfo = {
name:"ABC corp",
address: "4090 Shady Pines Drive Independence VA",
postalCode: 24348
}
let dataFetchedFromRemoteForUserInfo = {
name:"ABC corp",
title: "manager",
}
localStorage.setItem('companyInfo', JSON.stringify(dataFetchedFromRemoteForCompanyInfo))
View localStorageGetItemExample.js
let dataFetchedFromRemote = {
name:"ABC corp",
address: "4090 Shady Pines Drive Independence VA",
postalCode: 24348
}
localStorage.setItem('companyInfo', JSON.stringify(dataFetchedFromRemote))
//this code stores the dataFetchedFromRemote in the user's client
let companyInfo = localStorage.getItem('companyInfo')
let parsedCompanyInfo = JSON.parse(companyInfo);
View localStorageSetItemExample.js
let dataFetchedFromRemote = {
name:"ABC corp",
address: "4090 Shady Pines Drive Independence VA",
postalCode: "24348"
}
localStorage.setItem('companyInfo', JSON.stringify(dataFetchedFromRemote))
//Before setting item in localStorage, you have to make the data string.
//this code stores the dataFetchedFromRemote in the user's client
View excelDateToJsDate.js
const {excelDateToJSDate} = require('@tofusoup429/excel-date-handlers');
let excelDateToJsDate = excelDateToJSDate(42088);
console.log(excelDateToJsDate);
//2015-03-25T00:00:00.000Z
View excelDateToStringDateFormat-test.js
const {excelDateToStringDateFormat} = require('@tofusoup429/excel-date-handlers');
let stringdate= excelDateToStringDateFormat(42088,'yyyy-mm-dd');
console.log(stringdate);
//2015-03-25
let stringdate= excelDateToStringDateFormat(42088,'yyyy/mm/dd');
console.log(stringdate);
//2015/03/25
You can’t perform that action at this time.