@shakerquiz/utilities 0.5.177 → 0.5.179

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,7 +1,7 @@
1
1
  {
2
2
  "type": "module",
3
3
  "name": "@shakerquiz/utilities",
4
- "version": "0.5.177",
4
+ "version": "0.5.179",
5
5
  "author": "yurkimus <yurkimus@gmail.com>",
6
6
  "license": "ISC",
7
7
  "repository": {
@@ -13,3 +13,8 @@ export const Method = Object.freeze({
13
13
  })
14
14
 
15
15
  export const Methods = Object.freeze(Object.values(Method))
16
+
17
+ export const inferMethod = Object.freeze(
18
+ /** @returns {keyof typeof Method | 'Unknown'} */
19
+ x => Method[x] ?? 'Unknown',
20
+ )
@@ -65,6 +65,8 @@ export const Route = Object.freeze({
65
65
  'venues/city': 'venues/city',
66
66
  })
67
67
 
68
+ export const Routes = Object.freeze(Object.values(Route))
69
+
68
70
  export const RouteCardinality = Object.freeze({
69
71
  [Route['checkin']]: Cardinality['1'],
70
72
  [Route['cities']]: Cardinality['N'],
@@ -1,24 +1,30 @@
1
- import { Route, RouteParams, RoutePathname } from '../enumerations/route.js'
2
-
3
- import { inferKey } from './infer-key.js'
4
- import { isTag } from './tag.js'
1
+ import { inferRoute, inferRouteParams, inferRoutePathname } from '../enumerations/route.js'
5
2
 
6
3
  /**
7
4
  * @param {*} maybeRoute
8
5
  * @param {any[]} maybeRouteParams
9
6
  */
10
7
  export var hydrateRoutePathname = (maybeRoute, maybeRouteParams) => {
11
- if (!isTag('Array', maybeRouteParams))
8
+ if (!Array.isArray(maybeRouteParams))
12
9
  throw TypeError(`Parameter 'maybeRouteParams' must be 'Array'.`)
13
10
 
14
- var route = inferKey(Route, maybeRoute)
11
+ var route = inferRoute(maybeRoute)
12
+
13
+ if (route === 'Unknown')
14
+ throw TypeError(`Could not infer route of: '${maybeRoute}'.`)
15
+
16
+ var routePathname = inferRoutePathname(route)
17
+
18
+ if (routePathname === 'Unknown')
19
+ throw TypeError(`Could not infer route pathname of: '${route}'.`)
15
20
 
16
- var pathname = inferKey(RoutePathname, route)
21
+ var routeParams = inferRouteParams(route)
17
22
 
18
- var params = inferKey(RouteParams, route)
23
+ if (routeParams === 'Unknown')
24
+ throw TypeError(`Could not infer route params of: '${route}'.`)
19
25
 
20
- return params.reduce(
26
+ return routeParams.reduce(
21
27
  (pathname, param, index) => pathname.replace(param, maybeRouteParams[index]),
22
- pathname,
28
+ routePathname,
23
29
  )
24
30
  }
@@ -1,15 +1,17 @@
1
- import { Method } from '../enumerations/method.js'
1
+ import { inferMethod } from '../enumerations/method.js'
2
2
 
3
3
  import { hydrateRoutePathname } from './hydrate-route-pathname.js'
4
- import { inferKey } from './infer-key.js'
5
4
 
6
5
  /**
7
6
  * @param {any} maybeMethod
8
7
  * @param {any} maybeRoute
9
8
  * @param {any[]} maybeParameters
10
9
  */
11
- export var routeKey = (maybeMethod, maybeRoute, maybeParameters) =>
12
- ''
13
- + inferKey(Method, maybeMethod)
14
- + '/'
15
- + hydrateRoutePathname(maybeRoute, maybeParameters)
10
+ export var routeKey = (maybeMethod, maybeRoute, maybeParameters) => {
11
+ var method = inferMethod(maybeMethod)
12
+
13
+ if (method === 'Unknown')
14
+ throw TypeError(`Could not infer method of: '${maybeMethod}'.`)
15
+
16
+ return method + '/' + hydrateRoutePathname(maybeRoute, maybeParameters)
17
+ }
package/source/index.js CHANGED
@@ -8,9 +8,9 @@ export * from './enumerations/method.js'
8
8
  export * from './enumerations/mode.js'
9
9
  export * from './enumerations/network.js'
10
10
  export * from './enumerations/numerosity.js'
11
+ export * from './enumerations/pattern.js'
11
12
  export * from './enumerations/phase.js'
12
13
  export * from './enumerations/quantifier.js'
13
- export * from './enumerations/pattern.js'
14
14
  export * from './enumerations/route.js'
15
15
  export * from './enumerations/runtime.js'
16
16
  export * from './enumerations/service.js'
@@ -30,6 +30,5 @@ export * from './enumerations/venue/audience.js'
30
30
  export * from './enumerations/venue/status.js'
31
31
 
32
32
  export * from './functions/hydrate-route-pathname.js'
33
- export * from './functions/infer-key.js'
34
33
  export * from './functions/route-key.js'
35
34
  export * from './functions/tag.js'
@@ -1,13 +0,0 @@
1
- /**
2
- * @template {any} E
3
- *
4
- * @param {E} Enumeration
5
- *
6
- * @returns {E[keyof E]}
7
- */
8
- export var inferKey = (Enumeration, value) => {
9
- if (value in Enumeration)
10
- return Enumeration[value]
11
- else
12
- throw TypeError(`Cannot infer key of value: '${value}' for enum: '${Object.values(Enumeration).join(', ')}'.`)
13
- }