js-routes 2.1.1 → 2.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 64ddd33bda1dffe333670e22c7abe2e578d960709c5ddb42a1559fea57495288
4
- data.tar.gz: af6b923046c1d3e0e838be4502355d9a2c8646af03c90b084e0bf04ec41cbce5
3
+ metadata.gz: 61ecfa4f633571ccef27b543b26c0f8ca285cd5e26b8970f079262ec2d34525a
4
+ data.tar.gz: f4188f8ae11c79987ca533feb5750160b69339b78d7f3eb13ba6c3d53ff7da59
5
5
  SHA512:
6
- metadata.gz: 15d336c5dae45e63e7ca1700a58ca9d9146c867a59034f9a1346fbdb03153162055fee77d018a8b206bf5ead8a813730ca8618332d1fd5b1a42e0336db8c4ece
7
- data.tar.gz: fe9f55283a5b5d71a25b117f35cf9c2562128a4ca6d1efe4022a3f0108fb93779dd1ec13183b019cbf895df30ea52657c4c0f8c9df780ec7dcd486ad6eb71932
6
+ metadata.gz: 0e49b2584cefe8c936d087fb9fc14291f46b22c425397117f500cf18d492694bf81af4154a13be32b04b1c9738aa55923adf8277ca26f201dda82ba7c7c1a0df
7
+ data.tar.gz: a31127d506a1d316638d8e386cc96eee83fd980150f223f11aacf48602957323ff6850f9b38e6d2ee25ebb4c1824ed5d8047d657a5449c7bb82a7adf2d3dbac4
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  ## master
2
2
 
3
+ ## v2.1.2
4
+
5
+ * Improve browser window object detection. [#287](https://github.com/railsware/js-routes/issues/287)
6
+
3
7
  ## v2.1.1
4
8
 
5
9
  * Added webpacker generator `./bin/rails generate js_routes:webpacker`
@@ -1,3 +1,3 @@
1
1
  class JsRoutes
2
- VERSION = "2.1.1"
2
+ VERSION = "2.1.2"
3
3
  end
data/lib/routes.js CHANGED
@@ -16,6 +16,7 @@ RubyVariables.WRAPPER((that) => {
16
16
  NodeTypes[NodeTypes["DOT"] = 8] = "DOT";
17
17
  })(NodeTypes || (NodeTypes = {}));
18
18
  const Root = that;
19
+ const isBroswer = typeof window !== "undefined";
19
20
  const ModuleReferences = {
20
21
  CJS: {
21
22
  define(routes) {
@@ -419,15 +420,15 @@ RubyVariables.WRAPPER((that) => {
419
420
  }
420
421
  current_host() {
421
422
  var _a;
422
- return ((_a = window === null || window === void 0 ? void 0 : window.location) === null || _a === void 0 ? void 0 : _a.hostname) || "";
423
+ return (isBroswer && ((_a = window === null || window === void 0 ? void 0 : window.location) === null || _a === void 0 ? void 0 : _a.hostname)) || "";
423
424
  }
424
425
  current_protocol() {
425
426
  var _a, _b;
426
- return ((_b = (_a = window === null || window === void 0 ? void 0 : window.location) === null || _a === void 0 ? void 0 : _a.protocol) === null || _b === void 0 ? void 0 : _b.replace(/:$/, "")) || "http";
427
+ return ((isBroswer && ((_b = (_a = window === null || window === void 0 ? void 0 : window.location) === null || _a === void 0 ? void 0 : _a.protocol) === null || _b === void 0 ? void 0 : _b.replace(/:$/, ""))) || "http");
427
428
  }
428
429
  current_port() {
429
430
  var _a;
430
- return ((_a = window === null || window === void 0 ? void 0 : window.location) === null || _a === void 0 ? void 0 : _a.port) || "";
431
+ return (isBroswer && ((_a = window === null || window === void 0 ? void 0 : window.location) === null || _a === void 0 ? void 0 : _a.port)) || "";
431
432
  }
432
433
  is_object(value) {
433
434
  return (typeof value === "object" &&
data/lib/routes.ts CHANGED
@@ -129,6 +129,7 @@ RubyVariables.WRAPPER(
129
129
  }[keyof RouteNodes];
130
130
 
131
131
  const Root = that;
132
+ const isBroswer = typeof window !== "undefined";
132
133
  type ModuleDefinition = {
133
134
  define: (routes: RouterExposedMethods) => void;
134
135
  isSupported: () => boolean;
@@ -625,15 +626,17 @@ RubyVariables.WRAPPER(
625
626
  }
626
627
 
627
628
  current_host(): string {
628
- return window?.location?.hostname || "";
629
+ return (isBroswer && window?.location?.hostname) || "";
629
630
  }
630
631
 
631
632
  current_protocol(): string {
632
- return window?.location?.protocol?.replace(/:$/, "") || "http";
633
+ return (
634
+ (isBroswer && window?.location?.protocol?.replace(/:$/, "")) || "http"
635
+ );
633
636
  }
634
637
 
635
638
  current_port(): string {
636
- return window?.location?.port || "";
639
+ return (isBroswer && window?.location?.port) || "";
637
640
  }
638
641
 
639
642
  is_object(value: unknown): value is Record<string, unknown> {
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: js-routes
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.1
4
+ version: 2.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bogdan Gusiev
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-10-06 00:00:00.000000000 Z
11
+ date: 2021-11-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: railties