@deot/helper-route 1.1.4 → 1.1.6

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/dist/index.cjs CHANGED
@@ -13,8 +13,7 @@ const get = (key, url, options) => {
13
13
  const url$ = options$.url || (typeof window === "undefined" ? "" : window.location.search);
14
14
  const match = url$.substring(url$.indexOf("?") + 1).match(new RegExp("(^|&)" + key + "=([^&]*)"));
15
15
  let value = match != null ? match[2] : null;
16
- if (value === null)
17
- return null;
16
+ if (value === null) return null;
18
17
  value = helperUtils.flatten(value);
19
18
  return typeof options$.parse === "function" ? options$.parse(value) : value;
20
19
  };
@@ -59,10 +58,11 @@ const parse = (url, options) => {
59
58
  query[key] = typeof options$.parse === "function" ? options$.parse(value$) : value$;
60
59
  });
61
60
  }
62
- const sIndex = prefix.indexOf("/");
61
+ const pIndex = prefix.indexOf("://");
62
+ const sIndex = prefix.indexOf("/", pIndex === -1 ? 0 : pIndex + 3);
63
63
  return {
64
64
  origin: (sIndex !== -1 ? prefix.slice(0, sIndex) : prefix) || "",
65
- path: prefix.slice(sIndex),
65
+ path: sIndex !== -1 ? prefix.slice(sIndex) : "",
66
66
  query
67
67
  };
68
68
  };
