space-router 0.9.0 → 0.9.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/CHANGELOG.md CHANGED
@@ -1,3 +1,11 @@
1
+ ## 0.9.2
2
+
3
+ - Upgrade all depedencies.
4
+
5
+ ## 0.9.1
6
+
7
+ - Revert to commonjs (remove `type: "module"`) to keep support for cjs in node and esm in browsers.
8
+
1
9
  ## 0.9.0
2
10
 
3
11
  - Upgrade all dependencies.
@@ -9,7 +9,27 @@ Object.defineProperty(exports, "createHistory", {
9
9
  }
10
10
  });
11
11
  function createHistory(options) {
12
- var listen = function listen(onChange) {
12
+ var sync = options.sync;
13
+ var mode = options.mode;
14
+ var raf;
15
+ var onPop;
16
+ var memory = [];
17
+ var off;
18
+ var destroyed = false;
19
+ if (typeof window === "undefined") {
20
+ mode = "memory";
21
+ raf = sync ? function(cb) {
22
+ return cb();
23
+ } : global.setImmediate;
24
+ } else {
25
+ raf = sync ? function(cb) {
26
+ return cb();
27
+ } : requestAnimationFrame;
28
+ if (mode === "history" && !history.pushState) {
29
+ mode = "hash";
30
+ }
31
+ }
32
+ function listen(onChange) {
13
33
  onPop = function() {
14
34
  return onChange(getUrl());
15
35
  };
@@ -21,8 +41,18 @@ function createHistory(options) {
21
41
  destroyed = true;
22
42
  off && off();
23
43
  };
44
+ }
45
+ return {
46
+ listen: listen,
47
+ getUrl: getUrl,
48
+ push: function(url) {
49
+ go(url);
50
+ },
51
+ replace: function(url) {
52
+ go(url, true);
53
+ }
24
54
  };
25
- var go = function go(url, replace) {
55
+ function go(url, replace) {
26
56
  if (destroyed) return;
27
57
  url = url.replace(/^\/?#?\/?/, "/").replace(/\/$/, "") || "/";
28
58
  if (mode === "history") {
@@ -34,8 +64,8 @@ function createHistory(options) {
34
64
  replace ? memory[memory.length - 1] = url : memory.push(url);
35
65
  raf(onPop);
36
66
  }
37
- };
38
- var getUrl = function getUrl() {
67
+ }
68
+ function getUrl() {
39
69
  if (mode === "memory") {
40
70
  return memory[memory.length - 1];
41
71
  }
@@ -50,43 +80,13 @@ function createHistory(options) {
50
80
  }
51
81
  return url;
52
82
  }
53
- };
54
- var getHash = // Gets the true hash value. Cannot use location.hash directly due to bug
83
+ }
84
+ // Gets the true hash value. Cannot use location.hash directly due to bug
55
85
  // in Firefox where location.hash will always be decoded.
56
86
  function getHash() {
57
87
  var match = location.href.match(/#(.*)$/);
58
88
  return match ? match[1].replace("#", "") : "";
59
- };
60
- var sync = options.sync;
61
- var mode = options.mode;
62
- var raf;
63
- var onPop;
64
- var memory = [];
65
- var off;
66
- var destroyed = false;
67
- if (typeof window === "undefined") {
68
- mode = "memory";
69
- raf = sync ? function(cb) {
70
- return cb();
71
- } : global.setImmediate;
72
- } else {
73
- raf = sync ? function(cb) {
74
- return cb();
75
- } : requestAnimationFrame;
76
- if (mode === "history" && !history.pushState) {
77
- mode = "hash";
78
- }
79
89
  }
80
- return {
81
- listen: listen,
82
- getUrl: getUrl,
83
- push: function(url) {
84
- go(url);
85
- },
86
- replace: function(url) {
87
- go(url, true);
88
- }
89
- };
90
90
  }
91
91
  function on(el, type, fn) {
92
92
  el.addEventListener(type, fn, false);
package/dist/cjs/index.js CHANGED
@@ -9,19 +9,19 @@ function _export(target, all) {
9
9
  });
10
10
  }
11
11
  _export(exports, {
12
+ createHistory: function() {
13
+ return _history.createHistory;
14
+ },
12
15
  createRouter: function() {
13
16
  return _router.createRouter;
14
17
  },
15
18
  merge: function() {
16
19
  return _router.merge;
17
20
  },
18
- createHistory: function() {
19
- return _history.createHistory;
20
- },
21
21
  qs: function() {
22
22
  return _qs.qs;
23
23
  }
24
24
  });
25
- var _router = require("./router.js");
26
- var _history = require("./history.js");
27
- var _qs = require("./qs.js");
25
+ var _router = require("./router");
26
+ var _history = require("./history");
27
+ var _qs = require("./qs");
@@ -19,9 +19,9 @@ _export(exports, {
19
19
  return merge;
20
20
  }
21
21
  });
22
- var _match = require("./match.js");
23
- var _history = require("./history.js");
24
- var _qs = require("./qs.js");
22
+ var _match = require("./match");
23
+ var _history = require("./history");
24
+ var _qs = require("./qs");
25
25
  function _define_property(obj, key, value) {
26
26
  if (key in obj) {
27
27
  Object.defineProperty(obj, key, {
@@ -1,5 +1,25 @@
1
1
  export function createHistory(options) {
2
- var listen = function listen(onChange) {
2
+ var sync = options.sync;
3
+ var mode = options.mode;
4
+ var raf;
5
+ var onPop;
6
+ var memory = [];
7
+ var off;
8
+ var destroyed = false;
9
+ if (typeof window === "undefined") {
10
+ mode = "memory";
11
+ raf = sync ? function(cb) {
12
+ return cb();
13
+ } : global.setImmediate;
14
+ } else {
15
+ raf = sync ? function(cb) {
16
+ return cb();
17
+ } : requestAnimationFrame;
18
+ if (mode === "history" && !history.pushState) {
19
+ mode = "hash";
20
+ }
21
+ }
22
+ function listen(onChange) {
3
23
  onPop = function() {
4
24
  return onChange(getUrl());
5
25
  };
@@ -11,8 +31,18 @@ export function createHistory(options) {
11
31
  destroyed = true;
12
32
  off && off();
13
33
  };
34
+ }
35
+ return {
36
+ listen: listen,
37
+ getUrl: getUrl,
38
+ push: function push(url) {
39
+ go(url);
40
+ },
41
+ replace: function replace(url) {
42
+ go(url, true);
43
+ }
14
44
  };
15
- var go = function go(url, replace) {
45
+ function go(url, replace) {
16
46
  if (destroyed) return;
17
47
  url = url.replace(/^\/?#?\/?/, "/").replace(/\/$/, "") || "/";
18
48
  if (mode === "history") {
@@ -24,8 +54,8 @@ export function createHistory(options) {
24
54
  replace ? memory[memory.length - 1] = url : memory.push(url);
25
55
  raf(onPop);
26
56
  }
27
- };
28
- var getUrl = function getUrl() {
57
+ }
58
+ function getUrl() {
29
59
  if (mode === "memory") {
30
60
  return memory[memory.length - 1];
31
61
  }
@@ -40,43 +70,13 @@ export function createHistory(options) {
40
70
  }
41
71
  return url;
42
72
  }
43
- };
44
- var getHash = // Gets the true hash value. Cannot use location.hash directly due to bug
73
+ }
74
+ // Gets the true hash value. Cannot use location.hash directly due to bug
45
75
  // in Firefox where location.hash will always be decoded.
46
76
  function getHash() {
47
77
  var match = location.href.match(/#(.*)$/);
48
78
  return match ? match[1].replace("#", "") : "";
49
- };
50
- var sync = options.sync;
51
- var mode = options.mode;
52
- var raf;
53
- var onPop;
54
- var memory = [];
55
- var off;
56
- var destroyed = false;
57
- if (typeof window === "undefined") {
58
- mode = "memory";
59
- raf = sync ? function(cb) {
60
- return cb();
61
- } : global.setImmediate;
62
- } else {
63
- raf = sync ? function(cb) {
64
- return cb();
65
- } : requestAnimationFrame;
66
- if (mode === "history" && !history.pushState) {
67
- mode = "hash";
68
- }
69
79
  }
70
- return {
71
- listen: listen,
72
- getUrl: getUrl,
73
- push: function push(url) {
74
- go(url);
75
- },
76
- replace: function replace(url) {
77
- go(url, true);
78
- }
79
- };
80
80
  }
81
81
  function on(el, type, fn) {
82
82
  el.addEventListener(type, fn, false);
package/dist/esm/index.js CHANGED
@@ -1,3 +1,3 @@
1
- export { createRouter, merge } from "./router.js";
2
- export { createHistory } from "./history.js";
3
- export { qs } from "./qs.js";
1
+ export { createRouter, merge } from "./router";
2
+ export { createHistory } from "./history";
3
+ export { qs } from "./qs";
@@ -77,9 +77,9 @@ function _object_without_properties_loose(source, excluded) {
77
77
  }
78
78
  return target;
79
79
  }
80
- import { match as findMatch } from "./match.js";
81
- import { createHistory } from "./history.js";
82
- import { qs as defaultQs } from "./qs.js";
80
+ import { match as findMatch } from "./match";
81
+ import { createHistory } from "./history";
82
+ import { qs as defaultQs } from "./qs";
83
83
  export function createRouter() {
84
84
  var options = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
85
85
  var history = null;
package/package.json CHANGED
@@ -1,10 +1,9 @@
1
1
  {
2
2
  "name": "space-router",
3
3
  "description": "All the routing essentials.",
4
- "version": "0.9.0",
4
+ "version": "0.9.2",
5
5
  "main": "dist/cjs",
6
6
  "module": "dist/esm",
7
- "type": "module",
8
7
  "license": "ICS",
9
8
  "repository": {
10
9
  "type": "git",
@@ -20,6 +19,9 @@
20
19
  "location",
21
20
  "url"
22
21
  ],
22
+ "engines": {
23
+ "node": ">=14"
24
+ },
23
25
  "author": "Karolis Narkevicius",
24
26
  "scripts": {
25
27
  "test": "npm run build && healthier && prettier --check '**/*.{js,css,yml}' && c8 ava",
@@ -32,15 +34,15 @@
32
34
  "release:docs": "hugo -s docs && gh-pages -d docs/public"
33
35
  },
34
36
  "devDependencies": {
37
+ "@swc-node/register": "^1.6.8",
35
38
  "@swc/cli": "^0.1.62",
36
- "@swc/core": "^1.3.49",
37
- "ava": "^5.2.0",
38
- "c8": "^7.13.0",
39
- "esm": "^3.2.25",
40
- "execa": "^7.1.1",
41
- "gh-pages": "^5.0.0",
42
- "healthier": "^6.3.0",
43
- "prettier": "^2.8.7"
39
+ "@swc/core": "^1.3.96",
40
+ "ava": "^5.3.1",
41
+ "c8": "^8.0.1",
42
+ "execa": "^8.0.1",
43
+ "gh-pages": "^6.0.0",
44
+ "healthier": "^7.0.0",
45
+ "prettier": "^3.0.3"
44
46
  },
45
47
  "healthier": {
46
48
  "global": [
@@ -55,7 +57,7 @@
55
57
  },
56
58
  "ava": {
57
59
  "require": [
58
- "esm"
60
+ "@swc-node/register"
59
61
  ]
60
62
  }
61
63
  }
package/src/index.js CHANGED
@@ -1,3 +1,3 @@
1
- export { createRouter, merge } from './router.js'
2
- export { createHistory } from './history.js'
3
- export { qs } from './qs.js'
1
+ export { createRouter, merge } from './router'
2
+ export { createHistory } from './history'
3
+ export { qs } from './qs'
package/src/router.js CHANGED
@@ -1,6 +1,6 @@
1
- import { match as findMatch } from './match.js'
2
- import { createHistory } from './history.js'
3
- import { qs as defaultQs } from './qs.js'
1
+ import { match as findMatch } from './match'
2
+ import { createHistory } from './history'
3
+ import { qs as defaultQs } from './qs'
4
4
 
5
5
  export function createRouter(options = {}) {
6
6
  let history = null
package/tasks/build.js CHANGED
@@ -1,14 +1,10 @@
1
- import fs from 'fs'
2
- import path from 'path'
3
- import { fileURLToPath } from 'url'
4
- import { execa } from 'execa'
5
-
6
- const __filename = fileURLToPath(import.meta.url)
7
- const __dirname = path.dirname(__filename)
8
-
9
- const sh = (...args) => execa(...args, { stdio: 'inherit', shell: true })
1
+ const fs = require('fs')
2
+ const path = require('path')
10
3
 
11
4
  ;(async function () {
5
+ const { execa } = await import('execa')
6
+ const sh = (...args) => execa(...args, { stdio: 'inherit', shell: true })
7
+
12
8
  await sh('rm -rf dist')
13
9
  await sh('mkdir -p dist')
14
10
 
@@ -1,5 +1,5 @@
1
1
  import test from 'ava'
2
- import { flatten } from '../src/router.js'
2
+ import { flatten } from '../src/router'
3
3
 
4
4
  test('converts array of routes to array of internal route descriptors', (t) => {
5
5
  t.deepEqual(
@@ -10,7 +10,7 @@ test('converts array of routes to array of internal route descriptors', (t) => {
10
10
  [
11
11
  { pattern: '/foo', data: [{ a: 'foo' }] },
12
12
  { pattern: '/bar', data: [{ a: 'bar' }] },
13
- ]
13
+ ],
14
14
  )
15
15
  })
16
16
 
@@ -49,7 +49,7 @@ test('handles nested routes', (t) => {
49
49
  { pattern: '/foo/bar', data: [{ component: 'root' }, { component: 'foo' }, { component: 'bar' }] },
50
50
  { pattern: '/second', data: [{ component: 'second-root' }] },
51
51
  { pattern: '/baz/*', data: [{ component: 'second-root' }, { component: 'baz' }] },
52
- ]
52
+ ],
53
53
  )
54
54
  })
55
55
 
@@ -1,6 +1,6 @@
1
1
  import test from 'ava'
2
- import { qs } from '../src/index.js'
3
- import { matchOne as match } from '../src/match.js'
2
+ import { qs } from '../src'
3
+ import { matchOne as match } from '../src/match'
4
4
 
5
5
  test('match explicit equality', (t) => {
6
6
  t.deepEqual(match('/', '/').params, {})
@@ -1,5 +1,5 @@
1
1
  import test from 'ava'
2
- import { qs, createRouter } from '../src/index.js'
2
+ import { qs, createRouter } from '../src/index'
3
3
 
4
4
  test('createRouter, listen, navigate and dispose', (t) => {
5
5
  const calls = []
@@ -38,7 +38,7 @@ test('createRouter, listen, navigate and dispose', (t) => {
38
38
  'user=3?a=11&c=bla#test',
39
39
  'user=curr?curr=test',
40
40
  ],
41
- calls
41
+ calls,
42
42
  )
43
43
 
44
44
  dispose()
@@ -51,28 +51,28 @@ test('.href(to)', (t) => {
51
51
 
52
52
  t.deepEqual(
53
53
  router.href({ pathname: '/user/:id/friends', params: { id: 7 }, query: { a: 1, b: 2 } }),
54
- '/user/7/friends?a=1&b=2'
54
+ '/user/7/friends?a=1&b=2',
55
55
  )
56
56
  t.deepEqual(
57
57
  router.href({ pathname: '/user/:id/friends', params: { id: 7 }, query: { a: 1, b: 2 }, hash: '#bla' }),
58
- '/user/7/friends?a=1&b=2#bla'
58
+ '/user/7/friends?a=1&b=2#bla',
59
59
  )
60
60
  t.deepEqual(router.href({ pathname: '/user/:id/friends', params: { id: 8 }, hash: '#foo' }), '/user/8/friends#foo')
61
61
  t.deepEqual(
62
62
  router.href({ pathname: '/user/:id/friends', params: { id: 8 }, query: {}, hash: '#foo' }),
63
- '/user/8/friends#foo'
63
+ '/user/8/friends#foo',
64
64
  )
65
65
  t.deepEqual(
66
66
  router.href({ pathname: '/user/:id/friends', params: { id: 8 }, query: { q: null }, hash: '#foo' }),
67
- '/user/8/friends?q=null#foo'
67
+ '/user/8/friends?q=null#foo',
68
68
  )
69
69
  t.deepEqual(
70
70
  router.href({ pathname: '/user/:id/friends', params: { id: 8 }, query: { q: undefined }, hash: '#foo' }),
71
- '/user/8/friends#foo'
71
+ '/user/8/friends#foo',
72
72
  )
73
73
  t.deepEqual(
74
74
  router.href({ pathname: '/user/:id/friends', params: { id: 8 }, query: { q: undefined }, hash: '#foo' }),
75
- '/user/8/friends#foo'
75
+ '/user/8/friends#foo',
76
76
  )
77
77
  t.deepEqual(router.href({ params: { id: 8 }, query: { q: 1 }, hash: '#foo' }), '/?q=1#foo')
78
78
 
@@ -151,7 +151,7 @@ function createTestRouter(cb, { withoutCatchAll = false } = {}) {
151
151
  { path: '/user/:id/settings', datum: 'settings-data' },
152
152
  !withoutCatchAll && { path: '*', render: () => 'catchall' },
153
153
  ].filter(Boolean),
154
- cb
154
+ cb,
155
155
  )
156
156
  return { router, dispose }
157
157
  }