@shakerquiz/utilities 0.5.178 → 0.5.180
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,24 +1,32 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { inferRoute, inferRouteParams, inferRoutePathname } from '../enumerations/route.js'
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
export const hydrateRoutePathname = Object.freeze(
|
|
4
|
+
/**
|
|
5
|
+
* @param {*} maybeRoute
|
|
6
|
+
* @param {any[]} maybeRouteParams
|
|
7
|
+
*/
|
|
8
|
+
(maybeRoute, maybeRouteParams) => {
|
|
9
|
+
if (!Array.isArray(maybeRouteParams))
|
|
10
|
+
throw TypeError(`Parameter 'maybeRouteParams' must be 'Array'.`)
|
|
5
11
|
|
|
6
|
-
|
|
7
|
-
* @param {*} maybeRoute
|
|
8
|
-
* @param {any[]} maybeRouteParams
|
|
9
|
-
*/
|
|
10
|
-
export var hydrateRoutePathname = (maybeRoute, maybeRouteParams) => {
|
|
11
|
-
if (!isTag('Array', maybeRouteParams))
|
|
12
|
-
throw TypeError(`Parameter 'maybeRouteParams' must be 'Array'.`)
|
|
12
|
+
var route = inferRoute(maybeRoute)
|
|
13
13
|
|
|
14
|
-
|
|
14
|
+
if (route === 'Unknown')
|
|
15
|
+
throw TypeError(`Could not infer route of: '${maybeRoute}'.`)
|
|
15
16
|
|
|
16
|
-
|
|
17
|
+
var routePathname = inferRoutePathname(route)
|
|
17
18
|
|
|
18
|
-
|
|
19
|
+
if (routePathname === 'Unknown')
|
|
20
|
+
throw TypeError(`Could not infer route pathname of: '${route}'.`)
|
|
19
21
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
22
|
+
var routeParams = inferRouteParams(route)
|
|
23
|
+
|
|
24
|
+
if (routeParams === 'Unknown')
|
|
25
|
+
throw TypeError(`Could not infer route params of: '${route}'.`)
|
|
26
|
+
|
|
27
|
+
return routeParams.reduce(
|
|
28
|
+
(pathname, param, index) => pathname.replace(param, maybeRouteParams[index]),
|
|
29
|
+
routePathname,
|
|
30
|
+
)
|
|
31
|
+
},
|
|
32
|
+
)
|
|
@@ -1,15 +1,19 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { inferMethod } from '../enumerations/method.js'
|
|
2
2
|
|
|
3
3
|
import { hydrateRoutePathname } from './hydrate-route-pathname.js'
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
4
|
+
|
|
5
|
+
export const routeKey = Object.freeze(
|
|
6
|
+
/**
|
|
7
|
+
* @param {any} maybeMethod
|
|
8
|
+
* @param {any} maybeRoute
|
|
9
|
+
* @param {any[]} maybeParameters
|
|
10
|
+
*/
|
|
11
|
+
(maybeMethod, maybeRoute, maybeParameters) => {
|
|
12
|
+
var method = inferMethod(maybeMethod)
|
|
13
|
+
|
|
14
|
+
if (method === 'Unknown')
|
|
15
|
+
throw TypeError(`Could not infer method of: '${maybeMethod}'.`)
|
|
16
|
+
|
|
17
|
+
return method + '/' + hydrateRoutePathname(maybeRoute, maybeParameters)
|
|
18
|
+
},
|
|
19
|
+
)
|
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
|
-
}
|