@@ -1,7 +1,7 @@
1
1
  var HelperRoute = (function (exports) {
2
2
  'use strict';
3
3
 
4
- const flatten = (value, parser) => {
4
+ const flatten = (value, parser, exit) => {
5
5
  let need = true;
6
6
  let safeCount = 1;
7
7
  let parseValue = value;
@@ -11,7 +11,7 @@ var HelperRoute = (function (exports) {
11
11
  }
12
12
  try {
13
13
  const next = (parser || decodeURIComponent)(parseValue);
14
- if (parseValue === next) {
14
+ if (parseValue === next || typeof exit === "function" && exit(next)) {
15
15
  need = false;
16
16
  }
17
17
  parseValue = next;
@@ -24,8 +24,7 @@ var HelperRoute = (function (exports) {
24
24
  };
25
25
 
26
26
  const flattenJSONParse = (value) => {
27
- if (value === null)
28
- return null;
27
+ if (value === null) return null;
29
28
  const regex = /^\d+$/;
30
29
  if (regex.test(value) && value.length >= 16 && +value > Number.MAX_SAFE_INTEGER) {
31
30
  return value;
@@ -42,8 +41,7 @@ var HelperRoute = (function (exports) {
42
41
  const url$ = options$.url || (typeof window === "undefined" ? "" : window.location.search);
43
42
  const match = url$.substring(url$.indexOf("?") + 1).match(new RegExp("(^|&)" + key + "=([^&]*)"));
44
43
  let value = match != null ? match[2] : null;
45
- if (value === null)
46
- return null;
44
+ if (value === null) return null;
47
45
  value = flatten(value);
48
46
  return typeof options$.parse === "function" ? options$.parse(value) : value;
49
47
  };
@@ -88,10 +86,11 @@ var HelperRoute = (function (exports) {
88
86
  query[key] = typeof options$.parse === "function" ? options$.parse(value$) : value$;
89
87
  });
90
88
  }
91
- const sIndex = prefix.indexOf("/");
89
+ const pIndex = prefix.indexOf("://");
90
+ const sIndex = prefix.indexOf("/", pIndex === -1 ? 0 : pIndex + 3);
92
91
  return {
93
92
  origin: (sIndex !== -1 ? prefix.slice(0, sIndex) : prefix) || "",
94
- path: prefix.slice(sIndex),
93
+ path: sIndex !== -1 ? prefix.slice(sIndex) : "",
95
94
  query
96
95
  };
97
96
  };
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { flattenJSONParse, flatten } from '@deot/helper-utils';
1
+ import { flatten, flattenJSONParse } from '@deot/helper-utils';
2
2
 
3
3
  const get = (key, url, options) => {
4
4
  const options$ = {
@@ -9,8 +9,7 @@ const get = (key, url, options) => {
9
9
  const url$ = options$.url || (typeof window === "undefined" ? "" : window.location.search);
10
10
  const match = url$.substring(url$.indexOf("?") + 1).match(new RegExp("(^|&)" + key + "=([^&]*)"));
11
11
  let value = match != null ? match[2] : null;
12
- if (value === null)
13
- return null;
12
+ if (value === null) return null;
14
13
  value = flatten(value);
15
14
  return typeof options$.parse === "function" ? options$.parse(value) : value;
16
15
  };
@@ -55,10 +54,11 @@ const parse = (url, options) => {
55
54
  query[key] = typeof options$.parse === "function" ? options$.parse(value$) : value$;
56
55
  });
57
56
  }
58
- const sIndex = prefix.indexOf("/");
57
+ const pIndex = prefix.indexOf("://");
58
+ const sIndex = prefix.indexOf("/", pIndex === -1 ? 0 : pIndex + 3);
59
59
  return {
60
60
  origin: (sIndex !== -1 ? prefix.slice(0, sIndex) : prefix) || "",
61
- path: prefix.slice(sIndex),
61
+ path: sIndex !== -1 ? prefix.slice(sIndex) : "",
62
62
  query
63
63
  };
64
64
  };
@@ -4,7 +4,7 @@
4
4
  (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.HelperRoute = {}));
5
5
  })(this, (function (exports) { 'use strict';
6
6
 
7
- const flatten = (value, parser) => {
7
+ const flatten = (value, parser, exit) => {
8
8
  let need = true;
9
9
  let safeCount = 1;
10
10
  let parseValue = value;
@@ -14,7 +14,7 @@
14
14
  }
15
15
  try {
16
16
  const next = (parser || decodeURIComponent)(parseValue);
17
- if (parseValue === next) {
17
+ if (parseValue === next || typeof exit === "function" && exit(next)) {
18
18
  need = false;
19
19
  }
20
20
  parseValue = next;
@@ -27,8 +27,7 @@
27
27
  };
28
28
 
29
29
  const flattenJSONParse = (value) => {
30
- if (value === null)
31
- return null;
30
+ if (value === null) return null;
32
31
  const regex = /^\d+$/;
33
32
  if (regex.test(value) && value.length >= 16 && +value > Number.MAX_SAFE_INTEGER) {
34
33
  return value;
@@ -45,8 +44,7 @@
45
44
  const url$ = options$.url || (typeof window === "undefined" ? "" : window.location.search);
46
45
  const match = url$.substring(url$.indexOf("?") + 1).match(new RegExp("(^|&)" + key + "=([^&]*)"));
47
46
  let value = match != null ? match[2] : null;
48
- if (value === null)
49
- return null;
47
+ if (value === null) return null;
50
48
  value = flatten(value);
51
49
  return typeof options$.parse === "function" ? options$.parse(value) : value;
52
50
  };
@@ -91,10 +89,11 @@
91
89
  query[key] = typeof options$.parse === "function" ? options$.parse(value$) : value$;
92
90
  });
93
91
  }
94
- const sIndex = prefix.indexOf("/");
92
+ const pIndex = prefix.indexOf("://");
93
+ const sIndex = prefix.indexOf("/", pIndex === -1 ? 0 : pIndex + 3);
95
94
  return {
96
95
  origin: (sIndex !== -1 ? prefix.slice(0, sIndex) : prefix) || "",
97
- path: prefix.slice(sIndex),
96
+ path: sIndex !== -1 ? prefix.slice(sIndex) : "",
98
97
  query
99
98
  };
100
99
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@deot/helper-route",
3
- "version": "1.1.4",
3
+ "version": "1.1.6",
4
4
  "type": "module",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -19,6 +19,6 @@
19
19
  "access": "public"
20
20
  },
21
21
  "dependencies": {
22
- "@deot/helper-utils": "^1.1.4"
22
+ "@deot/helper-utils": "^1.1.5"
23
23
  }
24
24
  }