shinkansen-rails 1.0.269 → 1.0.271

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "shinkansen-rails",
3
- "version": "1.0.269",
3
+ "version": "1.0.271",
4
4
  "description": "Shinkansen Rails",
5
5
  "keywords": [
6
6
  "Shinkansen",
@@ -38,23 +38,26 @@
38
38
  "debug": "^4.4.0"
39
39
  },
40
40
  "devDependencies": {
41
- "@babel/core": "^7.26.7",
42
- "@babel/eslint-parser": "^7.26.5",
43
- "@babel/preset-env": "^7.26.7",
41
+ "@babel/core": "^7.26.8",
42
+ "@babel/eslint-parser": "^7.26.8",
43
+ "@babel/preset-env": "^7.26.8",
44
44
  "@babel/register": "^7.25.9",
45
45
  "@sequencemedia/eslint-config-standard": "^0.2.18",
46
46
  "@sequencemedia/eslint-config-typescript": "^0.1.27",
47
+ "@types/babel__register": "^7.17.3",
48
+ "@types/debug": "^4.1.12",
47
49
  "@typescript-eslint/eslint-plugin": "^8.23.0",
48
50
  "@typescript-eslint/parser": "^8.23.0",
49
51
  "chai": "^5.1.2",
50
52
  "core-js": "^3.40.0",
51
53
  "cross-env": "^7.0.3",
52
- "eslint": "^9.19.0",
54
+ "eslint": "^9.20.0",
53
55
  "eslint-import-resolver-babel-module": "^5.3.2",
54
56
  "globals": "^15.14.0",
55
57
  "husky": "^9.1.7",
56
58
  "mocha": "^11.1.0",
57
- "sinon": "^19.0.2"
59
+ "sinon": "^19.0.2",
60
+ "typescript": "^5.7.3"
58
61
  },
