jails.stdlib 1.0.0

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.
Files changed (101) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +22 -0
  3. package/build.js +34 -0
  4. package/cancelable/README.md +41 -0
  5. package/cancelable/index.d.ts +1 -0
  6. package/cancelable/index.js +16 -0
  7. package/cancelable/index.ts +18 -0
  8. package/cancelable/index.umd.js +1 -0
  9. package/debounce/README.md +21 -0
  10. package/debounce/index.d.ts +1 -0
  11. package/debounce/index.js +11 -0
  12. package/debounce/index.ts +8 -0
  13. package/debounce/index.umd.js +1 -0
  14. package/delay/README.md +17 -0
  15. package/delay/index.d.ts +1 -0
  16. package/delay/index.js +6 -0
  17. package/delay/index.ts +6 -0
  18. package/delay/index.umd.js +1 -0
  19. package/form-validation/index.d.ts +18 -0
  20. package/form-validation/index.js +119 -0
  21. package/form-validation/index.ts +198 -0
  22. package/form-validation/index.umd.js +1 -0
  23. package/form-validation/readme.md +117 -0
  24. package/import-css/README.md +22 -0
  25. package/import-css/index.d.ts +1 -0
  26. package/import-css/index.js +7 -0
  27. package/import-css/index.ts +11 -0
  28. package/import-css/index.umd.js +1 -0
  29. package/import-html/README.md +18 -0
  30. package/import-html/index.d.ts +4 -0
  31. package/import-html/index.js +4 -0
  32. package/import-html/index.ts +4 -0
  33. package/import-html/index.umd.js +1 -0
  34. package/import-js/README.md +22 -0
  35. package/import-js/index.d.ts +5 -0
  36. package/import-js/index.js +7 -0
  37. package/import-js/index.ts +15 -0
  38. package/import-js/index.umd.js +1 -0
  39. package/is-touch/README.md +18 -0
  40. package/is-touch/index.d.ts +1 -0
  41. package/is-touch/index.js +4 -0
  42. package/is-touch/index.ts +4 -0
  43. package/is-touch/index.umd.js +1 -0
  44. package/is-visible/README.md +24 -0
  45. package/is-visible/index.d.ts +7 -0
  46. package/is-visible/index.js +11 -0
  47. package/is-visible/index.ts +20 -0
  48. package/is-visible/index.umd.js +1 -0
  49. package/lazyload-image/README.md +28 -0
  50. package/lazyload-image/index.d.ts +1 -0
  51. package/lazyload-image/index.js +235 -0
  52. package/lazyload-image/index.ts +3 -0
  53. package/lazyload-image/index.umd.js +1 -0
  54. package/messenger/README.md +109 -0
  55. package/messenger/index.d.ts +9 -0
  56. package/messenger/index.js +39 -0
  57. package/messenger/index.ts +38 -0
  58. package/messenger/index.umd.js +1 -0
  59. package/mfe/README.md +90 -0
  60. package/mfe/index.d.ts +11 -0
  61. package/mfe/index.js +99 -0
  62. package/mfe/index.ts +141 -0
  63. package/mfe/index.umd.js +1 -0
  64. package/outlet/README.md +46 -0
  65. package/outlet/index.d.ts +6 -0
  66. package/outlet/index.js +550 -0
  67. package/outlet/index.ts +101 -0
  68. package/outlet/index.umd.js +1 -0
  69. package/package.json +25 -0
  70. package/querystring/README.md +19 -0
  71. package/querystring/index.d.ts +1 -0
  72. package/querystring/index.js +9 -0
  73. package/querystring/index.ts +9 -0
  74. package/querystring/index.umd.js +1 -0
  75. package/router/README.md +23 -0
  76. package/router/index.d.ts +1 -0
  77. package/router/index.js +134 -0
  78. package/router/index.ts +3 -0
  79. package/router/index.umd.js +1 -0
  80. package/storage/README.md +34 -0
  81. package/storage/index.d.ts +12 -0
  82. package/storage/index.js +39 -0
  83. package/storage/index.ts +45 -0
  84. package/storage/index.umd.js +1 -0
  85. package/store/README.md +44 -0
  86. package/store/index.d.ts +1 -0
  87. package/store/index.js +50 -0
  88. package/store/index.ts +1 -0
  89. package/store/index.umd.js +1 -0
  90. package/third-party/README.md +44 -0
  91. package/third-party/index.d.ts +8 -0
  92. package/third-party/index.js +15 -0
  93. package/third-party/index.ts +30 -0
  94. package/third-party/index.umd.js +1 -0
  95. package/throttle/README.md +21 -0
  96. package/throttle/index.d.ts +1 -0
  97. package/throttle/index.js +9 -0
  98. package/throttle/index.ts +10 -0
  99. package/throttle/index.umd.js +1 -0
  100. package/tsconfig.json +14 -0
  101. package/vite-env.d.ts +1 -0
@@ -0,0 +1,19 @@
1
+ ## querystring
2
+ ```ts
3
+ querystring( variable: string ) : string
4
+ ```
5
+
6
+ Returns a query string value.
7
+
8
+
9
+ ### Usage
10
+
11
+ ```js
12
+ import { querystring } from 'jails.std/querystring'
13
+
14
+ // https://my-awesome-site.com?search=david
15
+ const { search } = querystring()
16
+ console.log( search ) // 'david'
17
+
18
+ ```
19
+
@@ -0,0 +1 @@
1
+ export declare const querystring: () => {};
@@ -0,0 +1,9 @@
1
+ const n = () => {
2
+ const r = new URLSearchParams(location.search), o = {};
3
+ for (const [a, e] of r)
4
+ o[a] = e;
5
+ return o;
6
+ };
7
+ export {
8
+ n as querystring
9
+ };
@@ -0,0 +1,9 @@
1
+
2
+ export const querystring = () => {
3
+ const params = new URLSearchParams( location.search )
4
+ const obj = {}
5
+ for(const [ key, value] of params ) {
6
+ obj[key] = value
7
+ }
8
+ return obj
9
+ }
@@ -0,0 +1 @@
1
+ (function(e,n){typeof exports=="object"&&typeof module!="undefined"?n(exports):typeof define=="function"&&define.amd?define(["exports"],n):(e=typeof globalThis!="undefined"?globalThis:e||self,n(e.querystring={}))})(this,(function(e){"use strict";const n=()=>{const o=new URLSearchParams(location.search),t={};for(const[i,s]of o)t[i]=s;return t};e.querystring=n,Object.defineProperty(e,Symbol.toStringTag,{value:"Module"})}));
@@ -0,0 +1,23 @@
1
+ # router
2
+
3
+ ```ts
4
+ Router( options?:GrapnelOptions ) : GrapnelInstance
5
+ ```
6
+
7
+ Grapnel, the smallest Javascript router with named parameters.
8
+
9
+ Documentation : https://github.com/baseprime/grapnel
10
+
11
+ ## Usage
12
+
13
+ ```js
14
+ import { Router } from 'jails.std/router'
15
+
16
+ const router = new Router()
17
+
18
+ // http://localhost:3000/#/home
19
+ // http://localhost:3000/#/about
20
+
21
+ router.get('/', (page) => console.log(page))
22
+
23
+ ```
@@ -0,0 +1 @@
1
+ export declare const Router: any;
@@ -0,0 +1,134 @@
1
+ function d(h) {
2
+ return h && h.__esModule && Object.prototype.hasOwnProperty.call(h, "default") ? h.default : h;
3
+ }
4
+ var v = { exports: {} }, S = v.exports, m;
5
+ function E() {
6
+ return m || (m = 1, (function(h, b) {
7
+ (function(n) {
8
+ function s(e) {
9
+ var t = this;
10
+ return this.events = {}, this.state = null, this.options = e || {}, this.options.env = this.options.env || (Object.keys(n).length === 0 && process && process.browser !== !0 ? "server" : "client"), this.options.mode = this.options.mode || (this.options.env !== "server" && this.options.pushState && n.history && n.history.pushState ? "pushState" : "hashchange"), this.version = "0.6.4", typeof n.addEventListener == "function" && (n.addEventListener("hashchange", function() {
11
+ t.trigger("hashchange");
12
+ }), n.addEventListener("popstate", function(r) {
13
+ if (t.state && t.state.previousState === null) return !1;
14
+ t.trigger("navigate");
15
+ })), this;
16
+ }
17
+ s.regexRoute = function(e, t, r, a) {
18
+ return e instanceof RegExp ? e : (e instanceof Array && (e = "(" + e.join("|") + ")"), e = e.concat(a ? "" : "/?").replace(/\/\(/g, "(?:/").replace(/\+/g, "__plus__").replace(/(\/)?(\.)?:(\w+)(?:(\(.*?\)))?(\?)?/g, function(i, o, l, g, u, f) {
19
+ return t.push({
20
+ name: g,
21
+ optional: !!f
22
+ }), o = o || "", "" + (f ? "" : o) + "(?:" + (f ? o : "") + (l || "") + (u || l && "([^/.]+?)" || "([^/]+?)") + ")" + (f || "");
23
+ }).replace(/([\/.])/g, "\\$1").replace(/__plus__/g, "(.+)").replace(/\*/g, "(.*)"), new RegExp("^" + e + "$", r ? "" : "i"));
24
+ }, s._forEach = function(e, t) {
25
+ return typeof Array.prototype.forEach == "function" ? Array.prototype.forEach.call(e, t) : function(r, a) {
26
+ for (var i = 0, o = this.length; i < o; ++i)
27
+ r.call(a, this[i], i, this);
28
+ }.call(e, t);
29
+ }, s.prototype.get = s.prototype.add = function(e) {
30
+ var t = this, r = Array.prototype.slice.call(arguments, 1, -1), a = Array.prototype.slice.call(arguments, -1)[0], i = new y(e), o = function() {
31
+ var u = i.parse(t.path());
32
+ if (u.match) {
33
+ var f = {
34
+ route: e,
35
+ params: u.params,
36
+ req: u,
37
+ regex: u.match
38
+ }, c = new p(t, f).enqueue(r.concat(a));
39
+ if (t.trigger("match", c, u), !c.runCallback) return t;
40
+ if (c.previousState = t.state, t.state = c, c.parent() && c.parent().propagateEvent === !1)
41
+ return c.propagateEvent = !1, t;
42
+ c.callback();
43
+ }
44
+ return t;
45
+ }, l = t.options.mode !== "pushState" && t.options.env !== "server" ? "hashchange" : "navigate";
46
+ return o().on(l, o);
47
+ }, s.prototype.trigger = function(e) {
48
+ var t = this, r = Array.prototype.slice.call(arguments, 1);
49
+ return this.events[e] && s._forEach(this.events[e], function(a) {
50
+ a.apply(t, r);
51
+ }), this;
52
+ }, s.prototype.on = s.prototype.bind = function(e, t) {
53
+ var r = this, a = e.split(" ");
54
+ return s._forEach(a, function(i) {
55
+ r.events[i] ? r.events[i].push(t) : r.events[i] = [t];
56
+ }), this;
57
+ }, s.prototype.once = function(e, t) {
58
+ var r = !1;
59
+ return this.on(e, function() {
60
+ return r ? !1 : (r = !0, t.apply(this, arguments), t = null, !0);
61
+ });
62
+ }, s.prototype.context = function(e) {
63
+ var t = this, r = Array.prototype.slice.call(arguments, 1);
64
+ return function() {
65
+ var a = arguments[0], i = arguments.length > 2 ? Array.prototype.slice.call(arguments, 1, -1) : [], o = Array.prototype.slice.call(arguments, -1)[0], l = e.slice(-1) !== "/" && a !== "/" && a !== "" ? e + "/" : e, g = a.substr(0, 1) !== "/" ? a : a.substr(1), u = l + g;
66
+ return t.add.apply(t, [u].concat(r).concat(i).concat([o]));
67
+ };
68
+ }, s.prototype.navigate = function(e) {
69
+ return this.path(e).trigger("navigate");
70
+ }, s.prototype.path = function(e) {
71
+ var t = this, r;
72
+ if (typeof e == "string")
73
+ return t.options.mode === "pushState" ? (r = t.options.root ? t.options.root + e : e, n.history.pushState({}, null, r)) : n.location ? n.location.hash = (t.options.hashBang ? "!" : "") + e : n._pathname = e || "", this;
74
+ if (typeof e == "undefined")
75
+ return t.options.mode === "pushState" ? r = n.location.pathname.replace(t.options.root, "") : t.options.mode !== "pushState" && n.location ? r = n.location.hash ? n.location.hash.split(t.options.hashBang ? "#!" : "#")[1] : "" : r = n._pathname || "", r;
76
+ if (e === !1)
77
+ return t.options.mode === "pushState" ? n.history.pushState({}, null, t.options.root || "/") : n.location && (n.location.hash = t.options.hashBang ? "!" : ""), t;
78
+ }, s.listen = function() {
79
+ var e, t;
80
+ return arguments[0] && arguments[1] ? (e = arguments[0], t = arguments[1]) : t = arguments[0], (function() {
81
+ for (var r in t)
82
+ this.add.call(this, r, t[r]);
83
+ return this;
84
+ }).call(new s(e || {}));
85
+ };
86
+ function p(e, t) {
87
+ this.stack = p.global.slice(0), this.router = e, this.runCallback = !0, this.callbackRan = !1, this.propagateEvent = !0, this.value = e.path();
88
+ for (var r in t)
89
+ this[r] = t[r];
90
+ return this;
91
+ }
92
+ function y(e) {
93
+ this.route = e, this.keys = [], this.regex = s.regexRoute(e, this.keys);
94
+ }
95
+ p.global = [], p.prototype.preventDefault = function() {
96
+ this.runCallback = !1;
97
+ }, p.prototype.stopPropagation = function() {
98
+ this.propagateEvent = !1;
99
+ }, p.prototype.parent = function() {
100
+ var e = !!(this.previousState && this.previousState.value && this.previousState.value == this.value);
101
+ return e ? this.previousState : !1;
102
+ }, p.prototype.callback = function() {
103
+ this.callbackRan = !0, this.timeStamp = Date.now(), this.next();
104
+ }, p.prototype.enqueue = function(e, t) {
105
+ for (var r = Array.isArray(e) ? t < e.length ? e.reverse() : e : [e]; r.length; )
106
+ this.stack.splice(t || this.stack.length + 1, 0, r.shift());
107
+ return this;
108
+ }, p.prototype.next = function() {
109
+ var e = this;
110
+ return this.stack.shift().call(this.router, this.req, this, function() {
111
+ e.next.call(e);
112
+ });
113
+ }, y.prototype.parse = function(e) {
114
+ var t = e.match(this.regex), r = this, a = {
115
+ params: {},
116
+ keys: this.keys,
117
+ matches: (t || []).slice(1),
118
+ match: t
119
+ };
120
+ return s._forEach(a.matches, function(i, o) {
121
+ var l = r.keys[o] && r.keys[o].name ? r.keys[o].name : o;
122
+ a.params[l] = i ? decodeURIComponent(i) : void 0;
123
+ }), a;
124
+ }, s.CallStack = p, s.Request = y, typeof n.define == "function" && !n.define.amd.grapnel ? n.define(function(e, t, r) {
125
+ return n.define.amd.grapnel = !0, s;
126
+ }) : h.exports = s;
127
+ }).call({}, typeof window == "object" ? window : S);
128
+ })(v)), v.exports;
129
+ }
130
+ var _ = E();
131
+ const w = /* @__PURE__ */ d(_), x = w;
132
+ export {
133
+ x as Router
134
+ };
@@ -0,0 +1,3 @@
1
+ import Grapnel from 'grapnel'
2
+
3
+ export const Router = Grapnel
@@ -0,0 +1 @@
1
+ (function(f,v){typeof exports=="object"&&typeof module!="undefined"?v(exports):typeof define=="function"&&define.amd?define(["exports"],v):(f=typeof globalThis!="undefined"?globalThis:f||self,v(f.router={}))})(this,(function(f){"use strict";function v(h){return h&&h.__esModule&&Object.prototype.hasOwnProperty.call(h,"default")?h.default:h}var y={exports:{}},b=y.exports,S;function E(){return S||(S=1,(function(h,k){(function(r){function s(e){var t=this;return this.events={},this.state=null,this.options=e||{},this.options.env=this.options.env||(Object.keys(r).length===0&&process&&process.browser!==!0?"server":"client"),this.options.mode=this.options.mode||(this.options.env!=="server"&&this.options.pushState&&r.history&&r.history.pushState?"pushState":"hashchange"),this.version="0.6.4",typeof r.addEventListener=="function"&&(r.addEventListener("hashchange",function(){t.trigger("hashchange")}),r.addEventListener("popstate",function(n){if(t.state&&t.state.previousState===null)return!1;t.trigger("navigate")})),this}s.regexRoute=function(e,t,n,a){return e instanceof RegExp?e:(e instanceof Array&&(e="("+e.join("|")+")"),e=e.concat(a?"":"/?").replace(/\/\(/g,"(?:/").replace(/\+/g,"__plus__").replace(/(\/)?(\.)?:(\w+)(?:(\(.*?\)))?(\?)?/g,function(i,o,l,d,u,g){return t.push({name:d,optional:!!g}),o=o||"",""+(g?"":o)+"(?:"+(g?o:"")+(l||"")+(u||l&&"([^/.]+?)"||"([^/]+?)")+")"+(g||"")}).replace(/([\/.])/g,"\\$1").replace(/__plus__/g,"(.+)").replace(/\*/g,"(.*)"),new RegExp("^"+e+"$",n?"":"i"))},s._forEach=function(e,t){return typeof Array.prototype.forEach=="function"?Array.prototype.forEach.call(e,t):function(n,a){for(var i=0,o=this.length;i<o;++i)n.call(a,this[i],i,this)}.call(e,t)},s.prototype.get=s.prototype.add=function(e){var t=this,n=Array.prototype.slice.call(arguments,1,-1),a=Array.prototype.slice.call(arguments,-1)[0],i=new m(e),o=function(){var u=i.parse(t.path());if(u.match){var g={route:e,params:u.params,req:u,regex:u.match},c=new p(t,g).enqueue(n.concat(a));if(t.trigger("match",c,u),!c.runCallback)return t;if(c.previousState=t.state,t.state=c,c.parent()&&c.parent().propagateEvent===!1)return c.propagateEvent=!1,t;c.callback()}return t},l=t.options.mode!=="pushState"&&t.options.env!=="server"?"hashchange":"navigate";return o().on(l,o)},s.prototype.trigger=function(e){var t=this,n=Array.prototype.slice.call(arguments,1);return this.events[e]&&s._forEach(this.events[e],function(a){a.apply(t,n)}),this},s.prototype.on=s.prototype.bind=function(e,t){var n=this,a=e.split(" ");return s._forEach(a,function(i){n.events[i]?n.events[i].push(t):n.events[i]=[t]}),this},s.prototype.once=function(e,t){var n=!1;return this.on(e,function(){return n?!1:(n=!0,t.apply(this,arguments),t=null,!0)})},s.prototype.context=function(e){var t=this,n=Array.prototype.slice.call(arguments,1);return function(){var a=arguments[0],i=arguments.length>2?Array.prototype.slice.call(arguments,1,-1):[],o=Array.prototype.slice.call(arguments,-1)[0],l=e.slice(-1)!=="/"&&a!=="/"&&a!==""?e+"/":e,d=a.substr(0,1)!=="/"?a:a.substr(1),u=l+d;return t.add.apply(t,[u].concat(n).concat(i).concat([o]))}},s.prototype.navigate=function(e){return this.path(e).trigger("navigate")},s.prototype.path=function(e){var t=this,n;if(typeof e=="string")return t.options.mode==="pushState"?(n=t.options.root?t.options.root+e:e,r.history.pushState({},null,n)):r.location?r.location.hash=(t.options.hashBang?"!":"")+e:r._pathname=e||"",this;if(typeof e=="undefined")return t.options.mode==="pushState"?n=r.location.pathname.replace(t.options.root,""):t.options.mode!=="pushState"&&r.location?n=r.location.hash?r.location.hash.split(t.options.hashBang?"#!":"#")[1]:"":n=r._pathname||"",n;if(e===!1)return t.options.mode==="pushState"?r.history.pushState({},null,t.options.root||"/"):r.location&&(r.location.hash=t.options.hashBang?"!":""),t},s.listen=function(){var e,t;return arguments[0]&&arguments[1]?(e=arguments[0],t=arguments[1]):t=arguments[0],(function(){for(var n in t)this.add.call(this,n,t[n]);return this}).call(new s(e||{}))};function p(e,t){this.stack=p.global.slice(0),this.router=e,this.runCallback=!0,this.callbackRan=!1,this.propagateEvent=!0,this.value=e.path();for(var n in t)this[n]=t[n];return this}function m(e){this.route=e,this.keys=[],this.regex=s.regexRoute(e,this.keys)}p.global=[],p.prototype.preventDefault=function(){this.runCallback=!1},p.prototype.stopPropagation=function(){this.propagateEvent=!1},p.prototype.parent=function(){var e=!!(this.previousState&&this.previousState.value&&this.previousState.value==this.value);return e?this.previousState:!1},p.prototype.callback=function(){this.callbackRan=!0,this.timeStamp=Date.now(),this.next()},p.prototype.enqueue=function(e,t){for(var n=Array.isArray(e)?t<e.length?e.reverse():e:[e];n.length;)this.stack.splice(t||this.stack.length+1,0,n.shift());return this},p.prototype.next=function(){var e=this;return this.stack.shift().call(this.router,this.req,this,function(){e.next.call(e)})},m.prototype.parse=function(e){var t=e.match(this.regex),n=this,a={params:{},keys:this.keys,matches:(t||[]).slice(1),match:t};return s._forEach(a.matches,function(i,o){var l=n.keys[o]&&n.keys[o].name?n.keys[o].name:o;a.params[l]=i?decodeURIComponent(i):void 0}),a},s.CallStack=p,s.Request=m,typeof r.define=="function"&&!r.define.amd.grapnel?r.define(function(e,t,n){return r.define.amd.grapnel=!0,s}):h.exports=s}).call({},typeof window=="object"?window:b)})(y)),y.exports}var _=E();const w=v(_);f.Router=w,Object.defineProperty(f,Symbol.toStringTag,{value:"Module"})}));
@@ -0,0 +1,34 @@
1
+ # storage
2
+
3
+ The storage is a wrapper for the localStorage and sessionStorage global objects.
4
+
5
+
6
+ ## Usage
7
+
8
+ ### For local storage
9
+
10
+ ```js
11
+ import { storage } from 'jails.std/storage'
12
+
13
+ //Save data
14
+ storage.local.set('item', { my :'item' }); // Save data and return { my:'item' }
15
+
16
+ //Get data
17
+ storage.local.get('item'); // return { my:'item' }
18
+
19
+ //Delete data
20
+ storage.local.remove('item'); // Removes and return { my:'item' }
21
+ ```
22
+
23
+ ### For session storage
24
+
25
+ ```js
26
+ //Save data
27
+ storage.session.set('item', { my :'item' }); // Save data and return { my:'item' }
28
+
29
+ //Get data
30
+ storage.session.get('item'); // return { my:'item' }
31
+
32
+ //Delete data
33
+ storage.session.remove('item'); // Removes and return { my:'item' }
34
+ ```
@@ -0,0 +1,12 @@
1
+ export declare const storage: {
2
+ local: {
3
+ set(name: string, data: any): any;
4
+ get(name: string): any;
5
+ remove(name: string): any;
6
+ };
7
+ session: {
8
+ set(name: string, data: any): any;
9
+ get(name: string): any;
10
+ remove(name: string): any;
11
+ };
12
+ };
@@ -0,0 +1,39 @@
1
+ const s = {
2
+ local: {
3
+ set(t, e) {
4
+ return localStorage.setItem(t, JSON.stringify(e)), e;
5
+ },
6
+ get(t) {
7
+ let e = localStorage.getItem(t);
8
+ try {
9
+ e = JSON.parse(e);
10
+ } catch (r) {
11
+ }
12
+ return null;
13
+ },
14
+ remove(t) {
15
+ let e = this.get(t);
16
+ return localStorage.removeItem(t), e;
17
+ }
18
+ },
19
+ session: {
20
+ set(t, e) {
21
+ return sessionStorage.setItem(t, JSON.stringify(e)), e;
22
+ },
23
+ get(t) {
24
+ let e = sessionStorage.getItem(t);
25
+ try {
26
+ e = JSON.parse(e);
27
+ } catch (r) {
28
+ }
29
+ return e;
30
+ },
31
+ remove(t) {
32
+ let e = this.get(t);
33
+ return sessionStorage.removeItem(t), e;
34
+ }
35
+ }
36
+ };
37
+ export {
38
+ s as storage
39
+ };
@@ -0,0 +1,45 @@
1
+
2
+ export const storage = {
3
+
4
+ local : {
5
+ set( name: string, data ){
6
+ localStorage.setItem( name, JSON.stringify( data ) )
7
+ return data
8
+ },
9
+
10
+ get( name: string ): any {
11
+ let value = localStorage.getItem( name )
12
+ // This way I can distinguish what is a string and what is an object serialized.
13
+ try{ value = JSON.parse( value ) }
14
+ catch(e){ /* Noop */}
15
+ return null
16
+ },
17
+
18
+ remove( name: string ){
19
+ let data = this.get( name )
20
+ localStorage.removeItem( name )
21
+ return data
22
+ }
23
+ },
24
+ session : {
25
+
26
+ set( name: string, data ){
27
+ sessionStorage.setItem( name, JSON.stringify( data ) )
28
+ return data
29
+ },
30
+
31
+ get( name: string ): any {
32
+ let value = sessionStorage.getItem( name )
33
+ // This way I can distinguish what is a string and what is an object serialized.
34
+ try{ value = JSON.parse( value ) }
35
+ catch(e){ /* Noop */}
36
+ return value
37
+ },
38
+
39
+ remove( name: string ){
40
+ let data = this.get( name )
41
+ sessionStorage.removeItem( name )
42
+ return data
43
+ }
44
+ }
45
+ }
@@ -0,0 +1 @@
1
+ (function(o,r){typeof exports=="object"&&typeof module!="undefined"?r(exports):typeof define=="function"&&define.amd?define(["exports"],r):(o=typeof globalThis!="undefined"?globalThis:o||self,r(o.storage={}))})(this,(function(o){"use strict";const r={local:{set(t,e){return localStorage.setItem(t,JSON.stringify(e)),e},get(t){let e=localStorage.getItem(t);try{e=JSON.parse(e)}catch(s){}return null},remove(t){let e=this.get(t);return localStorage.removeItem(t),e}},session:{set(t,e){return sessionStorage.setItem(t,JSON.stringify(e)),e},get(t){let e=sessionStorage.getItem(t);try{e=JSON.parse(e)}catch(s){}return e},remove(t){let e=this.get(t);return sessionStorage.removeItem(t),e}}};o.storage=r,Object.defineProperty(o,Symbol.toStringTag,{value:"Module"})}));
@@ -0,0 +1,44 @@
1
+ # store
2
+
3
+ Oni, A state machine Store that ressembles Redux but simpler.
4
+ <br />
5
+ Documentation: [Oni](https://github.com/Javiani/Oni)
6
+
7
+ ```ts
8
+ Store( initialState: Object , actions: Object )
9
+ ```
10
+
11
+
12
+ ## Usage
13
+
14
+ ```js
15
+ import { Store } from 'jails.std/store'
16
+
17
+ const initialState = {
18
+ loading: false,
19
+ items: []
20
+ }
21
+
22
+ export const store = Store( initialState, {
23
+
24
+ //@Actions
25
+
26
+ FETCH: (state, payload, { dispatch }) => {
27
+
28
+ fetch('/some/async/service')
29
+ .then( data => dispatch('LOADED', { data }))
30
+
31
+ // Update only the desired property
32
+ return {
33
+ loading: true
34
+ }
35
+ },
36
+
37
+ LOADED: (state, { data }) => {
38
+ return {
39
+ items: data,
40
+ loading: false
41
+ }
42
+ }
43
+ })
44
+ ```
@@ -0,0 +1 @@
1
+ export { default as Store } from '@javiani/onijs';
package/store/index.js ADDED
@@ -0,0 +1,50 @@
1
+ function S(e, d) {
2
+ let r = [];
3
+ const l = /* @__PURE__ */ new Set(), c = g(e), p = () => c, s = (a) => {
4
+ if (a.call)
5
+ return l.add(a), () => {
6
+ l.delete(a);
7
+ };
8
+ {
9
+ const n = (t, { action: o, payload: i }) => {
10
+ o in a && a[o].call(null, t, { action: o, payload: i });
11
+ };
12
+ return l.add(n), () => {
13
+ l.delete(n);
14
+ };
15
+ }
16
+ }, u = (a, n) => (r.push({ action: a, payload: n }), new Promise(
17
+ (t) => f({ action: a, payload: n }, t)
18
+ )), y = (a) => new Promise((n) => {
19
+ s((t, { action: o, payload: i }) => {
20
+ o in a && w((h) => {
21
+ a[o].call(null, t, { action: o, payload: i }), n(t);
22
+ });
23
+ });
24
+ }), f = ({ action: a, payload: n = {} }, t) => {
25
+ r.forEach(({ action: o, payload: i = {} }) => {
26
+ if (!(o in d))
27
+ console.log(`[Oni] Error -> No action [ ${o} ] found.`);
28
+ else {
29
+ const h = d[o].call(null, c, i, {
30
+ getState: p,
31
+ subscribe: s,
32
+ dispatch: u,
33
+ patternMatch: y
34
+ });
35
+ Object.assign(c, h);
36
+ }
37
+ }), r.length && (l.forEach((o) => o(c, { action: a, payload: n })), r = []), t(c);
38
+ };
39
+ return {
40
+ getState: p,
41
+ subscribe: s,
42
+ dispatch: u,
43
+ patternMatch: y,
44
+ destroy: () => l.clear()
45
+ };
46
+ }
47
+ const g = (e) => JSON.parse(JSON.stringify(e)), w = typeof window > "u" ? (e) => e() : (e) => requestAnimationFrame(e);
48
+ export {
49
+ S as Store
50
+ };
package/store/index.ts ADDED
@@ -0,0 +1 @@
1
+ export { default as Store } from '@javiani/onijs'
@@ -0,0 +1 @@
1
+ (function(i,c){typeof exports=="object"&&typeof module!="undefined"?c(exports):typeof define=="function"&&define.amd?define(["exports"],c):(i=typeof globalThis!="undefined"?globalThis:i||self,c(i.store={}))})(this,(function(i){"use strict";function c(a,u){let s=[];const l=new Set,d=b(a),f=()=>d,p=e=>{if(e.call)return l.add(e),()=>{l.delete(e)};{const o=(t,{action:n,payload:r})=>{n in e&&e[n].call(null,t,{action:n,payload:r})};return l.add(o),()=>{l.delete(o)}}},y=(e,o)=>(s.push({action:e,payload:o}),new Promise(t=>S({action:e,payload:o},t))),h=e=>new Promise(o=>{p((t,{action:n,payload:r})=>{n in e&&m(g=>{e[n].call(null,t,{action:n,payload:r}),o(t)})})}),S=({action:e,payload:o={}},t)=>{s.forEach(({action:n,payload:r={}})=>{if(!(n in u))console.log(`[Oni] Error -> No action [ ${n} ] found.`);else{const g=u[n].call(null,d,r,{getState:f,subscribe:p,dispatch:y,patternMatch:h});Object.assign(d,g)}}),s.length&&(l.forEach(n=>n(d,{action:e,payload:o})),s=[]),t(d)};return{getState:f,subscribe:p,dispatch:y,patternMatch:h,destroy:()=>l.clear()}}const b=a=>JSON.parse(JSON.stringify(a)),m=typeof window>"u"?a=>a():a=>requestAnimationFrame(a);i.Store=c,Object.defineProperty(i,Symbol.toStringTag,{value:"Module"})}));
@@ -0,0 +1,44 @@
1
+ # third-party
2
+
3
+ ```ts
4
+ thirdParty( name: string ): Promise<HTMLScriptElement>
5
+ ```
6
+
7
+ A package that has some utilities functions to manage third-party cdn scripts like: **analytics**, **appDynamics**, etc.
8
+ Enables the developer to run third-party scripts at a convenient time, integrating those scripts into the app flow.
9
+
10
+ <br />
11
+
12
+ ### Usage
13
+ Set your third-party snippet anywhere in your Layout our html page.
14
+ That code will not be executed on page load due to its `type="text/third-party"` property.
15
+
16
+ ```html
17
+ <script data-name="analytics" src="https://www.googletagmanager.com/gtag/js?id=G-XXXXXXXXX" type="text/third-party">
18
+ window.dataLayer = window.dataLayer || [];
19
+ function gtag(){dataLayer.push(arguments);}
20
+ gtag('js', new Date());
21
+ gtag('config', 'G-XXXXXXXXX');
22
+ </script>
23
+ ```
24
+ <br />
25
+ <br />
26
+
27
+ The `thirdParty` will execute the text script code and then will load the cdn library if there's any `src` property setted.
28
+ This way you can have the control of third party code execution and when it should be executed inside your application flow.
29
+
30
+ ```js
31
+ import { thirdParty } from 'jails.std/third-party'
32
+
33
+ export const analytics = thirdParty('analytics')
34
+
35
+ function main() {
36
+
37
+ analytics.then(() => {
38
+ // Now you know that window.dataLayer is available
39
+ console.log( window.dataLayer )
40
+ })
41
+ }
42
+ ```
43
+
44
+ The string arguments have to match with the `data-name` attribute in the `script` tag. That way you can have many other third-party scripts and reference each of them separately.
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Gets an <script type="text/third-party" data-name="analytics"> element by name and
3
+ * returns a Promise that will be resolved after script load and execute inline text script.
4
+ * @usage
5
+ * const analytics = thirdParty('analytics')
6
+ analytics.then( _ => window.gtag('event', 'buy_click', {...})
7
+ */
8
+ export declare const thirdParty: (name: string) => Promise<HTMLScriptElement>;
@@ -0,0 +1,15 @@
1
+ const thirdParty = (name) => new Promise((resolve, reject) => {
2
+ const script = document.querySelector(`script[data-name=${name}]`);
3
+ if (!script)
4
+ reject({ error: "ThirdPartyScriptError", message: `There is no script with data-name: ${name} in the document.` });
5
+ else if (script.src) {
6
+ const e = document.createElement("script");
7
+ e.onload = () => {
8
+ new Function(script.text)(), resolve(e);
9
+ }, e.src = script.src, document.head.appendChild(e);
10
+ } else
11
+ eval(script.text), resolve(script);
12
+ });
13
+ export {
14
+ thirdParty
15
+ };
@@ -0,0 +1,30 @@
1
+ /**
2
+ * Gets an <script type="text/third-party" data-name="analytics"> element by name and
3
+ * returns a Promise that will be resolved after script load and execute inline text script.
4
+ * @usage
5
+ * const analytics = thirdParty('analytics')
6
+ analytics.then( _ => window.gtag('event', 'buy_click', {...})
7
+ */
8
+
9
+ export const thirdParty = ( name:string ) : Promise<HTMLScriptElement> => {
10
+
11
+ return new Promise((resolve, reject) => {
12
+ const script = document.querySelector<HTMLScriptElement>(`script[data-name=${name}]`)
13
+ if (!script) {
14
+ reject({ error: 'ThirdPartyScriptError', message: `There is no script with data-name: ${name} in the document.` })
15
+ } else {
16
+ if( script.src ) {
17
+ const newscript = document.createElement('script')
18
+ newscript.onload = () => {
19
+ ;(new Function(script.text))()
20
+ resolve( newscript )
21
+ }
22
+ newscript.src = script.src
23
+ document.head.appendChild(newscript)
24
+ }else {
25
+ eval(script.text)
26
+ resolve(script)
27
+ }
28
+ }
29
+ })
30
+ }
@@ -0,0 +1 @@
1
+ (function(e,t){typeof exports=="object"&&typeof module!="undefined"?t(exports):typeof define=="function"&&define.amd?define(["exports"],t):(e=typeof globalThis!="undefined"?globalThis:e||self,t(e["third-party"]={}))})(this,(function(exports){"use strict";const thirdParty=name=>new Promise((resolve,reject)=>{const script=document.querySelector(`script[data-name=${name}]`);if(!script)reject({error:"ThirdPartyScriptError",message:`There is no script with data-name: ${name} in the document.`});else if(script.src){const e=document.createElement("script");e.onload=()=>{new Function(script.text)(),resolve(e)},e.src=script.src,document.head.appendChild(e)}else eval(script.text),resolve(script)});exports.thirdParty=thirdParty,Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"})}));
@@ -0,0 +1,21 @@
1
+ ## throttle
2
+ ```ts
3
+ throttle( fn: Function, timeInterval? = 100 )
4
+ ```
5
+
6
+ Limits a function's execution to at most once per specified time interval.
7
+
8
+
9
+ ### Usage
10
+
11
+ ```js
12
+ import { throttle } from 'jails.std/throttle'
13
+
14
+ const onscroll = throttle(() => {
15
+ console.log('throttling scroll')
16
+ })
17
+
18
+ window.addEventListener('scroll', onscroll)
19
+
20
+ ```
21
+
@@ -0,0 +1 @@
1
+ export declare const throttle: (fn: Function, wait?: number) => () => void;
@@ -0,0 +1,9 @@
1
+ const n = (e, o = 100) => {
2
+ let t = Date.now();
3
+ return () => {
4
+ t + o - Date.now() < 0 && (e(), t = Date.now());
5
+ };
6
+ };
7
+ export {
8
+ n as throttle
9
+ };
@@ -0,0 +1,10 @@
1
+
2
+ export const throttle = (fn:Function, wait:number = 100) => {
3
+ let time = Date.now()
4
+ return () => {
5
+ if ((time + wait - Date.now()) < 0) {
6
+ fn()
7
+ time = Date.now()
8
+ }
9
+ }
10
+ }
@@ -0,0 +1 @@
1
+ (function(e,t){typeof exports=="object"&&typeof module!="undefined"?t(exports):typeof define=="function"&&define.amd?define(["exports"],t):(e=typeof globalThis!="undefined"?globalThis:e||self,t(e.throttle={}))})(this,(function(e){"use strict";const t=(o,i=100)=>{let n=Date.now();return()=>{n+i-Date.now()<0&&(o(),n=Date.now())}};e.throttle=t,Object.defineProperty(e,Symbol.toStringTag,{value:"Module"})}));
package/tsconfig.json ADDED
@@ -0,0 +1,14 @@
1
+ {
2
+ "compilerOptions": {
3
+ "rootDir": "./",
4
+ "target": "ESNext",
5
+ "moduleResolution": "node",
6
+ "allowImportingTsExtensions": true,
7
+ "resolveJsonModule": true,
8
+ "isolatedModules": true,
9
+ "esModuleInterop": true,
10
+ "declaration": true,
11
+ "emitDeclarationOnly": true,
12
+ "strict": false
13
+ }
14
+ }
package/vite-env.d.ts ADDED
@@ -0,0 +1 @@
1
+ /// <reference types="vite/client" />