@xylabs/enum 4.13.14 β 4.13.16
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 +22 -31
- package/dist/neutral/Enum.d.ts +88 -0
- package/dist/neutral/Enum.d.ts.map +1 -0
- package/dist/neutral/index.d.ts +2 -90
- package/dist/neutral/index.d.ts.map +1 -0
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -1,63 +1,54 @@
|
|
|
1
|
-
|
|
1
|
+
# @xylabs/enum
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[![logo][]](https://xylabs.com)
|
|
4
4
|
|
|
5
|
+
[![main-build][]][main-build-link]
|
|
5
6
|
[![npm-badge][]][npm-link]
|
|
6
7
|
[![npm-downloads-badge][]][npm-link]
|
|
7
8
|
[![jsdelivr-badge][]][jsdelivr-link]
|
|
8
9
|
[![npm-license-badge][]](LICENSE)
|
|
10
|
+
[![codacy-badge][]][codacy-link]
|
|
11
|
+
[![codeclimate-badge][]][codeclimate-link]
|
|
12
|
+
[![snyk-badge][]][snyk-link]
|
|
9
13
|
[![socket-badge][]][socket-link]
|
|
10
14
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
## Table of Contents
|
|
14
|
-
|
|
15
|
-
- [Description](#description)
|
|
16
|
-
- [Install](#install)
|
|
17
|
-
- [Maintainers](#maintainers)
|
|
18
|
-
- [License](#license)
|
|
19
|
-
- [Credits](#credits)
|
|
20
|
-
|
|
21
|
-
## Description
|
|
22
|
-
|
|
23
|
-
Common Javascript code that is used throughout XYO projects that use React.
|
|
15
|
+
Version: 4.13.15
|
|
24
16
|
|
|
25
|
-
|
|
17
|
+
Primary SDK for using XYO Protocol 2.0
|
|
26
18
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
```sh
|
|
30
|
-
npm i --save @xylabs/object
|
|
31
|
-
```
|
|
32
|
-
|
|
33
|
-
Using yarn:
|
|
19
|
+
## Documentation
|
|
34
20
|
|
|
35
|
-
|
|
36
|
-
yarn add @xylabs/object
|
|
37
|
-
```
|
|
21
|
+
Coming Soon!
|
|
38
22
|
|
|
39
|
-
|
|
40
|
-
[Developer Reference](https://xylabs.github.io/sdk-js)
|
|
23
|
+
Part of [sdk-js](https://www.npmjs.com/package/@xyo-network/sdk-js)
|
|
41
24
|
|
|
42
25
|
## Maintainers
|
|
43
26
|
|
|
44
27
|
- [Arie Trouw](https://github.com/arietrouw) ([arietrouw.com](https://arietrouw.com))
|
|
45
|
-
- [Joel Carter](https://github.com/JoelBCarter)
|
|
46
28
|
- [Matt Jones](https://github.com/jonesmac)
|
|
29
|
+
- [Joel Carter](https://github.com/JoelBCarter)
|
|
47
30
|
- [Jordan Trouw](https://github.com/jordantrouw)
|
|
48
31
|
|
|
49
32
|
## License
|
|
50
33
|
|
|
51
|
-
See the [LICENSE](LICENSE) file for license details
|
|
34
|
+
> See the [LICENSE](LICENSE) file for license details
|
|
52
35
|
|
|
53
36
|
## Credits
|
|
54
37
|
|
|
55
|
-
[Made with π₯and βοΈ by
|
|
38
|
+
[Made with π₯ and βοΈ by XYLabs](https://xylabs.com)
|
|
56
39
|
|
|
57
40
|
[logo]: https://cdn.xy.company/img/brand/XYPersistentCompany_Logo_Icon_Colored.svg
|
|
58
41
|
|
|
42
|
+
[main-build]: https://github.com/xylabs/sdk-js/actions/workflows/build.yml/badge.svg
|
|
43
|
+
[main-build-link]: https://github.com/xylabs/sdk-js/actions/workflows/build.yml
|
|
59
44
|
[npm-badge]: https://img.shields.io/npm/v/@xylabs/enum.svg
|
|
60
45
|
[npm-link]: https://www.npmjs.com/package/@xylabs/enum
|
|
46
|
+
[codacy-badge]: https://app.codacy.com/project/badge/Grade/c8e15e14f37741c18cfb47ac7245c698
|
|
47
|
+
[codacy-link]: https://www.codacy.com/gh/xylabs/sdk-js/dashboard?utm_source=github.com&utm_medium=referral&utm_content=xylabs/sdk-js&utm_campaign=Badge_Grade
|
|
48
|
+
[codeclimate-badge]: https://api.codeclimate.com/v1/badges/c5eb068f806f0b047ea7/maintainability
|
|
49
|
+
[codeclimate-link]: https://codeclimate.com/github/xylabs/sdk-js/maintainability
|
|
50
|
+
[snyk-badge]: https://snyk.io/test/github/xylabs/sdk-js/badge.svg?targetFile=package.json
|
|
51
|
+
[snyk-link]: https://snyk.io/test/github/xylabs/sdk-js?targetFile=package.json
|
|
61
52
|
|
|
62
53
|
[npm-downloads-badge]: https://img.shields.io/npm/dw/@xylabs/enum
|
|
63
54
|
[npm-license-badge]: https://img.shields.io/npm/l/@xylabs/enum
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Transforms a given record object into a readonly "enum-like" structure while preserving
|
|
3
|
+
* the literal types of its values. This allows you to use the returned object both at runtime
|
|
4
|
+
* (for lookups) and at compile time (for strongly typed values).
|
|
5
|
+
*
|
|
6
|
+
* To maintain literal types (i.e., prevent them from being widened to `string`, `number`, etc.),
|
|
7
|
+
* ensure you annotate your object with `as const` before passing it to `Enum`.
|
|
8
|
+
*
|
|
9
|
+
* @template T - A record type with string keys and any kind of values.
|
|
10
|
+
* @param obj - A readonly record object annotated with `as const`.
|
|
11
|
+
* @returns A readonly version of the provided record, preserving exact literal value types.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```typescript
|
|
15
|
+
* // Defining a record with literal types using as const:
|
|
16
|
+
* const DnsRecordType = Enum({
|
|
17
|
+
* A: 1,
|
|
18
|
+
* AAAA: 28,
|
|
19
|
+
* CAA: 257,
|
|
20
|
+
* CNAME: 5,
|
|
21
|
+
* DNAME: 39,
|
|
22
|
+
* MX: 15,
|
|
23
|
+
* NS: 2,
|
|
24
|
+
* PTR: 12,
|
|
25
|
+
* SOA: 6,
|
|
26
|
+
* SPF: 99,
|
|
27
|
+
* SRV: 33,
|
|
28
|
+
* TXT: 16,
|
|
29
|
+
* } as const);
|
|
30
|
+
*
|
|
31
|
+
* // DnsRecordType is now a readonly object:
|
|
32
|
+
* // {
|
|
33
|
+
* // readonly A: 1;
|
|
34
|
+
* // readonly AAAA: 28;
|
|
35
|
+
* // readonly CAA: 257;
|
|
36
|
+
* // readonly CNAME: 5;
|
|
37
|
+
* // readonly DNAME: 39;
|
|
38
|
+
* // readonly MX: 15;
|
|
39
|
+
* // readonly NS: 2;
|
|
40
|
+
* // readonly PTR: 12;
|
|
41
|
+
* // readonly SOA: 6;
|
|
42
|
+
* // readonly SPF: 99;
|
|
43
|
+
* // readonly SRV: 33;
|
|
44
|
+
* // readonly TXT: 16;
|
|
45
|
+
* // }
|
|
46
|
+
* ```
|
|
47
|
+
*/
|
|
48
|
+
export declare const Enum: <const T extends Record<string | number | symbol, unknown>>(obj: Readonly<T>) => Enum<T>;
|
|
49
|
+
/**
|
|
50
|
+
* A utility type that, given a `Record<string, unknown>`, returns a readonly version
|
|
51
|
+
* of that record. This results in a type where all properties of `T` are readonly.
|
|
52
|
+
*
|
|
53
|
+
* @template T - The record type to make readonly.
|
|
54
|
+
*
|
|
55
|
+
* @example
|
|
56
|
+
* ```typescript
|
|
57
|
+
* // Given a record:
|
|
58
|
+
* export const DnsRecordType = Enum({
|
|
59
|
+
* A: 1,
|
|
60
|
+
* AAAA: 28,
|
|
61
|
+
* CAA: 257,
|
|
62
|
+
* CNAME: 5,
|
|
63
|
+
* DNAME: 39,
|
|
64
|
+
* MX: 15,
|
|
65
|
+
* NS: 2,
|
|
66
|
+
* PTR: 12,
|
|
67
|
+
* SOA: 6,
|
|
68
|
+
* SPF: 99,
|
|
69
|
+
* SRV: 33,
|
|
70
|
+
* TXT: 16,
|
|
71
|
+
* })
|
|
72
|
+
*
|
|
73
|
+
* // Now the type inference will preserve the literal types:
|
|
74
|
+
* export type DnsRecordType = Enum<typeof DnsRecordType>
|
|
75
|
+
* ```
|
|
76
|
+
*/
|
|
77
|
+
export type Enum<T extends Readonly<Record<string | number | symbol, unknown>>> = {
|
|
78
|
+
readonly [K in keyof T]: T[K];
|
|
79
|
+
};
|
|
80
|
+
/**
|
|
81
|
+
* A utility type that, given an `Enum` object, returns the union of its keys.
|
|
82
|
+
*/
|
|
83
|
+
export type EnumKey<T extends Record<string | number | symbol, unknown>, K = Enum<T>> = keyof K;
|
|
84
|
+
/**
|
|
85
|
+
* A utility type that, given an `Enum` object, returns the union of its values.
|
|
86
|
+
*/
|
|
87
|
+
export type EnumValue<T extends Record<string | number | symbol, unknown>, K = Enum<T>> = K[keyof K];
|
|
88
|
+
//# sourceMappingURL=Enum.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Enum.d.ts","sourceRoot":"","sources":["../../src/Enum.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8CG;AACH,eAAO,MAAM,IAAI,GAAI,KAAK,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,GAAG,MAAM,GAAG,MAAM,EAAE,OAAO,CAAC,EAAE,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAG,IAAI,CAAC,CAAC,CAExG,CAAA;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,MAAM,MAAM,IAAI,CAAC,CAAC,SAAS,QAAQ,CAAC,MAAM,CAAC,MAAM,GAAG,MAAM,GAAG,MAAM,EAAE,OAAO,CAAC,CAAC,IAAI;IAChF,QAAQ,EAAE,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;CAC9B,CAAA;AAED;;GAEG;AACH,MAAM,MAAM,OAAO,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,GAAG,MAAM,GAAG,MAAM,EAAE,OAAO,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC,IAAI,MAAM,CAAC,CAAA;AAE/F;;GAEG;AACH,MAAM,MAAM,SAAS,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,GAAG,MAAM,GAAG,MAAM,EAAE,OAAO,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,CAAC,CAAA"}
|
package/dist/neutral/index.d.ts
CHANGED
|
@@ -1,90 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
* the literal types of its values. This allows you to use the returned object both at runtime
|
|
4
|
-
* (for lookups) and at compile time (for strongly typed values).
|
|
5
|
-
*
|
|
6
|
-
* To maintain literal types (i.e., prevent them from being widened to `string`, `number`, etc.),
|
|
7
|
-
* ensure you annotate your object with `as const` before passing it to `Enum`.
|
|
8
|
-
*
|
|
9
|
-
* @template T - A record type with string keys and any kind of values.
|
|
10
|
-
* @param obj - A readonly record object annotated with `as const`.
|
|
11
|
-
* @returns A readonly version of the provided record, preserving exact literal value types.
|
|
12
|
-
*
|
|
13
|
-
* @example
|
|
14
|
-
* ```typescript
|
|
15
|
-
* // Defining a record with literal types using as const:
|
|
16
|
-
* const DnsRecordType = Enum({
|
|
17
|
-
* A: 1,
|
|
18
|
-
* AAAA: 28,
|
|
19
|
-
* CAA: 257,
|
|
20
|
-
* CNAME: 5,
|
|
21
|
-
* DNAME: 39,
|
|
22
|
-
* MX: 15,
|
|
23
|
-
* NS: 2,
|
|
24
|
-
* PTR: 12,
|
|
25
|
-
* SOA: 6,
|
|
26
|
-
* SPF: 99,
|
|
27
|
-
* SRV: 33,
|
|
28
|
-
* TXT: 16,
|
|
29
|
-
* } as const);
|
|
30
|
-
*
|
|
31
|
-
* // DnsRecordType is now a readonly object:
|
|
32
|
-
* // {
|
|
33
|
-
* // readonly A: 1;
|
|
34
|
-
* // readonly AAAA: 28;
|
|
35
|
-
* // readonly CAA: 257;
|
|
36
|
-
* // readonly CNAME: 5;
|
|
37
|
-
* // readonly DNAME: 39;
|
|
38
|
-
* // readonly MX: 15;
|
|
39
|
-
* // readonly NS: 2;
|
|
40
|
-
* // readonly PTR: 12;
|
|
41
|
-
* // readonly SOA: 6;
|
|
42
|
-
* // readonly SPF: 99;
|
|
43
|
-
* // readonly SRV: 33;
|
|
44
|
-
* // readonly TXT: 16;
|
|
45
|
-
* // }
|
|
46
|
-
* ```
|
|
47
|
-
*/
|
|
48
|
-
declare const Enum: <const T extends Record<string | number | symbol, unknown>>(obj: Readonly<T>) => Enum<T>;
|
|
49
|
-
/**
|
|
50
|
-
* A utility type that, given a `Record<string, unknown>`, returns a readonly version
|
|
51
|
-
* of that record. This results in a type where all properties of `T` are readonly.
|
|
52
|
-
*
|
|
53
|
-
* @template T - The record type to make readonly.
|
|
54
|
-
*
|
|
55
|
-
* @example
|
|
56
|
-
* ```typescript
|
|
57
|
-
* // Given a record:
|
|
58
|
-
* export const DnsRecordType = Enum({
|
|
59
|
-
* A: 1,
|
|
60
|
-
* AAAA: 28,
|
|
61
|
-
* CAA: 257,
|
|
62
|
-
* CNAME: 5,
|
|
63
|
-
* DNAME: 39,
|
|
64
|
-
* MX: 15,
|
|
65
|
-
* NS: 2,
|
|
66
|
-
* PTR: 12,
|
|
67
|
-
* SOA: 6,
|
|
68
|
-
* SPF: 99,
|
|
69
|
-
* SRV: 33,
|
|
70
|
-
* TXT: 16,
|
|
71
|
-
* })
|
|
72
|
-
*
|
|
73
|
-
* // Now the type inference will preserve the literal types:
|
|
74
|
-
* export type DnsRecordType = Enum<typeof DnsRecordType>
|
|
75
|
-
* ```
|
|
76
|
-
*/
|
|
77
|
-
type Enum<T extends Readonly<Record<string | number | symbol, unknown>>> = {
|
|
78
|
-
readonly [K in keyof T]: T[K];
|
|
79
|
-
};
|
|
80
|
-
/**
|
|
81
|
-
* A utility type that, given an `Enum` object, returns the union of its keys.
|
|
82
|
-
*/
|
|
83
|
-
type EnumKey<T extends Record<string | number | symbol, unknown>, K = Enum<T>> = keyof K;
|
|
84
|
-
/**
|
|
85
|
-
* A utility type that, given an `Enum` object, returns the union of its values.
|
|
86
|
-
*/
|
|
87
|
-
type EnumValue<T extends Record<string | number | symbol, unknown>, K = Enum<T>> = K[keyof K];
|
|
88
|
-
|
|
89
|
-
export { Enum };
|
|
90
|
-
export type { EnumKey, EnumValue };
|
|
1
|
+
export * from './Enum.ts';
|
|
2
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xylabs/enum",
|
|
3
|
-
"version": "4.13.
|
|
3
|
+
"version": "4.13.16",
|
|
4
4
|
"description": "Primary SDK for using XYO Protocol 2.0",
|
|
5
5
|
"homepage": "https://xyo.network",
|
|
6
6
|
"bugs": {
|
|
@@ -29,8 +29,8 @@
|
|
|
29
29
|
"module": "dist/neutral/index.mjs",
|
|
30
30
|
"types": "dist/neutral/index.d.ts",
|
|
31
31
|
"devDependencies": {
|
|
32
|
-
"@xylabs/ts-scripts-yarn3": "^7.0.0-rc.
|
|
33
|
-
"@xylabs/tsconfig": "^7.0.0-rc.
|
|
32
|
+
"@xylabs/ts-scripts-yarn3": "^7.0.0-rc.27",
|
|
33
|
+
"@xylabs/tsconfig": "^7.0.0-rc.27",
|
|
34
34
|
"typescript": "^5.8.3"
|
|
35
35
|
},
|
|
36
36
|
"publishConfig": {
|