@xylabs/enum 5.0.84 → 5.0.86
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/README.md +28 -34
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -15,6 +15,8 @@
|
|
|
15
15
|
|
|
16
16
|
Base functionality used throughout XY Labs TypeScript/JavaScript libraries
|
|
17
17
|
|
|
18
|
+
|
|
19
|
+
|
|
18
20
|
## Reference
|
|
19
21
|
|
|
20
22
|
**@xylabs/enum**
|
|
@@ -23,13 +25,17 @@ Base functionality used throughout XY Labs TypeScript/JavaScript libraries
|
|
|
23
25
|
|
|
24
26
|
## Type Aliases
|
|
25
27
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
28
|
+
| Type Alias | Description |
|
|
29
|
+
| ------ | ------ |
|
|
30
|
+
| [Enum](#type-aliases/Enum) | A utility type that, given a `Record<string, unknown>`, returns a readonly version of that record. This results in a type where all properties of `T` are readonly. |
|
|
31
|
+
| [EnumKey](#type-aliases/EnumKey) | A utility type that, given an `Enum` object, returns the union of its keys. |
|
|
32
|
+
| [EnumValue](#type-aliases/EnumValue) | A utility type that, given an `Enum` object, returns the union of its values. |
|
|
29
33
|
|
|
30
34
|
## Functions
|
|
31
35
|
|
|
32
|
-
|
|
36
|
+
| Function | Description |
|
|
37
|
+
| ------ | ------ |
|
|
38
|
+
| [Enum](#functions/Enum) | Transforms a given record object into a readonly "enum-like" structure while preserving the literal types of its values. This allows you to use the returned object both at runtime (for lookups) and at compile time (for strongly typed values). |
|
|
33
39
|
|
|
34
40
|
### functions
|
|
35
41
|
|
|
@@ -40,7 +46,7 @@ Base functionality used throughout XY Labs TypeScript/JavaScript libraries
|
|
|
40
46
|
***
|
|
41
47
|
|
|
42
48
|
```ts
|
|
43
|
-
function Enum<T>(obj): Enum<T>;
|
|
49
|
+
function Enum<T>(obj: Readonly<T>): Enum<T>;
|
|
44
50
|
```
|
|
45
51
|
|
|
46
52
|
Transforms a given record object into a readonly "enum-like" structure while preserving
|
|
@@ -52,19 +58,15 @@ ensure you annotate your object with `as const` before passing it to `Enum`.
|
|
|
52
58
|
|
|
53
59
|
## Type Parameters
|
|
54
60
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
`T` *extends* `Record`\<`string` \| `number` \| `symbol`, `unknown`\>
|
|
58
|
-
|
|
59
|
-
A record type with string keys and any kind of values.
|
|
61
|
+
| Type Parameter | Description |
|
|
62
|
+
| ------ | ------ |
|
|
63
|
+
| `T` *extends* `Record`\<`string` \| `number` \| `symbol`, `unknown`\> | A record type with string keys and any kind of values. |
|
|
60
64
|
|
|
61
65
|
## Parameters
|
|
62
66
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
`Readonly`\<`T`\>
|
|
66
|
-
|
|
67
|
-
A readonly record object annotated with `as const`.
|
|
67
|
+
| Parameter | Type | Description |
|
|
68
|
+
| ------ | ------ | ------ |
|
|
69
|
+
| `obj` | `Readonly`\<`T`\> | A readonly record object annotated with `as const`. |
|
|
68
70
|
|
|
69
71
|
## Returns
|
|
70
72
|
|
|
@@ -125,11 +127,9 @@ of that record. This results in a type where all properties of `T` are readonly.
|
|
|
125
127
|
|
|
126
128
|
## Type Parameters
|
|
127
129
|
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
`T` *extends* `Readonly`\<`Record`\<`string` \| `number` \| `symbol`, `unknown`\>\>
|
|
131
|
-
|
|
132
|
-
The record type to make readonly.
|
|
130
|
+
| Type Parameter | Description |
|
|
131
|
+
| ------ | ------ |
|
|
132
|
+
| `T` *extends* `Readonly`\<`Record`\<`string` \| `number` \| `symbol`, `unknown`\>\> | The record type to make readonly. |
|
|
133
133
|
|
|
134
134
|
## Example
|
|
135
135
|
|
|
@@ -168,13 +168,10 @@ A utility type that, given an `Enum` object, returns the union of its keys.
|
|
|
168
168
|
|
|
169
169
|
## Type Parameters
|
|
170
170
|
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
`T` *extends* `Record`\<`string` \| `number` \| `symbol`, `unknown`\>
|
|
174
|
-
|
|
175
|
-
### K
|
|
176
|
-
|
|
177
|
-
`K` = [`Enum`](#Enum)\<`T`\>
|
|
171
|
+
| Type Parameter | Default type |
|
|
172
|
+
| ------ | ------ |
|
|
173
|
+
| `T` *extends* `Record`\<`string` \| `number` \| `symbol`, `unknown`\> | - |
|
|
174
|
+
| `K` | [`Enum`](#Enum)\<`T`\> |
|
|
178
175
|
|
|
179
176
|
### <a id="EnumValue"></a>EnumValue
|
|
180
177
|
|
|
@@ -190,13 +187,10 @@ A utility type that, given an `Enum` object, returns the union of its values.
|
|
|
190
187
|
|
|
191
188
|
## Type Parameters
|
|
192
189
|
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
`T` *extends* `Record`\<`string` \| `number` \| `symbol`, `unknown`\>
|
|
196
|
-
|
|
197
|
-
### K
|
|
198
|
-
|
|
199
|
-
`K` = [`Enum`](#Enum)\<`T`\>
|
|
190
|
+
| Type Parameter | Default type |
|
|
191
|
+
| ------ | ------ |
|
|
192
|
+
| `T` *extends* `Record`\<`string` \| `number` \| `symbol`, `unknown`\> | - |
|
|
193
|
+
| `K` | [`Enum`](#Enum)\<`T`\> |
|
|
200
194
|
|
|
201
195
|
|
|
202
196
|
Part of [sdk-js](https://www.npmjs.com/package/@xyo-network/sdk-js)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xylabs/enum",
|
|
3
|
-
"version": "5.0.
|
|
3
|
+
"version": "5.0.86",
|
|
4
4
|
"description": "Base functionality used throughout XY Labs TypeScript/JavaScript libraries",
|
|
5
5
|
"homepage": "https://xyo.network",
|
|
6
6
|
"bugs": {
|
|
@@ -35,8 +35,8 @@
|
|
|
35
35
|
"!**/*.test.*"
|
|
36
36
|
],
|
|
37
37
|
"devDependencies": {
|
|
38
|
-
"@xylabs/ts-scripts-yarn3": "~7.4.
|
|
39
|
-
"@xylabs/tsconfig": "~7.4.
|
|
38
|
+
"@xylabs/ts-scripts-yarn3": "~7.4.16",
|
|
39
|
+
"@xylabs/tsconfig": "~7.4.16",
|
|
40
40
|
"typescript": "~5.9.3",
|
|
41
41
|
"vitest": "^4.0.18"
|
|
42
42
|
},
|