js_rails_routes 1.1.0 → 1.2.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c11d8e6af1565c2c53a41fae11b7f802862abdc0fdf025d91c55b06718b69f42
4
- data.tar.gz: 44d767c56274bf63c53d241dfd84feb1f2bac1e56f59e68d8b28ff3e6852ec98
3
+ metadata.gz: e50948437613107c257fb18c1207d97578746364aec3cb07ca8a93b8bcab3102
4
+ data.tar.gz: 845917a81764d9f13531fb4a8498d4c8c71fee5b432c326b1fa31f5767c9d1ce
5
5
  SHA512:
6
- metadata.gz: ba97b9bb129f473f3c50fb5bd4fc5804c95c77ae48a5acf34d6b02dd8fe5f8250af895915f3d834feb69a7878d3e01bb376fec2b6b85c4f1ca93d6c831e687bc
7
- data.tar.gz: 9ad1938f061504f09dd194e991a352dcee227d07f6a6be2cfc633ed6b558386898e71fae6345f4a58c2622092a4a93dc2b2ea4f7cc37846a84a4c4039b40fb46
6
+ metadata.gz: d38cfab4a3d127c3423345a1c4c56b72d24b198909b4f294b0b83055ce73a7175a7ce66767eb22187beab6300a5909e554c9e1609cdcd8fcf9a2ec5f77c8d12e
7
+ data.tar.gz: 8fd42be0a4fbb917cef7719de28a9fc5013cbd4cd1022399194d42fa40cbae9e59236944af31b6b6d64dcdec064e51f9fe30f26e892a0214619498acde6e3ad9
@@ -15,7 +15,7 @@ jobs:
15
15
  strategy:
16
16
  fail-fast: false
17
17
  matrix:
18
- os: ['ubuntu-18.04', 'ubuntu-latest', 'macos-latest']
18
+ os: ['ubuntu-20.04', 'ubuntu-latest', 'macos-latest']
19
19
  ruby: [2.6, 2.7, 3.0, 3.1]
20
20
  experimental: [false]
21
21
  include:
@@ -27,7 +27,7 @@ jobs:
27
27
  steps:
28
28
  - name: Get branch names
29
29
  id: branch-name
30
- uses: tj-actions/branch-names@v4.9
30
+ uses: tj-actions/branch-names@v7.0.7
31
31
  - uses: actions/checkout@v2
32
32
  - uses: ruby/setup-ruby@v1
33
33
  with:
