jetr 0.4.6 → 0.6.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 (3) hide show
  1. package/index.js +4 -4
  2. package/license.txt +15 -0
  3. package/package.json +4 -3
package/index.js CHANGED
@@ -1,4 +1,4 @@
1
- function h(a){var b=0;return function(){return b<a.length?{done:!1,value:a[b++]}:{done:!0}}}function k(){var a=l(m()),b="undefined"!=typeof Symbol&&Symbol.iterator&&a[Symbol.iterator];return b?b.call(a):{next:h(a)}}var __jete_=require("jete"),n=__jete_.useEffect,l=__jete_.useState,q=[];function r(){q.forEach(function(a){return a()})}function m(){return{pathname:window.location.pathname,search:window.location.search,hash:window.location.hash.split("?")[0]}}
2
- function t(){function a(){g(m())}var b=k(),c=b.next().value,d=c.pathname,f=c.search;c=c.hash;var g=b.next().value;n(function(){q.push(a);window.addEventListener("popstate",a);return function(){var e=q.indexOf(a);-1<e&&q.splice(e,1);window.removeEventListener("popstate",a)}},[]);return{hash:c,pathname:d,push:function(e){window.history.pushState(null,null,e);r()},replace:function(e){window.history.replaceState(null,null,e);r()},search:f}}
3
- function u(a){var b=t(),c=b.pathname;b=b.hash;var d=[];a=a.replace(/:(\w+)/g,function(f,g){d.push(g);return"([^/]+)"});return{match:(c+b).match(new RegExp("^"+a)),keys:d}}
4
- module.exports={default:function(a){var b=a||{};a=b.children;b=u(void 0===b.path?"":b.path);var c=b.match,d=b.keys;return c&&Array.isArray(a)?a.map(function(f){if(f.props){var g={};d.forEach(function(e,p){c.length>p&&(g[e]=c[p+1])});f.updateProps(g)}return f}):c?a:[]},route:function(a){return function(b){return function(c){var d=u(a),f=d.match;d=d.keys;return f?(d.forEach(function(g,e){f.length>e&&(c[g]=f[e+1])}),b(c)):null}}},useLocation:t};
1
+ 'use strict';const g=require("jete"),h=g.jsx,k=g.createContext,l=g.useContext,m=g.useEffect,n=g.useState,p=[],v=k(u());function w(){p.forEach(a=>void a())}function u(){return{hash:window.location.hash.split("?")[0],pathname:window.location.pathname,search:window.location.search}}function x(){const [{hash:a,pathname:c,search:b},f]=n(u()),e=()=>{f(u())};m(()=>{p.push(e);return()=>{const d=p.indexOf(e);-1<d&&p.splice(d,1)}},[]);return{hash:a,pathname:c,search:b}}
2
+ function y(a,c,b){b&&(c="^"+c+"$");const f=[];c=c.replace(/:(\w+)/g,(e,d)=>{f.push(d);return"([^/]+)"});return{match:a.match(new RegExp(c)),keys:f}}function z(a,c){return a.map(b=>{b.props&&b.updateProps(c);return b})}
3
+ module.exports={Route:function(a){const {exact:c=!1,withSwitch:b={},path:f="",children:e}=a||{};a=l(v);if(null!==b&&"object"===typeof b&&b.break)return null;const {match:d,keys:q}=y(a,f,c),r={};d&&q&&(q.forEach((A,t)=>{d.length>t&&(r[A]=d[t+1])}),null!==b&&"object"===typeof b&&(b.break=!0));return d&&e&&Array.isArray(e)?z(e,r):d?e:null},Router:function(a){({children:a}=a||{});const {hash:c,pathname:b}=x();return h(v.Provider,{value:b+c},[a])},Switch:function(a){({children:a}=a||{});const c={withSwitch:{break:!1}};
4
+ return a&&Array.isArray(a)?z(a,c):a},useHistory:function(){return{back:()=>{window.history.go(-1);w()},forward:()=>{window.history.go(1);w()},push:a=>{window.history.pushState(null,null,a);w()},replace:a=>{window.history.replaceState(null,null,a);w()}}},useLocation:x};
package/license.txt ADDED
@@ -0,0 +1,15 @@
1
+ License
2
+
3
+ Copyright © 2020-2023 by Oleksandr Krayilo
4
+
5
+ Permission to use, copy, modify, and/or distribute this software for any
6
+ purpose with or without fee is hereby granted, provided that the above
7
+ copyright notice and this permission notice appear in all copies.
8
+
9
+ THE SOFTWARE IS PROVIDED “AS IS” AND AUTHORS DISCLAIM ALL WARRANTIES WITH
10
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
11
+ AND FITNESS. IN NO EVENT SHALL AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
12
+ SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
13
+ RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
14
+ NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE
15
+ USE OR PERFORMANCE OF THIS SOFTWARE.
package/package.json CHANGED
@@ -1,17 +1,18 @@
1
1
  {
2
2
  "name": "jetr",
3
- "version": "0.4.6",
3
+ "version": "0.6.0",
4
4
  "description": "Jet.js Router.",
5
5
  "main": "index.js",
6
6
  "scripts": {
7
7
  "test": "echo \"Error: no test specified\" && exit 1"
8
8
  },
9
9
  "files": [
10
- "index.js"
10
+ "index.js",
11
+ "license.txt"
11
12
  ],
12
13
  "author": "Oleksandr Krayilo",
13
14
  "license": "ISC",
14
15
  "dependencies": {
15
- "jete": "^0.9.1"
16
+ "jete": "^0.10.0"
16
17
  }
17
18
  }