Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

simple-localstorage-data-service-stub

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

simple-localstorage-data-service-stub - npm Package Compare versions

Comparing version 1.0.2 to 1.0.3

72

data-service.js

@@ -19,5 +19,12 @@ const getData = (url = '') => {

const processResponse = (r) => {
data = JSON.parse(r);
resourceNames = data ? Object.keys(data) : [];
actionNames = data ? Object.keys(actions): [];
return new Promise((resolve, reject) => {
try{
data = JSON.parse(r);
resourceNames = data ? Object.keys(data) : [];
actionNames = data ? Object.keys(actions): [];
resolve(data)
} catch (error) {
reject(error)
}
})
}

@@ -86,3 +93,3 @@

} else {
initData().then(r => route({url, action, payload}))
initData().then(r => route({url, action, payload}).then(rr => resolve(rr)))
}

@@ -126,25 +133,52 @@ })

const saveData = (url = '', data) => {
const blob = new Blob([JSON.stringify(data)], { type: "text/json" });
const link = document.createElement("a");
const saveData = (url = 'savedData.json', data) => {
return new Promise((resolve, reject) => {
if (data) {
const blob = new Blob([JSON.stringify(data)], { type: "text/json" });
const link = document.createElement("a");
link.download = url;
link.href = window.URL.createObjectURL(blob);
link.dataset.downloadurl = ["text/json", link.download, link.href].join(":");
link.download = url;
link.href = window.URL.createObjectURL(blob);
link.dataset.downloadurl = ["text/json", link.download, link.href].join(":");
const event = new MouseEvent("click", {
view: window,
bubbles: true,
cancelable: true,
});
const event = new MouseEvent("click", {
view: window,
bubbles: true,
cancelable: true,
});
link.dispatchEvent(event);
link.remove()
link.dispatchEvent(event);
link.remove();
resolve()
} else {
initData().then((data) => saveData(url, data).then(() => resolve()))
}
})
}
return {get, create, delete: remove, update, saveData}
const uploadFileInput = (event) => {
return new Promise((resolve, reject) => {
let files = event?.target?.files;
let file = files ? files[0] : null;
if (!file) {
reject("No file passed to the function.");
return
}
try {
file.text().then(data => {
processResponse(data).then(r => resolve(r)).catch(e => reject(e))
});
} catch (error) {
reject(error)
}
})
}
return {get, create, delete: remove, update, saveData, uploadFileInput}
};
const actions = {
index: ({dataPool, id, resource, data}) => {
index: ({dataPool}) => {
return dataPool

@@ -151,0 +185,0 @@ },

{
"name": "simple-localstorage-data-service-stub",
"version": "1.0.2",
"version": "1.0.3",
"description": "REST-API-esque stub service for frontend experiments",

@@ -5,0 +5,0 @@ "main": "data-service.js",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc