@shakerquiz/utilities 0.4.10 → 0.4.11

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": "@shakerquiz/utilities",
3
- "version": "0.4.10",
3
+ "version": "0.4.11",
4
4
  "author": "yurkimus <yurkimus@gmail.com>",
5
5
  "license": "ISC",
6
6
  "scripts": {
@@ -2,3 +2,4 @@
2
2
  * @type {Scope[]}
3
3
  */
4
4
  export const Scopes: Scope[];
5
+ export function resolveScope(request: Request): Scope | "";
@@ -1,4 +1,4 @@
1
- import { Features } from './features.js'
1
+ import { FeatureKindPatterns, Features } from './features.js'
2
2
  import { Kinds } from './kinds.js'
3
3
  import { Methods } from './methods.js'
4
4
 
@@ -10,3 +10,18 @@ export var Scopes = Object
10
10
  .flatMap(method => Object.values(Features).map(feature => [method, feature]))
11
11
  .flatMap(array => Object.values(Kinds).map(kind => array.concat(kind)))
12
12
  .map(array => array.join('/'))
13
+
14
+ /**
15
+ * @param {Request} request
16
+ *
17
+ * @returns {Scope | ''}
18
+ */
19
+ export var resolveScope = request => {
20
+ var found = FeatureKindPatterns
21
+ .find(([, , pattern]) => pattern.test(request.url))
22
+ ?.slice(0, -1)
23
+
24
+ return found
25
+ ? request.method + '/' + found[0] + '/' + found[1]
26
+ : ''
27
+ }