59
62
  "imports": {
60
63
  "#rails": "./src/index.mjs",
package/src/index.cjs CHANGED
@@ -11,7 +11,7 @@ const log = debug('shinkansen-rails')
11
11
  log('`shinkansen` is awake')
12
12
 
13
13
  const {
14
- default: Rails
14
+ default: Rails // @ts-ignore
15
15
  } = require('./rails/index.mjs')
16
16
 
17
17
  module.exports.Rails = Rails
@@ -3,15 +3,15 @@ declare module '#rails/rails' {
3
3
  export function has (o: Record<PropertyKey, unknown>, k: string): boolean
4
4
  export function get (o: Record<PropertyKey, unknown>, k: string): unknown
5
5
 
6
- export function rail (p: string): string
7
- export function go (o: Record<PropertyKey, unknown>, p: string): boolean
8
- export function to (o: Record<PropertyKey, unknown>, p: string): boolean
6
+ export function rail (p?: string): string
7
+ export function go (o?: Record<PropertyKey, unknown>, p?: string): boolean
8
+ export function to (o?: Record<PropertyKey, unknown>, p?: string): string
9
9
 
10
10
  export default class Rails { // eslint-disable-line @typescript-eslint/no-extraneous-class -- Static class
11
- static pattern (p: string | undefined): string
12
- static rail (p: string | undefined): string
13
- static go (o: Record<PropertyKey, unknown> | undefined, p: string | undefined): boolean
14
- static to (o: Record<PropertyKey, unknown> | undefined, p: string | undefined): boolean
11
+ static pattern (p?: string): string
12
+ static rail (p?: string): string
13
+ static go (o?: Record<PropertyKey, unknown>, p?: string): boolean
14
+ static to (o?: Record<PropertyKey, unknown>, p?: string): string
15
15
  }
16
16
  }
17
17
 
@@ -4,6 +4,7 @@ const log = debug('shinkansen-rails')
4
4
 
5
5
  log('`shinkansen` is awake')
6
6
 
7
+ // @ts-ignore
7
8
  let pattern
8
9
 
9
10
  const map = new Map()
@@ -21,12 +22,14 @@ export const any = (o) => !!Reflect.ownKeys(o).length
21
22
  /**
22
23
  * @param {Record<PropertyKey, unknown>} o The object containing values
23
24
  * @param {string} k The value name
25
+ * @returns {boolean}
24
26
  */
25
27
  export const has = (o, k) => Reflect.has(o, k)
26
28
 
27
29
  /**
28
30
  * @param {Record<PropertyKey, unknown>} o The object containing values
29
31
  * @param {string} k The value name
32
+ * @returns {unknown}
30
33
  */
31
34
  export const get = (o, k) => Reflect.get(o, k)
32
35
 
@@ -47,7 +50,6 @@ export function rail (p) {
47
50
  *
48
51
  * @param {Record<PropertyKey, unknown>} o The object containing values for the 'pattern'
49
52
  * @param {string} p The 'pattern' according to which URLs should be created
50
- * @param {boolean} b Whether the Rails can go
51
53
  * @return {boolean}
52
54
  *
53
55
  * @description
@@ -68,7 +70,7 @@ export function go (o, p) {
68
70
 
69
71
  if (b) {
70
72
  let k
71
- const a = p.match(/(\w+)/g)
73
+ const a = p.match(/(\w+)/g) ?? []
72
74
  while (b && (k = a.shift())) b = has(o, k) // it is only necessary that the `o` has key `k`. Otherwise, `b = has(o, k) && !!get(o, k)` to enforce a truthy field value for field key `k`
73
75
  }
74
76
 
@@ -86,31 +88,35 @@ export function go (o, p) {
86
88
  *
87
89
  * A valid object is
88
90
  *
91
+ * ```javascript
89
92
  * { fieldName: 'field Value' }
93
+ * ```
90
94
  *
91
95
  * A valid string is
92
96
  *
97
+ * ```javascript
93
98
  * /:fieldName
99
+ * ```
94
100
  */
95
101
  export function to (o, p) {
96
102
  return (
97
- p.replace(/(?::)(\w+)/g, (m, k) => m ? has(o, k) ? get(o, k) : m : m)
103
+ p.replace(/(?::)(\w+)/g, (m, k) => m ? has(o, k) ? String(get(o, k)) : m : m)
98
104
  )
99
105
  }
100
106
 
101
107
  export default class Rails {
102
108
  /**
103
- * @param {string | undefined} p The 'pattern' according to which URLs should be created
109
+ * @param {string | undefined} [p] The 'pattern' according to which URLs should be created
104
110
  * @return {string}
105
111
  */
106
112
  static pattern (p) {
107
- return (
113
+ return ( // @ts-ignore
108
114
  p ? (pattern = String(p)) : pattern || (pattern = PATTERN)
109
115
  )
110
116
  }
111
117
 
112
118
  /**
113
- * @param {string | undefined} p The 'pattern' according to which URLs should be created
119
+ * @param {string} [p] The 'pattern' according to which URLs should be created
114
120
  * @return {string}
115
121
  */
116
122
  static rail (p = Rails.pattern()) {
@@ -122,8 +128,8 @@ export default class Rails {
122
128
  }
123
129
 
124
130
  /**
125
- * @param {Record<PropertyKey, unknown> | undefined} o The object containing values for the 'pattern'
126
- * @param {string | undefined} p The 'pattern' according to which URLs should be created
131
+ * @param {Record<PropertyKey, unknown>} [o] The object containing values for the 'pattern'
132
+ * @param {string | undefined} [p] The 'pattern' according to which URLs should be created
127
133
  * @return {boolean}
128
134
  */
129
135
  static go (o = {}, p = Rails.pattern()) {
@@ -133,9 +139,9 @@ export default class Rails {
133
139
  }
134
140
 
135
141
  /**
136
- * @param {Record<PropertyKey, unknown> | undefined} o The object containing values for the 'pattern'
137
- * @param {string | undefined} p The 'pattern' according to which URLs should be created
138
- * @return {boolean}
142
+ * @param {Record<PropertyKey, unknown>} [o] The object containing values for the 'pattern'
143
+ * @param {string} [p] The 'pattern' according to which URLs should be created
144
+ * @return {string}
139
145
  */
140
146
  static to (o = {}, p = Rails.pattern()) {
141
147
  return ( // eslint-disable-next-line no-cond-assign