shinkansen-rails 1.0.30 → 1.0.33

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.
Files changed (2) hide show
  1. package/package.json +2 -2
  2. package/src/rails/index.mjs +42 -28
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "shinkansen-rails",
3
- "version": "1.0.30",
3
+ "version": "1.0.33",
4
4
  "description": "Shinkansen Rails",
5
5
  "keywords": [
6
6
  "Shinkansen",
@@ -38,7 +38,7 @@
38
38
  "@babel/plugin-proposal-export-default-from": "^7.18.10",
39
39
  "@babel/preset-env": "^7.21.5",
40
40
  "@babel/register": "^7.21.0",
41
- "@modernpoacher/hooks": "^1.0.396",
41
+ "@modernpoacher/hooks": "^1.0.397",
42
42
  "babel-plugin-module-resolver": "^5.0.0",
43
43
  "chai": "^4.3.7",
44
44
  "core-js": "^3.30.2",
@@ -20,22 +20,22 @@ export const get = (o, k) => Reflect.get(o, k)
20
20
  /**
21
21
  * Format simple latin character strings as URL compatible
22
22
  *
23
- * @param {String} s The string to convert
24
- * @return {String} The string, converted
23
+ * @param {string} p The string to convert
24
+ * @return {string} The string, converted
25
25
  */
26
- export function rail (s) {
26
+ export function rail (p) {
27
27
  return ( // eslint-disable-next-line no-useless-escape
28
- s.toLowerCase().replace(/[^\w\-\d]/g, CHAR32).trim().replace(/[\s]+/g, CHAR45).replace(/[\s\s|\-\-]+/g, CHAR45)
28
+ p.toLowerCase().replace(/[^\w\-\d]/g, CHAR32).trim().replace(/[\s]+/g, CHAR45).replace(/[\s\s|\-\-]+/g, CHAR45)
29
29
  )
30
30
  }
31
31
 
32
32
  /**
33
33
  * Interrogate parameters to determine whether or not components can be created
34
34
  *
35
- * @param {Object} o The object containing values for the 'pattern'
36
- * @param {String} s The 'pattern' according to which URLs should be created
37
- * @param {Boolean} b Whether the Rails can go
38
- * @return {Boolean}
35
+ * @param {{}} o The object containing values for the 'pattern'
36
+ * @param {string} p The 'pattern' according to which URLs should be created
37
+ * @param {boolean} b Whether the Rails can go
38
+ * @return {boolean}
39
39
  *
40
40
  * @description
41
41
  *
@@ -50,12 +50,12 @@ export function rail (s) {
50
50
  *
51
51
  * A `reduce` cannot break when `b` is false
52
52
  */
53
- export function go (o, s) {
53
+ export function go (o, p) {
54
54
  let b = any(o)
55
55
 
56
56
  if (b) {
57
57
  let k
58
- const a = s.match(/(\w+)/g)
58
+ const a = p.match(/(\w+)/g)
59
59
  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`
60
60
  }
61
61
 
@@ -65,9 +65,9 @@ export function go (o, s) {
65
65
  /**
66
66
  * Interrogate parameters for object field names
67
67
  *
68
- * @param {Object} o The object containing fields
69
- * @param {String} s The string containing field names to be found
70
- * @return {String}
68
+ * @param {{}} o The object containing fields
69
+ * @param {string} p The string containing field names to be found
70
+ * @return {string}
71
71
  *
72
72
  * @description
73
73
  *
@@ -79,40 +79,54 @@ export function go (o, s) {
79
79
  *
80
80
  * /:fieldName
81
81
  */
82
- export function to (o, s) {
82
+ export function to (o, p) {
83
83
  return (
84
- s.replace(/(?::)(\w+)/g, (m, k) => m ? has(o, k) ? get(o, k) : m : m)
84
+ p.replace(/(?::)(\w+)/g, (m, k) => m ? has(o, k) ? get(o, k) : m : m)
85
85
  )
86
86
  }
87
87
 
88
- /**
89
- * Rails.go() Boolean
90
- * Rails.to() String
91
- */
92
88
  export default class Rails {
89
+ /**
90
+ * @param {string | void} p The 'pattern' according to which URLs should be created
91
+ * @return {string}
92
+ */
93
93
  static pattern (p) {
94
94
  return (
95
95
  p ? (pattern = String(p)) : pattern || (pattern = PATTERN)
96
96
  )
97
97
  }
98
98
 
99
- static rail (s) {
100
- const k = String(s)
99
+ /**
100
+ * @param {string | void} p The 'pattern' according to which URLs should be created
101
+ * @return {string}
102
+ */
103
+ static rail (p = Rails.pattern()) {
104
+ const k = String(p)
101
105
  if (map.has(k)) return map.get(k)
102
- const S = rail(k)
103
- map.set(k, S)
104
- return S
106
+ const s = rail(k)
107
+ map.set(k, s)
108
+ return s
105
109
  }
106
110
 
107
- static go (o = {}, s = Rails.pattern()) {
111
+ /**
112
+ * @param {{} | void} o The object containing values for the 'pattern'
113
+ * @param {string | void} p The 'pattern' according to which URLs should be created
114
+ * @return {boolean}
115
+ */
116
+ static go (o = {}, p = Rails.pattern()) {
108
117
  return ( // eslint-disable-next-line no-cond-assign
109
- any(o) ? (s = String(s)) ? go(o, s) : false : false // return is s is truthy true then go else false
118
+ any(o) ? (p = String(p)) ? go(o, p) : false : false // return is p is truthy true then go else false
110
119
  )
111
120
  }
112
121
 
113
- static to (o = {}, s = Rails.pattern()) {
122
+ /**
123
+ * @param {{} | void} o The object containing values for the 'pattern'
124
+ * @param {string | void} p The 'pattern' according to which URLs should be created
125
+ * @return {boolean}
126
+ */
127
+ static to (o = {}, p = Rails.pattern()) {
114
128
  return ( // eslint-disable-next-line no-cond-assign
115
- any(o) ? (s = String(s)) ? to(o, s) : s : s
129
+ any(o) ? (p = String(p)) ? to(o, p) : p : p
116
130
  )
117
131
  }
118
132
  }