data/CHANGELOG.md CHANGED
@@ -6,6 +6,10 @@ This change log adheres to [keepachangelog.com](http://keepachangelog.com).
6
6
 
7
7
  ## [Unreleased]
8
8
 
9
+ ## [1.2.0] - 2024-04-19
10
+ ### Added
11
+ - Add support for parameters as Array
12
+
9
13
  ## [1.1.0] - 2024-02-09
10
14
  ### Changed
11
15
  - Add eslint-disable comment not to affect eslint format
@@ -94,7 +98,9 @@ This change log adheres to [keepachangelog.com](http://keepachangelog.com).
94
98
  ### Added
95
99
  - Implement "js:rails:routes" task
96
100
 
97
- [Unreleased]: https://github.com/increments/js_rails_routes/compare/v1.0.0...HEAD
101
+ [Unreleased]: https://github.com/increments/js_rails_routes/compare/v1.2.0...HEAD
102
+ [1.2.0]: https://github.com/increments/js_rails_routes/compare/v1.1.0...v1.2.0
103
+ [1.1.0]: https://github.com/increments/js_rails_routes/compare/v1.0.0...v1.1.0
98
104
  [1.0.0]: https://github.com/increments/js_rails_routes/compare/v0.10.1...v1.0.0
99
105
  [0.10.1]: https://github.com/increments/js_rails_routes/compare/v0.10.0...v0.10.1
100
106
  [0.10.0]: https://github.com/increments/js_rails_routes/compare/v0.9.0...v0.10.0
@@ -11,7 +11,13 @@ module JSRailsRoutes
11
11
  var query = [];
12
12
  for (var param in params) if (Object.prototype.hasOwnProperty.call(params, param)) {
13
13
  if (keys.indexOf(param) === -1) {
14
- query.push(param + "=" + encodeURIComponent(params[param]));
14
+ if (Array.isArray(params[param])) {
15
+ for (var value of params[param]) {
16
+ query.push(param + "[]=" + encodeURIComponent(value));
17
+ }
18
+ } else {
19
+ query.push(param + "=" + encodeURIComponent(params[param]));
20
+ }
15
21
  }
16
22
  }
17
23
  return query.length ? route + "?" + query.join("&") : route;
@@ -7,14 +7,20 @@ module JSRailsRoutes
7
7
  module Language
8
8
  class TypeScript < JavaScript
9
9
  PROCESS_FUNC = <<~TYPESCRIPT
10
- type Value = string | number
10
+ type Value = string | number | (string | number)[];
11
11
  type Params<Keys extends string> = { [key in Keys]: Value } & Record<string, Value>
12
12
  function process(route: string, params: Record<string, Value> | undefined, keys: string[]): string {
13
13
  if (!params) return route
14
14
  var query: string[] = [];
15
15
  for (var param in params) if (Object.prototype.hasOwnProperty.call(params, param)) {
16
16
  if (keys.indexOf(param) === -1) {
17
- query.push(param + "=" + encodeURIComponent(params[param].toString()));
17
+ if (Array.isArray(params[param])) {
18
+ for (var value of params[param] as (string | number)[]) {
19
+ query.push(param + "[]=" + encodeURIComponent(value.toString()));
20
+ }
21
+ } else {
22
+ query.push(param + "=" + encodeURIComponent(params[param].toString()));
23
+ }
18
24
  }
19
25
  }
20
26
  return query.length ? route + "?" + query.join("&") : route;
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module JSRailsRoutes
4
- VERSION = '1.1.0'
4
+ VERSION = '1.2.0'
5
5
  end
@@ -14,7 +14,13 @@ RSpec.describe JSRailsRoutes::Language::JavaScript do
14
14
  var query = [];
15
15
  for (var param in params) if (Object.prototype.hasOwnProperty.call(params, param)) {
16
16
  if (keys.indexOf(param) === -1) {
17
- query.push(param + "=" + encodeURIComponent(params[param]));
17
+ if (Array.isArray(params[param])) {
18
+ for (var value of params[param]) {
19
+ query.push(param + "[]=" + encodeURIComponent(value));
20
+ }
21
+ } else {
22
+ query.push(param + "=" + encodeURIComponent(params[param]));
23
+ }
18
24
  }
19
25
  }
20
26
  return query.length ? route + "?" + query.join("&") : route;
@@ -10,14 +10,20 @@ RSpec.describe JSRailsRoutes::Language::TypeScript do
10
10
 
11
11
  it 'returns a typescript function' do
12
12
  expect(subject).to eq <<~TYPESCRIPT
13
- type Value = string | number
13
+ type Value = string | number | (string | number)[];
14
14
  type Params<Keys extends string> = { [key in Keys]: Value } & Record<string, Value>
15
15
  function process(route: string, params: Record<string, Value> | undefined, keys: string[]): string {
16
16
  if (!params) return route
17
17
  var query: string[] = [];
18
18
  for (var param in params) if (Object.prototype.hasOwnProperty.call(params, param)) {
19
19
  if (keys.indexOf(param) === -1) {
20
- query.push(param + "=" + encodeURIComponent(params[param].toString()));
20
+ if (Array.isArray(params[param])) {
21
+ for (var value of params[param] as (string | number)[]) {
22
+ query.push(param + "[]=" + encodeURIComponent(value.toString()));
23
+ }
24
+ } else {
25
+ query.push(param + "=" + encodeURIComponent(params[param].toString()));
26
+ }
21
27
  }
22
28
  }
23
29
  return query.length ? route + "?" + query.join("&") : route;
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: js_rails_routes
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Qiita Inc.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-02-09 00:00:00.000000000 Z
11
+ date: 2024-04-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails