remote-storage
Advanced tools
Comparing version
@@ -1,2 +0,2 @@ | ||
import c from"cross-fetch";function d(){let s=new Date().getTime(),e=typeof performance<"u"&&performance.now&&performance.now()*1e3||0;return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,t=>{let r=Math.random()*16;return s>0?(r=(s+r)%16|0,s=Math.floor(s/16)):(r=(e+r)%16|0,e=Math.floor(e/16)),(t=="x"?r:r&7|8).toString(16)})}function i(){return typeof window<"u"}var x="x-remote-storage-instance-id",u="x-remote-storage-user-id";var a="/entities/",o=class{constructor(e){let{serverAddress:t,instanceId:r,userId:n}=e??{};this.serverAddress=t??"https://api.remote.storage",this.instanceId=r??"default",this.userId=n??this.getUserId()}async getItem(e,t){let r=await this.call("GET",`${a}${e}`,t,null);if(r.status===404)return null;let n=await r.text();return n.startsWith("{")?JSON.parse(n):n==="true"?!0:n==="false"?!1:isNaN(Number(n))?n:Number(n)}async setItem(e,t,r){await this.call("PUT",`${a}${e}`,r,t)}async removeItem(e,t){await this.call("DELETE",`${a}${e}`,t,null)}async call(e,t,r,n){return c(new URL(t,this.serverAddress).toString(),{method:e,headers:{"Content-Type":"application/json",[x]:this.instanceId,[u]:this.userId,...r==null?void 0:r.headers},body:n?JSON.stringify(n):void 0})}getUserId(){let e="rs-user-id";if(i()&&window.localStorage.getItem(e))return window.localStorage.getItem(e);let t=d();return i()&&window.localStorage.setItem(e,t),t}};export{x as HEADER_REMOTE_STORAGE_INSTANCE_ID,u as HEADER_REMOTE_STORAGE_USER_ID,o as RemoteStorage}; | ||
import c from"cross-fetch";function d(){let n=new Date().getTime(),e=typeof performance<"u"&&performance.now&&performance.now()*1e3||0;return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,r=>{let t=Math.random()*16;return n>0?(t=(n+t)%16|0,n=Math.floor(n/16)):(t=(e+t)%16|0,e=Math.floor(e/16)),(r=="x"?t:t&7|8).toString(16)})}function i(){return typeof window<"u"}var x="x-remote-storage-instance-id",u="x-remote-storage-user-id";var a="/entities/",o=class{constructor(e){let{serverAddress:r,instanceId:t,userId:s}=e??{};this.serverAddress=r??"https://api.remote.storage",this.instanceId=t??"default",this.userId=s??this.getUserId()}async getItem(e,r){let t=await this.call("GET",`${a}${e}`,r,null);if(t.status===404)return null;let s=await t.text();return!s.startsWith("{")&&!s.startsWith("[")?s==="true"?!0:s==="false"?!1:isNaN(Number(s))?s:Number(s):JSON.parse(s)}async setItem(e,r,t){await this.call("PUT",`${a}${e}`,t,r)}async removeItem(e,r){await this.call("DELETE",`${a}${e}`,r,null)}async call(e,r,t,s){return c(new URL(r,this.serverAddress).toString(),{method:e,headers:{"Content-Type":"application/json",[x]:this.instanceId,[u]:this.userId,...t==null?void 0:t.headers},body:s?JSON.stringify(s):void 0})}getUserId(){let e="rs-user-id";if(i()&&window.localStorage.getItem(e))return window.localStorage.getItem(e);let r=d();return i()&&window.localStorage.setItem(e,r),r}};export{x as HEADER_REMOTE_STORAGE_INSTANCE_ID,u as HEADER_REMOTE_STORAGE_USER_ID,o as RemoteStorage}; | ||
//# sourceMappingURL=index.js.map |
@@ -1,2 +0,2 @@ | ||
import c from"cross-fetch";function d(){let s=new Date().getTime(),e=typeof performance<"u"&&performance.now&&performance.now()*1e3||0;return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,t=>{let r=Math.random()*16;return s>0?(r=(s+r)%16|0,s=Math.floor(s/16)):(r=(e+r)%16|0,e=Math.floor(e/16)),(t=="x"?r:r&7|8).toString(16)})}function i(){return typeof window<"u"}var x="x-remote-storage-instance-id",u="x-remote-storage-user-id";var a="/entities/",o=class{constructor(e){let{serverAddress:t,instanceId:r,userId:n}=e??{};this.serverAddress=t??"https://api.remote.storage",this.instanceId=r??"default",this.userId=n??this.getUserId()}async getItem(e,t){let r=await this.call("GET",`${a}${e}`,t,null);if(r.status===404)return null;let n=await r.text();return n.startsWith("{")?JSON.parse(n):n==="true"?!0:n==="false"?!1:isNaN(Number(n))?n:Number(n)}async setItem(e,t,r){await this.call("PUT",`${a}${e}`,r,t)}async removeItem(e,t){await this.call("DELETE",`${a}${e}`,t,null)}async call(e,t,r,n){return c(new URL(t,this.serverAddress).toString(),{method:e,headers:{"Content-Type":"application/json",[x]:this.instanceId,[u]:this.userId,...r==null?void 0:r.headers},body:n?JSON.stringify(n):void 0})}getUserId(){let e="rs-user-id";if(i()&&window.localStorage.getItem(e))return window.localStorage.getItem(e);let t=d();return i()&&window.localStorage.setItem(e,t),t}};export{x as HEADER_REMOTE_STORAGE_INSTANCE_ID,u as HEADER_REMOTE_STORAGE_USER_ID,o as RemoteStorage}; | ||
import c from"cross-fetch";function d(){let n=new Date().getTime(),e=typeof performance<"u"&&performance.now&&performance.now()*1e3||0;return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,r=>{let t=Math.random()*16;return n>0?(t=(n+t)%16|0,n=Math.floor(n/16)):(t=(e+t)%16|0,e=Math.floor(e/16)),(r=="x"?t:t&7|8).toString(16)})}function i(){return typeof window<"u"}var x="x-remote-storage-instance-id",u="x-remote-storage-user-id";var a="/entities/",o=class{constructor(e){let{serverAddress:r,instanceId:t,userId:s}=e??{};this.serverAddress=r??"https://api.remote.storage",this.instanceId=t??"default",this.userId=s??this.getUserId()}async getItem(e,r){let t=await this.call("GET",`${a}${e}`,r,null);if(t.status===404)return null;let s=await t.text();return!s.startsWith("{")&&!s.startsWith("[")?s==="true"?!0:s==="false"?!1:isNaN(Number(s))?s:Number(s):JSON.parse(s)}async setItem(e,r,t){await this.call("PUT",`${a}${e}`,t,r)}async removeItem(e,r){await this.call("DELETE",`${a}${e}`,r,null)}async call(e,r,t,s){return c(new URL(r,this.serverAddress).toString(),{method:e,headers:{"Content-Type":"application/json",[x]:this.instanceId,[u]:this.userId,...t==null?void 0:t.headers},body:s?JSON.stringify(s):void 0})}getUserId(){let e="rs-user-id";if(i()&&window.localStorage.getItem(e))return window.localStorage.getItem(e);let r=d();return i()&&window.localStorage.setItem(e,r),r}};export{x as HEADER_REMOTE_STORAGE_INSTANCE_ID,u as HEADER_REMOTE_STORAGE_USER_ID,o as RemoteStorage}; | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "remote-storage", | ||
"version": "1.0.4", | ||
"version": "1.0.5", | ||
"description": "remoteStorage is a simple library that combines the localStorage API with a remote server to persist data across browsers and devices.", | ||
@@ -5,0 +5,0 @@ "type": "module", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
30146
0.6%