@xylabs/enum 4.13.19 → 4.13.21

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 CHANGED
@@ -12,13 +12,192 @@
12
12
  [![snyk-badge][]][snyk-link]
13
13
  [![socket-badge][]][socket-link]
14
14
 
15
- Version: 4.13.15
16
15
 
17
- Primary SDK for using XYO Protocol 2.0
16
+ Base functionality used throughout XY Labs TypeScript/JavaScript libraries
18
17
 
19
- ## Documentation
18
+ ## API Documentation
19
+
20
+ **@xylabs/enum**
21
+
22
+ ***
23
+
24
+ ## Type Aliases
25
+
26
+ - [Enum](#type-aliases/Enum)
27
+ - [EnumKey](#type-aliases/EnumKey)
28
+ - [EnumValue](#type-aliases/EnumValue)
29
+
30
+ ## Functions
31
+
32
+ - [Enum](#functions/Enum)
33
+
34
+ ### functions
35
+
36
+ ### <a id="Enum"></a>Enum
37
+
38
+ [**@xylabs/enum**](#../README)
39
+
40
+ ***
41
+
42
+ ```ts
43
+ function Enum<T>(obj): Enum<T>;
44
+ ```
45
+
46
+ Transforms a given record object into a readonly "enum-like" structure while preserving
47
+ the literal types of its values. This allows you to use the returned object both at runtime
48
+ (for lookups) and at compile time (for strongly typed values).
49
+
50
+ To maintain literal types (i.e., prevent them from being widened to `string`, `number`, etc.),
51
+ ensure you annotate your object with `as const` before passing it to `Enum`.
52
+
53
+ ## Type Parameters
54
+
55
+ ### T
56
+
57
+ `T` *extends* `Record`\<`string` \| `number` \| `symbol`, `unknown`\>
58
+
59
+ A record type with string keys and any kind of values.
60
+
61
+ ## Parameters
62
+
63
+ ### obj
64
+
65
+ `Readonly`\<`T`\>
66
+
67
+ A readonly record object annotated with `as const`.
68
+
69
+ ## Returns
70
+
71
+ [`Enum`](#../type-aliases/Enum)\<`T`\>
72
+
73
+ A readonly version of the provided record, preserving exact literal value types.
74
+
75
+ ## Example
76
+
77
+ ```typescript
78
+ // Defining a record with literal types using as const:
79
+ const DnsRecordType = Enum({
80
+ A: 1,
81
+ AAAA: 28,
82
+ CAA: 257,
83
+ CNAME: 5,
84
+ DNAME: 39,
85
+ MX: 15,
86
+ NS: 2,
87
+ PTR: 12,
88
+ SOA: 6,
89
+ SPF: 99,
90
+ SRV: 33,
91
+ TXT: 16,
92
+ } as const);
93
+
94
+ // DnsRecordType is now a readonly object:
95
+ // {
96
+ // readonly A: 1;
97
+ // readonly AAAA: 28;
98
+ // readonly CAA: 257;
99
+ // readonly CNAME: 5;
100
+ // readonly DNAME: 39;
101
+ // readonly MX: 15;
102
+ // readonly NS: 2;
103
+ // readonly PTR: 12;
104
+ // readonly SOA: 6;
105
+ // readonly SPF: 99;
106
+ // readonly SRV: 33;
107
+ // readonly TXT: 16;
108
+ // }
109
+ ```
110
+
111
+ ### type-aliases
112
+
113
+ ### <a id="Enum"></a>Enum
114
+
115
+ [**@xylabs/enum**](#../README)
116
+
117
+ ***
118
+
119
+ ```ts
120
+ type Enum<T> = { readonly [K in keyof T]: T[K] };
121
+ ```
122
+
123
+ A utility type that, given a `Record<string, unknown>`, returns a readonly version
124
+ of that record. This results in a type where all properties of `T` are readonly.
125
+
126
+ ## Type Parameters
127
+
128
+ ### T
129
+
130
+ `T` *extends* `Readonly`\<`Record`\<`string` \| `number` \| `symbol`, `unknown`\>\>
131
+
132
+ The record type to make readonly.
133
+
134
+ ## Example
135
+
136
+ ```typescript
137
+ // Given a record:
138
+ export const DnsRecordType = Enum({
139
+ A: 1,
140
+ AAAA: 28,
141
+ CAA: 257,
142
+ CNAME: 5,
143
+ DNAME: 39,
144
+ MX: 15,
145
+ NS: 2,
146
+ PTR: 12,
147
+ SOA: 6,
148
+ SPF: 99,
149
+ SRV: 33,
150
+ TXT: 16,
151
+ })
152
+
153
+ // Now the type inference will preserve the literal types:
154
+ export type DnsRecordType = Enum<typeof DnsRecordType>
155
+ ```
156
+
157
+ ### <a id="EnumKey"></a>EnumKey
158
+
159
+ [**@xylabs/enum**](#../README)
160
+
161
+ ***
162
+
163
+ ```ts
164
+ type EnumKey<T, K> = keyof K;
165
+ ```
166
+
167
+ A utility type that, given an `Enum` object, returns the union of its keys.
168
+
169
+ ## Type Parameters
170
+
171
+ ### T
172
+
173
+ `T` *extends* `Record`\<`string` \| `number` \| `symbol`, `unknown`\>
174
+
175
+ ### K
176
+
177
+ `K` = [`Enum`](#Enum)\<`T`\>
178
+
179
+ ### <a id="EnumValue"></a>EnumValue
180
+
181
+ [**@xylabs/enum**](#../README)
182
+
183
+ ***
184
+
185
+ ```ts
186
+ type EnumValue<T, K> = K[keyof K];
187
+ ```
188
+
189
+ A utility type that, given an `Enum` object, returns the union of its values.
190
+
191
+ ## Type Parameters
192
+
193
+ ### T
194
+
195
+ `T` *extends* `Record`\<`string` \| `number` \| `symbol`, `unknown`\>
196
+
197
+ ### K
198
+
199
+ `K` = [`Enum`](#Enum)\<`T`\>
20
200
 
21
- Coming Soon!
22
201
 
23
202
  Part of [sdk-js](https://www.npmjs.com/package/@xyo-network/sdk-js)
24
203
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@xylabs/enum",
3
- "version": "4.13.19",
4
- "description": "Primary SDK for using XYO Protocol 2.0",
3
+ "version": "4.13.21",
4
+ "description": "Base functionality used throughout XY Labs TypeScript/JavaScript libraries",
5
5
  "homepage": "https://xyo.network",
6
6
  "bugs": {
7
7
  "url": "git+https://github.com/XYOracleNetwork/sdk-xyo-client-js/issues",
@@ -22,15 +22,21 @@
22
22
  "exports": {
23
23
  ".": {
24
24
  "types": "./dist/neutral/index.d.ts",
25
+ "source": "./src/index.ts",
25
26
  "default": "./dist/neutral/index.mjs"
26
27
  },
27
28
  "./package.json": "./package.json"
28
29
  },
29
- "module": "dist/neutral/index.mjs",
30
- "types": "dist/neutral/index.d.ts",
30
+ "module": "./dist/neutral/index.mjs",
31
+ "source": "./src/index.ts",
32
+ "types": "./dist/neutral/index.d.ts",
33
+ "files": [
34
+ "dist",
35
+ "src"
36
+ ],
31
37
  "devDependencies": {
32
- "@xylabs/ts-scripts-yarn3": "^7.0.0-rc.27",
33
- "@xylabs/tsconfig": "^7.0.0-rc.27",
38
+ "@xylabs/ts-scripts-yarn3": "^7.0.0",
39
+ "@xylabs/tsconfig": "^7.0.0",
34
40
  "typescript": "^5.8.3"
35
41
  },
36
42
  "publishConfig": {
package/typedoc.json DELETED
@@ -1,5 +0,0 @@
1
- {
2
- "$schema": "https://typedoc.org/schema.json",
3
- "entryPoints": ["./src/index.ts"],
4
- "tsconfig": "./tsconfig.typedoc.json"
5
- }
package/xy.config.ts DELETED
@@ -1,10 +0,0 @@
1
- import type { XyTsupConfig } from '@xylabs/ts-scripts-yarn3'
2
- const config: XyTsupConfig = {
3
- compile: {
4
- browser: {},
5
- neutral: { src: true },
6
- node: {},
7
- },
8
- }
9
-
10
- export default config