@shakerquiz/utilities 4.0.81 → 4.0.83
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 +10 -4
- package/source/entities/method.js +1 -0
- package/source/helpers/map.js +21 -0
- package/source/helpers/next-router.js +29 -0
- package/source/helpers/object.js +17 -1
- package/source/helpers/promise.js +7 -4
- package/source/helpers/url-search-params.js +21 -0
- package/source/index.js +0 -4
- package/source/helpers/access.js +0 -160
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"type": "module",
|
|
3
3
|
"name": "@shakerquiz/utilities",
|
|
4
|
-
"version": "4.0.
|
|
4
|
+
"version": "4.0.83",
|
|
5
5
|
"author": "yurkimus <yurkimus@gmail.com>",
|
|
6
6
|
"license": "ISC",
|
|
7
7
|
"repository": {
|
|
@@ -9,13 +9,19 @@
|
|
|
9
9
|
"url": "https://github.com/shaker-quiz/utilities.git"
|
|
10
10
|
},
|
|
11
11
|
"exports": {
|
|
12
|
-
"
|
|
12
|
+
".": {
|
|
13
|
+
"default": "./source/index.js"
|
|
14
|
+
},
|
|
15
|
+
"./helpers/*": {
|
|
16
|
+
"default": "./source/helpers/*.js"
|
|
17
|
+
}
|
|
13
18
|
},
|
|
14
19
|
"scripts": {
|
|
15
20
|
"prepublishOnly": "bun scripts/codegen.js && dprint fmt --includes-override source/codegen/autogenerated.js"
|
|
16
21
|
},
|
|
17
22
|
"devDependencies": {
|
|
18
|
-
"@types/bun": "1.3.
|
|
19
|
-
"dprint": "0.51.1"
|
|
23
|
+
"@types/bun": "1.3.10",
|
|
24
|
+
"dprint": "0.51.1",
|
|
25
|
+
"typescript": "5.9.3"
|
|
20
26
|
}
|
|
21
27
|
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @param {Map} collection
|
|
3
|
+
*/
|
|
4
|
+
export const set = (collection, key, value) => {
|
|
5
|
+
var result = new Map(collection)
|
|
6
|
+
|
|
7
|
+
result.set(key, value)
|
|
8
|
+
|
|
9
|
+
return result
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* @param {Map} collection
|
|
14
|
+
*/
|
|
15
|
+
export const remove = (collection, key) => {
|
|
16
|
+
var result = new Map(collection)
|
|
17
|
+
|
|
18
|
+
result.delete(key)
|
|
19
|
+
|
|
20
|
+
return result
|
|
21
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @param {object} router
|
|
3
|
+
* @param {string | Partial<URL>} input
|
|
4
|
+
* @param {{ shallow?: boolean }} [transition]
|
|
5
|
+
*/
|
|
6
|
+
export const push = (router, input, transition) => {
|
|
7
|
+
if (!Object.hasOwn(router, 'push'))
|
|
8
|
+
throw TypeError(`Parameter 'router.push' is not defined.`)
|
|
9
|
+
|
|
10
|
+
if (typeof router.push !== 'function')
|
|
11
|
+
throw TypeError(`Parameter 'router.push' is not a function.`)
|
|
12
|
+
|
|
13
|
+
return router.push(input, undefined, transition)
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* @param {object} router
|
|
18
|
+
* @param {string | Partial<URL>} input
|
|
19
|
+
* @param {{ shallow?: boolean }} [transition]
|
|
20
|
+
*/
|
|
21
|
+
export const replace = (router, input, transition) => {
|
|
22
|
+
if (!Object.hasOwn(router, 'replace'))
|
|
23
|
+
throw TypeError(`Parameter 'router.replace' is not defined.`)
|
|
24
|
+
|
|
25
|
+
if (typeof router.replace !== 'function')
|
|
26
|
+
throw TypeError(`Parameter 'router.replace' is not a function.`)
|
|
27
|
+
|
|
28
|
+
return router.replace(input, undefined, transition)
|
|
29
|
+
}
|
package/source/helpers/object.js
CHANGED
|
@@ -7,7 +7,7 @@ export const hasOwn = Object.hasOwn
|
|
|
7
7
|
* @param {object} o
|
|
8
8
|
* @param {PropertyKey} v
|
|
9
9
|
*
|
|
10
|
-
* @returns {
|
|
10
|
+
* @returns {*}
|
|
11
11
|
*/
|
|
12
12
|
export const tryOwn = (o, v) => hasOwn(o, v) ? o[v] : undefined
|
|
13
13
|
|
|
@@ -28,3 +28,19 @@ export const getOwn = (o, v) => {
|
|
|
28
28
|
|
|
29
29
|
return o[v]
|
|
30
30
|
}
|
|
31
|
+
|
|
32
|
+
export const set = (object, key, value) => {
|
|
33
|
+
var result = { ...object }
|
|
34
|
+
|
|
35
|
+
result[key] = value
|
|
36
|
+
|
|
37
|
+
return result
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export const remove = (object, key) => {
|
|
41
|
+
var result = { ...object }
|
|
42
|
+
|
|
43
|
+
delete result[key]
|
|
44
|
+
|
|
45
|
+
return result
|
|
46
|
+
}
|
|
@@ -2,14 +2,17 @@ export let settle = value =>
|
|
|
2
2
|
Promise
|
|
3
3
|
.resolve(value)
|
|
4
4
|
.then(
|
|
5
|
-
value => ({ status: 'fulfilled', value }),
|
|
6
|
-
reason => ({ status: 'rejected', reason }),
|
|
5
|
+
value => (/** @type {const} */ ({ status: 'fulfilled', value })),
|
|
6
|
+
reason => (/** @type {const} */ ({ status: 'rejected', reason })),
|
|
7
7
|
)
|
|
8
8
|
|
|
9
|
+
/**
|
|
10
|
+
* @param {Parameters<typeof Promise.try>[0]} fn
|
|
11
|
+
*/
|
|
9
12
|
export let trySettle = (fn, ...args) =>
|
|
10
13
|
Promise
|
|
11
14
|
.try(fn, ...args)
|
|
12
15
|
.then(
|
|
13
|
-
value => ({ status: 'fulfilled', value }),
|
|
14
|
-
reason => ({ status: 'rejected', reason }),
|
|
16
|
+
value => (/** @type {const} */ ({ status: 'fulfilled', value })),
|
|
17
|
+
reason => (/** @type {const} */ ({ status: 'rejected', reason })),
|
|
15
18
|
)
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @param {URLSearchParams} collection
|
|
3
|
+
*/
|
|
4
|
+
export const set = (collection, key, value) => {
|
|
5
|
+
var result = new URLSearchParams(collection)
|
|
6
|
+
|
|
7
|
+
result.set(key, value)
|
|
8
|
+
|
|
9
|
+
return result
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* @param {URLSearchParams} collection
|
|
14
|
+
*/
|
|
15
|
+
export const remove = (collection, key) => {
|
|
16
|
+
var result = new URLSearchParams(collection)
|
|
17
|
+
|
|
18
|
+
result.delete(key)
|
|
19
|
+
|
|
20
|
+
return result
|
|
21
|
+
}
|
package/source/index.js
CHANGED
|
@@ -38,9 +38,5 @@ export * from './entities/services.js'
|
|
|
38
38
|
export * from './entities/theme-status.js'
|
|
39
39
|
export * from './entities/venue-audience.js'
|
|
40
40
|
export * from './entities/venue-status.js'
|
|
41
|
-
export * from './helpers/access.js'
|
|
42
|
-
export * from './helpers/array.js'
|
|
43
|
-
export * from './helpers/object.js'
|
|
44
|
-
export * from './helpers/promise.js'
|
|
45
41
|
export * from './helpers/route.js'
|
|
46
42
|
export * from './helpers/tag.js'
|
package/source/helpers/access.js
DELETED
|
@@ -1,160 +0,0 @@
|
|
|
1
|
-
import { ParameterPattern, PathnameParameters, RouteCardinality, RoutePathname, RouteService, ServiceRoutes } from '../codegen/autogenerated.js'
|
|
2
|
-
import { Blend } from '../entities/blend.js'
|
|
3
|
-
import { Cardinality } from '../entities/cardinality.js'
|
|
4
|
-
import { Category } from '../entities/category.js'
|
|
5
|
-
import { CityAffilation } from '../entities/city-affilation.js'
|
|
6
|
-
import { CityChatappVersion } from '../entities/city-chatapp-version.js'
|
|
7
|
-
import { Constants } from '../entities/constants.js'
|
|
8
|
-
import { Display } from '../entities/display.js'
|
|
9
|
-
import { GameStatus } from '../entities/game-status.js'
|
|
10
|
-
import { Gender } from '../entities/gender.js'
|
|
11
|
-
import { Icon } from '../entities/icon.js'
|
|
12
|
-
import { Method } from '../entities/method.js'
|
|
13
|
-
import { Mode } from '../entities/mode.js'
|
|
14
|
-
import { Network } from '../entities/network.js'
|
|
15
|
-
import { Numerosity } from '../entities/numerosity.js'
|
|
16
|
-
import { Pattern } from '../entities/pattern.js'
|
|
17
|
-
import { Phase } from '../entities/phase.js'
|
|
18
|
-
import { Quantifier } from '../entities/quantifier.js'
|
|
19
|
-
import { RegistrationChannel } from '../entities/registration-channel.js'
|
|
20
|
-
import { RegistrationLineup } from '../entities/registration-lineup.js'
|
|
21
|
-
import { RegistrationMailing } from '../entities/registration-mailing.js'
|
|
22
|
-
import { RegistrationStatus } from '../entities/registration-status.js'
|
|
23
|
-
import { Role } from '../entities/role.js'
|
|
24
|
-
import { Route } from '../entities/routes.js'
|
|
25
|
-
import { Runtime } from '../entities/runtimes.js'
|
|
26
|
-
import { ServiceRuntime } from '../entities/service-runtime.js'
|
|
27
|
-
import { Service } from '../entities/services.js'
|
|
28
|
-
import { ThemeStatus } from '../entities/theme-status.js'
|
|
29
|
-
import { VenueAudience } from '../entities/venue-audience.js'
|
|
30
|
-
import { VenueStatus } from '../entities/venue-status.js'
|
|
31
|
-
|
|
32
|
-
const Node = new Map([
|
|
33
|
-
[CityAffilation, 'city'],
|
|
34
|
-
[CityChatappVersion, 'city'],
|
|
35
|
-
[GameStatus, 'game'],
|
|
36
|
-
[RegistrationChannel, 'registration'],
|
|
37
|
-
[RegistrationLineup, 'registration'],
|
|
38
|
-
[RegistrationMailing, 'registration'],
|
|
39
|
-
[RegistrationStatus, 'registration'],
|
|
40
|
-
[Role, 'role'],
|
|
41
|
-
[ThemeStatus, 'theme'],
|
|
42
|
-
[VenueAudience, 'venue'],
|
|
43
|
-
[VenueStatus, 'venue'],
|
|
44
|
-
])
|
|
45
|
-
|
|
46
|
-
const Prop = new Map([
|
|
47
|
-
[Blend, 'blend'],
|
|
48
|
-
[Cardinality, 'cardinality'],
|
|
49
|
-
[Category, 'category'],
|
|
50
|
-
[CityAffilation, 'affilation'],
|
|
51
|
-
[CityChatappVersion, 'version'],
|
|
52
|
-
[Constants, 'constants'],
|
|
53
|
-
[Display, 'display'],
|
|
54
|
-
[GameStatus, 'status'],
|
|
55
|
-
[Gender, 'gender'],
|
|
56
|
-
[Icon, 'icon'],
|
|
57
|
-
[Method, 'method'],
|
|
58
|
-
[Mode, 'mode'],
|
|
59
|
-
[Network, 'network'],
|
|
60
|
-
[Numerosity, 'numerosity'],
|
|
61
|
-
[ParameterPattern, 'pattern'],
|
|
62
|
-
[PathnameParameters, 'parameters'],
|
|
63
|
-
[Pattern, 'pattern'],
|
|
64
|
-
[Phase, 'phase'],
|
|
65
|
-
[Quantifier, 'quantifier'],
|
|
66
|
-
[RegistrationChannel, 'channel'],
|
|
67
|
-
[RegistrationLineup, 'lineup'],
|
|
68
|
-
[RegistrationMailing, 'mailing'],
|
|
69
|
-
[RegistrationStatus, 'status'],
|
|
70
|
-
[Role, 'name'],
|
|
71
|
-
[Route, 'route'],
|
|
72
|
-
[RouteCardinality, 'cardinality'],
|
|
73
|
-
[RoutePathname, 'pathname'],
|
|
74
|
-
[RouteService, 'service'],
|
|
75
|
-
[Runtime, 'runtime'],
|
|
76
|
-
[Service, 'service'],
|
|
77
|
-
[ServiceRoutes, 'routes'],
|
|
78
|
-
[ServiceRuntime, 'runtime'],
|
|
79
|
-
[ThemeStatus, 'status'],
|
|
80
|
-
[VenueAudience, 'audience'],
|
|
81
|
-
[VenueStatus, 'status'],
|
|
82
|
-
])
|
|
83
|
-
|
|
84
|
-
const Tag = new Map([
|
|
85
|
-
[Blend, 'Blend'],
|
|
86
|
-
[Cardinality, 'Cardinality'],
|
|
87
|
-
[Category, 'Category'],
|
|
88
|
-
[CityAffilation, 'CityAffilation'],
|
|
89
|
-
[CityChatappVersion, 'CityChatappVersion'],
|
|
90
|
-
[Constants, 'Constants'],
|
|
91
|
-
[Display, 'Display'],
|
|
92
|
-
[GameStatus, 'GameStatus'],
|
|
93
|
-
[Gender, 'Gender'],
|
|
94
|
-
[Icon, 'Icon'],
|
|
95
|
-
[Method, 'Method'],
|
|
96
|
-
[Mode, 'Mode'],
|
|
97
|
-
[Network, 'Network'],
|
|
98
|
-
[Numerosity, 'Numerosity'],
|
|
99
|
-
[ParameterPattern, 'ParameterPattern'],
|
|
100
|
-
[PathnameParameters, 'PathnameParameters'],
|
|
101
|
-
[Pattern, 'Pattern'],
|
|
102
|
-
[Phase, 'Phase'],
|
|
103
|
-
[Quantifier, 'Quantifier'],
|
|
104
|
-
[RegistrationChannel, 'RegistrationChannel'],
|
|
105
|
-
[RegistrationLineup, 'RegistrationLineup'],
|
|
106
|
-
[RegistrationMailing, 'RegistrationMailing'],
|
|
107
|
-
[RegistrationStatus, 'RegistrationStatus'],
|
|
108
|
-
[Role, 'Role'],
|
|
109
|
-
[Route, 'Route'],
|
|
110
|
-
[RouteCardinality, 'RouteCardinality'],
|
|
111
|
-
[RoutePathname, 'RoutePathname'],
|
|
112
|
-
[RouteService, 'RouteService'],
|
|
113
|
-
[Runtime, 'Runtime'],
|
|
114
|
-
[Service, 'Service'],
|
|
115
|
-
[ServiceRuntime, 'ServiceRuntime'],
|
|
116
|
-
[ThemeStatus, 'ThemeStatus'],
|
|
117
|
-
[VenueAudience, 'VenueAudience'],
|
|
118
|
-
[VenueStatus, 'VenueStatus'],
|
|
119
|
-
])
|
|
120
|
-
|
|
121
|
-
/**
|
|
122
|
-
* @template Relation
|
|
123
|
-
* @template {keyof Relation} Key
|
|
124
|
-
*
|
|
125
|
-
* @param {Relation} relation
|
|
126
|
-
* @param {Key} value
|
|
127
|
-
*
|
|
128
|
-
* @returns {Relation[Key]}
|
|
129
|
-
*
|
|
130
|
-
* @throws {TypeError}
|
|
131
|
-
*/
|
|
132
|
-
export const access = (relation, value) => {
|
|
133
|
-
const node = Node.get(relation)
|
|
134
|
-
|
|
135
|
-
const prop = Prop.get(relation)
|
|
136
|
-
|
|
137
|
-
const read = value?.[node]?.[prop] ?? value?.[prop] ?? value
|
|
138
|
-
|
|
139
|
-
if (Object.hasOwn(relation, read))
|
|
140
|
-
return relation[read]
|
|
141
|
-
else
|
|
142
|
-
throw TypeError(`Could not require key '${value}' from '${Tag.get(relation)}'.`)
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
/**
|
|
146
|
-
* @template Relation
|
|
147
|
-
* @template {keyof Relation} Key
|
|
148
|
-
*
|
|
149
|
-
* @param {Relation} relation
|
|
150
|
-
* @param {Key} value
|
|
151
|
-
*
|
|
152
|
-
* @returns {Relation[Key] | 'Unknown'}
|
|
153
|
-
*/
|
|
154
|
-
export const tryAccess = (relation, value) => {
|
|
155
|
-
try {
|
|
156
|
-
return access(relation, value)
|
|
157
|
-
} catch (error) {
|
|
158
|
-
return 'Unknown'
|
|
159
|
-
}
|
|
160
|
-
}
|