itty-sockets 0.5.0 → 0.5.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -66,7 +66,7 @@ import { connect } from 'itty-sockets'
66
66
  ...or simply paste this into your environment/console:
67
67
  <!-- BEGIN SNIPPET -->
68
68
  ```ts
69
- let connect=(e,s={})=>{let o,t=[],n=0,a={},r=()=>(o||(o=new WebSocket(/^(wss?):/.test(e)?e:`wss://ittysockets.io/c/${e}?`+new URLSearchParams(s)),o.onopen=()=>{for(;t.length;)o?.send(t.shift());for(let e of a.open??[])e();n&&o?.close()},o.onmessage=(e,s=JSON.parse(e.data))=>{for(let e of a[s.type??"message"]??[])e({...s,date:new Date(s.date)})},o.onclose=()=>{n=0,o=null;for(let e of a.close??[])e()}),l);const l=new Proxy(r,{get:(e,s)=>({open:r,close:()=>(1==o?.readyState?o.close():n=1,l),send:(e,s)=>(e=JSON.stringify(e),e=s?`@@${s}@@${e}`:e,1==o?.readyState?(o.send(e),l):(t.push(e),r())),push:(e,s)=>(n=1,l.send(e,s)),on:(e,s)=>((a[e]??=[]).push(s),r()),remove:(e,s,o=a[e],t=o?.indexOf(s)??-1)=>(~t&&o?.splice(t,1),r())}[s])});return l};
69
+ let connect=(e,s={})=>{let o,t=0,n=[],a={},r=()=>(o||(o=new WebSocket((/^wss?:/.test(e)?e:"wss://ittysockets.io/c/"+e)+"?"+new URLSearchParams(s)),o.onclose=()=>{t=0,o=null;for(let e of a.close??[])e()},o.onopen=()=>{for(;n.length;)o?.send(n.shift());for(let e of a.open??[])e();t&&o?.close()},o.onmessage=(e,s=JSON.parse(e.data))=>{for(let e of a[s.type??"message"]??[])e({...s,date:new Date(s.date)})}),l);const l=new Proxy(r,{get:(e,s)=>({close:()=>(1==o?.readyState?o.close():t=1,l),open:r,send:(e,s)=>(e=JSON.stringify(e),e=s?"@@"+s+"@@"+e:e,1==o?.readyState?(o.send(e),l):(n.push(e),r())),push:(e,s)=>(t=1,l.send(e,s)),on:(e,s)=>((a[e]??=[]).push(s),r()),remove:(e,s,o=a[e],t=o?.indexOf(s)??-1)=>(~t&&o?.splice(t,1),r())}[s])});return l};
70
70
  ```
71
71
  <!-- END SNIPPET -->
72
72
 
package/connect.js CHANGED
@@ -1 +1 @@
1
- "use strict";exports.connect=(e,s={})=>{let t,o=[],n=0,r={},a=()=>(t||(t=new WebSocket(/^(wss?):/.test(e)?e:`wss://ittysockets.io/c/${e}?`+new URLSearchParams(s)),t.onopen=()=>{for(;o.length;)t?.send(o.shift());for(let e of r.open??[])e();n&&t?.close()},t.onmessage=(e,s=JSON.parse(e.data))=>{for(let e of r[s.type??"message"]??[])e({...s,date:new Date(s.date)})},t.onclose=()=>{n=0,t=null;for(let e of r.close??[])e()}),c);const c=new Proxy(a,{get:(e,s)=>({open:a,close:()=>(1==t?.readyState?t.close():n=1,c),send:(e,s)=>(e=JSON.stringify(e),e=s?`@@${s}@@${e}`:e,1==t?.readyState?(t.send(e),c):(o.push(e),a())),push:(e,s)=>(n=1,c.send(e,s)),on:(e,s)=>((r[e]??=[]).push(s),a()),remove:(e,s,t=r[e],o=t?.indexOf(s)??-1)=>(~o&&t?.splice(o,1),a())}[s])});return c};
1
+ "use strict";exports.connect=(e,s={})=>{let t,o=0,n=[],r={},a=()=>(t||(t=new WebSocket((/^wss?:/.test(e)?e:"wss://ittysockets.io/c/"+e)+"?"+new URLSearchParams(s)),t.onclose=()=>{o=0,t=null;for(let e of r.close??[])e()},t.onopen=()=>{for(;n.length;)t?.send(n.shift());for(let e of r.open??[])e();o&&t?.close()},t.onmessage=(e,s=JSON.parse(e.data))=>{for(let e of r[s.type??"message"]??[])e({...s,date:new Date(s.date)})}),c);const c=new Proxy(a,{get:(e,s)=>({close:()=>(1==t?.readyState?t.close():o=1,c),open:a,send:(e,s)=>(e=JSON.stringify(e),e=s?"@@"+s+"@@"+e:e,1==t?.readyState?(t.send(e),c):(n.push(e),a())),push:(e,s)=>(o=1,c.send(e,s)),on:(e,s)=>((r[e]??=[]).push(s),a()),remove:(e,s,t=r[e],o=t?.indexOf(s)??-1)=>(~o&&t?.splice(o,1),a())}[s])});return c};
package/connect.mjs CHANGED
@@ -1 +1 @@
1
- const e=(e,s={})=>{let o,t=[],n=0,a={},r=()=>(o||(o=new WebSocket(/^(wss?):/.test(e)?e:`wss://ittysockets.io/c/${e}?`+new URLSearchParams(s)),o.onopen=()=>{for(;t.length;)o?.send(t.shift());for(let e of a.open??[])e();n&&o?.close()},o.onmessage=(e,s=JSON.parse(e.data))=>{for(let e of a[s.type??"message"]??[])e({...s,date:new Date(s.date)})},o.onclose=()=>{n=0,o=null;for(let e of a.close??[])e()}),l);const l=new Proxy(r,{get:(e,s)=>({open:r,close:()=>(1==o?.readyState?o.close():n=1,l),send:(e,s)=>(e=JSON.stringify(e),e=s?`@@${s}@@${e}`:e,1==o?.readyState?(o.send(e),l):(t.push(e),r())),push:(e,s)=>(n=1,l.send(e,s)),on:(e,s)=>((a[e]??=[]).push(s),r()),remove:(e,s,o=a[e],t=o?.indexOf(s)??-1)=>(~t&&o?.splice(t,1),r())}[s])});return l};export{e as connect};
1
+ const e=(e,s={})=>{let o,t=0,n=[],a={},r=()=>(o||(o=new WebSocket((/^wss?:/.test(e)?e:"wss://ittysockets.io/c/"+e)+"?"+new URLSearchParams(s)),o.onclose=()=>{t=0,o=null;for(let e of a.close??[])e()},o.onopen=()=>{for(;n.length;)o?.send(n.shift());for(let e of a.open??[])e();t&&o?.close()},o.onmessage=(e,s=JSON.parse(e.data))=>{for(let e of a[s.type??"message"]??[])e({...s,date:new Date(s.date)})}),l);const l=new Proxy(r,{get:(e,s)=>({close:()=>(1==o?.readyState?o.close():t=1,l),open:r,send:(e,s)=>(e=JSON.stringify(e),e=s?"@@"+s+"@@"+e:e,1==o?.readyState?(o.send(e),l):(n.push(e),r())),push:(e,s)=>(t=1,l.send(e,s)),on:(e,s)=>((a[e]??=[]).push(s),r()),remove:(e,s,o=a[e],t=o?.indexOf(s)??-1)=>(~t&&o?.splice(t,1),r())}[s])});return l};export{e as connect};
package/index.js CHANGED
@@ -1 +1 @@
1
- "use strict";exports.connect=(e,s={})=>{let t,o=[],n=0,r={},a=()=>(t||(t=new WebSocket(/^(wss?):/.test(e)?e:`wss://ittysockets.io/c/${e}?`+new URLSearchParams(s)),t.onopen=()=>{for(;o.length;)t?.send(o.shift());for(let e of r.open??[])e();n&&t?.close()},t.onmessage=(e,s=JSON.parse(e.data))=>{for(let e of r[s.type??"message"]??[])e({...s,date:new Date(s.date)})},t.onclose=()=>{n=0,t=null;for(let e of r.close??[])e()}),c);const c=new Proxy(a,{get:(e,s)=>({open:a,close:()=>(1==t?.readyState?t.close():n=1,c),send:(e,s)=>(e=JSON.stringify(e),e=s?`@@${s}@@${e}`:e,1==t?.readyState?(t.send(e),c):(o.push(e),a())),push:(e,s)=>(n=1,c.send(e,s)),on:(e,s)=>((r[e]??=[]).push(s),a()),remove:(e,s,t=r[e],o=t?.indexOf(s)??-1)=>(~o&&t?.splice(o,1),a())}[s])});return c};
1
+ "use strict";exports.connect=(e,s={})=>{let t,o=0,n=[],r={},a=()=>(t||(t=new WebSocket((/^wss?:/.test(e)?e:"wss://ittysockets.io/c/"+e)+"?"+new URLSearchParams(s)),t.onclose=()=>{o=0,t=null;for(let e of r.close??[])e()},t.onopen=()=>{for(;n.length;)t?.send(n.shift());for(let e of r.open??[])e();o&&t?.close()},t.onmessage=(e,s=JSON.parse(e.data))=>{for(let e of r[s.type??"message"]??[])e({...s,date:new Date(s.date)})}),c);const c=new Proxy(a,{get:(e,s)=>({close:()=>(1==t?.readyState?t.close():o=1,c),open:a,send:(e,s)=>(e=JSON.stringify(e),e=s?"@@"+s+"@@"+e:e,1==t?.readyState?(t.send(e),c):(n.push(e),a())),push:(e,s)=>(o=1,c.send(e,s)),on:(e,s)=>((r[e]??=[]).push(s),a()),remove:(e,s,t=r[e],o=t?.indexOf(s)??-1)=>(~o&&t?.splice(o,1),a())}[s])});return c};
package/index.mjs CHANGED
@@ -1 +1 @@
1
- const e=(e,s={})=>{let o,t=[],n=0,a={},r=()=>(o||(o=new WebSocket(/^(wss?):/.test(e)?e:`wss://ittysockets.io/c/${e}?`+new URLSearchParams(s)),o.onopen=()=>{for(;t.length;)o?.send(t.shift());for(let e of a.open??[])e();n&&o?.close()},o.onmessage=(e,s=JSON.parse(e.data))=>{for(let e of a[s.type??"message"]??[])e({...s,date:new Date(s.date)})},o.onclose=()=>{n=0,o=null;for(let e of a.close??[])e()}),l);const l=new Proxy(r,{get:(e,s)=>({open:r,close:()=>(1==o?.readyState?o.close():n=1,l),send:(e,s)=>(e=JSON.stringify(e),e=s?`@@${s}@@${e}`:e,1==o?.readyState?(o.send(e),l):(t.push(e),r())),push:(e,s)=>(n=1,l.send(e,s)),on:(e,s)=>((a[e]??=[]).push(s),r()),remove:(e,s,o=a[e],t=o?.indexOf(s)??-1)=>(~t&&o?.splice(t,1),r())}[s])});return l};export{e as connect};
1
+ const e=(e,s={})=>{let o,t=0,n=[],a={},r=()=>(o||(o=new WebSocket((/^wss?:/.test(e)?e:"wss://ittysockets.io/c/"+e)+"?"+new URLSearchParams(s)),o.onclose=()=>{t=0,o=null;for(let e of a.close??[])e()},o.onopen=()=>{for(;n.length;)o?.send(n.shift());for(let e of a.open??[])e();t&&o?.close()},o.onmessage=(e,s=JSON.parse(e.data))=>{for(let e of a[s.type??"message"]??[])e({...s,date:new Date(s.date)})}),l);const l=new Proxy(r,{get:(e,s)=>({close:()=>(1==o?.readyState?o.close():t=1,l),open:r,send:(e,s)=>(e=JSON.stringify(e),e=s?"@@"+s+"@@"+e:e,1==o?.readyState?(o.send(e),l):(n.push(e),r())),push:(e,s)=>(t=1,l.send(e,s)),on:(e,s)=>((a[e]??=[]).push(s),r()),remove:(e,s,o=a[e],t=o?.indexOf(s)??-1)=>(~t&&o?.splice(t,1),r())}[s])});return l};export{e as connect};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "itty-sockets",
3
- "version": "0.5.0",
3
+ "version": "0.5.2",
4
4
  "description": "Tiny realtime messaging client in under 450 bytes. No backend needed.",
5
5
  "type": "module",
6
6
  "exports": {