@discordjs/util 0.1.0

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/CHANGELOG.md ADDED
@@ -0,0 +1,9 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ # [@discordjs/util@0.1.0](https://github.com/discordjs/discord.js/tree/@discordjs/util@0.1.0) - (2022-10-03)
6
+
7
+ ## Features
8
+
9
+ - Add `@discordjs/util` (#8591) ([b2ec865](https://github.com/discordjs/discord.js/commit/b2ec865765bf94181473864a627fb63ea8173fd3))
package/LICENSE ADDED
@@ -0,0 +1,190 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ Copyright 2022 Noel Buechler
179
+
180
+ Licensed under the Apache License, Version 2.0 (the "License");
181
+ you may not use this file except in compliance with the License.
182
+ You may obtain a copy of the License at
183
+
184
+ http://www.apache.org/licenses/LICENSE-2.0
185
+
186
+ Unless required by applicable law or agreed to in writing, software
187
+ distributed under the License is distributed on an "AS IS" BASIS,
188
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
189
+ See the License for the specific language governing permissions and
190
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,34 @@
1
+ <div align="center">
2
+ <br />
3
+ <p>
4
+ <a href="https://discord.js.org"><img src="https://discord.js.org/static/logo.svg" width="546" alt="discord.js" /></a>
5
+ </p>
6
+ <br />
7
+ <p>
8
+ <a href="https://discord.gg/djs"><img src="https://img.shields.io/discord/222078108977594368?color=5865F2&logo=discord&logoColor=white" alt="Discord server" /></a>
9
+ <a href="https://github.com/discordjs/discord.js/actions"><img src="https://github.com/discordjs/discord.js/actions/workflows/test.yml/badge.svg" alt="Build status" /></a>
10
+ </p>
11
+ <p>
12
+ <a href="https://vercel.com/?utm_source=discordjs&utm_campaign=oss"><img src="https://raw.githubusercontent.com/discordjs/discord.js/main/.github/powered-by-vercel.svg" alt="Vercel" /></a>
13
+ </p>
14
+ </div>
15
+
16
+ ## Links
17
+
18
+ - [Website](https://discord.js.org/) ([source](https://github.com/discordjs/discord.js/tree/main/packages/website))
19
+ - [Documentation](https://discord.js.org/#/docs)
20
+ - [Guide](https://discordjs.guide/) ([source](https://github.com/discordjs/guide))
21
+ See also the [Update Guide](https://discordjs.guide/additional-info/changes-in-v14.html), including updated and removed items in the library.
22
+ - [discord.js Discord server](https://discord.gg/djs)
23
+ - [Discord API Discord server](https://discord.gg/discord-api)
24
+ - [GitHub](https://github.com/discordjs/discord.js/tree/main/packages/scripts)
25
+ - [Related libraries](https://discord.com/developers/docs/topics/community-resources#libraries)
26
+
27
+ ## Contributing
28
+
29
+ See [the contribution guide](https://github.com/discordjs/discord.js/blob/main/.github/CONTRIBUTING.md) if you'd like to submit a PR.
30
+
31
+ ## Help
32
+
33
+ If you don't understand something in the documentation, you are experiencing problems, or you just need a gentle
34
+ nudge in the right direction, please don't hesitate to join our official [discord.js Server](https://discord.gg/djs).
@@ -0,0 +1,76 @@
1
+ /**
2
+ * Represents a type that may or may not be a promise
3
+ */
4
+ declare type Awaitable<T> = PromiseLike<T> | T;
5
+
6
+ /**
7
+ * Lazy is a wrapper around a value that is computed lazily. It is useful for
8
+ * cases where the value is expensive to compute and the computation may not
9
+ * be needed at all.
10
+ *
11
+ * @param cb - The callback to lazily evaluate
12
+ * @typeParam T - The type of the value
13
+ * @example
14
+ * ```ts
15
+ * const value = lazy(() => computeExpensiveValue());
16
+ * ```
17
+ */
18
+ declare function lazy<T>(cb: () => T): () => T;
19
+
20
+ /**
21
+ * Yields the numbers in the given range as an array
22
+ *
23
+ * @param start - The start of the range
24
+ * @param end - The end of the range (inclusive)
25
+ * @param step - The amount to increment between each number
26
+ * @example
27
+ * Basic range
28
+ * ```ts
29
+ * range(3, 5); // [3, 4, 5]
30
+ * ```
31
+ * @example
32
+ * Range with a step
33
+ * ```ts
34
+ * range(3, 10, 2); // [3, 5, 7, 9]
35
+ * ```
36
+ */
37
+ declare function range(start: number, end: number, step?: number): number[];
38
+
39
+ /**
40
+ * Represents an object capable of representing itself as a JSON object
41
+ *
42
+ * @typeParam T - The JSON type corresponding to {@link JSONEncodable.toJSON} outputs.
43
+ */
44
+ interface JSONEncodable<T> {
45
+ /**
46
+ * Transforms this object to its JSON format
47
+ */
48
+ toJSON(): T;
49
+ }
50
+ /**
51
+ * Indicates if an object is encodable or not.
52
+ *
53
+ * @param maybeEncodable - The object to check against
54
+ */
55
+ declare function isJSONEncodable(maybeEncodable: unknown): maybeEncodable is JSONEncodable<unknown>;
56
+
57
+ /**
58
+ * Represents a structure that can be checked against another
59
+ * given structure for equality
60
+ *
61
+ * @typeParam T - The type of object to compare the current object to
62
+ */
63
+ interface Equatable<T> {
64
+ /**
65
+ * Whether or not this is equal to another structure
66
+ */
67
+ equals(other: T): boolean;
68
+ }
69
+ /**
70
+ * Indicates if an object is equatable or not.
71
+ *
72
+ * @param maybeEquatable - The object to check against
73
+ */
74
+ declare function isEquatable(maybeEquatable: unknown): maybeEquatable is Equatable<unknown>;
75
+
76
+ export { Awaitable, Equatable, JSONEncodable, isEquatable, isJSONEncodable, lazy, range };
package/dist/index.js ADDED
@@ -0,0 +1,62 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
+
21
+ // src/index.ts
22
+ var src_exports = {};
23
+ __export(src_exports, {
24
+ isEquatable: () => isEquatable,
25
+ isJSONEncodable: () => isJSONEncodable,
26
+ lazy: () => lazy,
27
+ range: () => range
28
+ });
29
+ module.exports = __toCommonJS(src_exports);
30
+
31
+ // src/functions/lazy.ts
32
+ function lazy(cb) {
33
+ let defaultValue;
34
+ return () => defaultValue ??= cb();
35
+ }
36
+ __name(lazy, "lazy");
37
+
38
+ // src/functions/range.ts
39
+ function range(start, end, step = 1) {
40
+ return Array.from({ length: (end - start) / step + 1 }, (_, index) => start + index * step);
41
+ }
42
+ __name(range, "range");
43
+
44
+ // src/JSONEncodable.ts
45
+ function isJSONEncodable(maybeEncodable) {
46
+ return maybeEncodable !== null && typeof maybeEncodable === "object" && "toJSON" in maybeEncodable;
47
+ }
48
+ __name(isJSONEncodable, "isJSONEncodable");
49
+
50
+ // src/Equatable.ts
51
+ function isEquatable(maybeEquatable) {
52
+ return maybeEquatable !== null && typeof maybeEquatable === "object" && "equals" in maybeEquatable;
53
+ }
54
+ __name(isEquatable, "isEquatable");
55
+ // Annotate the CommonJS export names for ESM import in node:
56
+ 0 && (module.exports = {
57
+ isEquatable,
58
+ isJSONEncodable,
59
+ lazy,
60
+ range
61
+ });
62
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts","../src/functions/lazy.ts","../src/functions/range.ts","../src/JSONEncodable.ts","../src/Equatable.ts"],"sourcesContent":["export * from './types.js';\nexport * from './functions/index.js';\nexport * from './JSONEncodable.js';\nexport * from './Equatable.js';\n","/**\n * Lazy is a wrapper around a value that is computed lazily. It is useful for\n * cases where the value is expensive to compute and the computation may not\n * be needed at all.\n *\n * @param cb - The callback to lazily evaluate\n * @typeParam T - The type of the value\n * @example\n * ```ts\n * const value = lazy(() => computeExpensiveValue());\n * ```\n */\n// eslint-disable-next-line promise/prefer-await-to-callbacks\nexport function lazy<T>(cb: () => T): () => T {\n\tlet defaultValue: T;\n\t// eslint-disable-next-line promise/prefer-await-to-callbacks\n\treturn () => (defaultValue ??= cb());\n}\n","/**\n * Yields the numbers in the given range as an array\n *\n * @param start - The start of the range\n * @param end - The end of the range (inclusive)\n * @param step - The amount to increment between each number\n * @example\n * Basic range\n * ```ts\n * range(3, 5); // [3, 4, 5]\n * ```\n * @example\n * Range with a step\n * ```ts\n * range(3, 10, 2); // [3, 5, 7, 9]\n * ```\n */\nexport function range(start: number, end: number, step = 1): number[] {\n\treturn Array.from({ length: (end - start) / step + 1 }, (_, index) => start + index * step);\n}\n","/**\n * Represents an object capable of representing itself as a JSON object\n *\n * @typeParam T - The JSON type corresponding to {@link JSONEncodable.toJSON} outputs.\n */\nexport interface JSONEncodable<T> {\n\t/**\n\t * Transforms this object to its JSON format\n\t */\n\ttoJSON(): T;\n}\n\n/**\n * Indicates if an object is encodable or not.\n *\n * @param maybeEncodable - The object to check against\n */\nexport function isJSONEncodable(maybeEncodable: unknown): maybeEncodable is JSONEncodable<unknown> {\n\treturn maybeEncodable !== null && typeof maybeEncodable === 'object' && 'toJSON' in maybeEncodable;\n}\n","/**\n * Represents a structure that can be checked against another\n * given structure for equality\n *\n * @typeParam T - The type of object to compare the current object to\n */\nexport interface Equatable<T> {\n\t/**\n\t * Whether or not this is equal to another structure\n\t */\n\tequals(other: T): boolean;\n}\n\n/**\n * Indicates if an object is equatable or not.\n *\n * @param maybeEquatable - The object to check against\n */\nexport function isEquatable(maybeEquatable: unknown): maybeEquatable is Equatable<unknown> {\n\treturn maybeEquatable !== null && typeof maybeEquatable === 'object' && 'equals' in maybeEquatable;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACaO,SAAS,KAAQ,IAAsB;AAC7C,MAAI;AAEJ,SAAO,MAAO,iBAAiB,GAAG;AACnC;AAJgB;;;ACIT,SAAS,MAAM,OAAe,KAAa,OAAO,GAAa;AACrE,SAAO,MAAM,KAAK,EAAE,SAAS,MAAM,SAAS,OAAO,EAAE,GAAG,CAAC,GAAG,UAAU,QAAQ,QAAQ,IAAI;AAC3F;AAFgB;;;ACAT,SAAS,gBAAgB,gBAAmE;AAClG,SAAO,mBAAmB,QAAQ,OAAO,mBAAmB,YAAY,YAAY;AACrF;AAFgB;;;ACCT,SAAS,YAAY,gBAA+D;AAC1F,SAAO,mBAAmB,QAAQ,OAAO,mBAAmB,YAAY,YAAY;AACrF;AAFgB;","names":[]}
package/dist/index.mjs ADDED
@@ -0,0 +1,34 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
+
4
+ // src/functions/lazy.ts
5
+ function lazy(cb) {
6
+ let defaultValue;
7
+ return () => defaultValue ??= cb();
8
+ }
9
+ __name(lazy, "lazy");
10
+
11
+ // src/functions/range.ts
12
+ function range(start, end, step = 1) {
13
+ return Array.from({ length: (end - start) / step + 1 }, (_, index) => start + index * step);
14
+ }
15
+ __name(range, "range");
16
+
17
+ // src/JSONEncodable.ts
18
+ function isJSONEncodable(maybeEncodable) {
19
+ return maybeEncodable !== null && typeof maybeEncodable === "object" && "toJSON" in maybeEncodable;
20
+ }
21
+ __name(isJSONEncodable, "isJSONEncodable");
22
+
23
+ // src/Equatable.ts
24
+ function isEquatable(maybeEquatable) {
25
+ return maybeEquatable !== null && typeof maybeEquatable === "object" && "equals" in maybeEquatable;
26
+ }
27
+ __name(isEquatable, "isEquatable");
28
+ export {
29
+ isEquatable,
30
+ isJSONEncodable,
31
+ lazy,
32
+ range
33
+ };
34
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/functions/lazy.ts","../src/functions/range.ts","../src/JSONEncodable.ts","../src/Equatable.ts"],"sourcesContent":["/**\n * Lazy is a wrapper around a value that is computed lazily. It is useful for\n * cases where the value is expensive to compute and the computation may not\n * be needed at all.\n *\n * @param cb - The callback to lazily evaluate\n * @typeParam T - The type of the value\n * @example\n * ```ts\n * const value = lazy(() => computeExpensiveValue());\n * ```\n */\n// eslint-disable-next-line promise/prefer-await-to-callbacks\nexport function lazy<T>(cb: () => T): () => T {\n\tlet defaultValue: T;\n\t// eslint-disable-next-line promise/prefer-await-to-callbacks\n\treturn () => (defaultValue ??= cb());\n}\n","/**\n * Yields the numbers in the given range as an array\n *\n * @param start - The start of the range\n * @param end - The end of the range (inclusive)\n * @param step - The amount to increment between each number\n * @example\n * Basic range\n * ```ts\n * range(3, 5); // [3, 4, 5]\n * ```\n * @example\n * Range with a step\n * ```ts\n * range(3, 10, 2); // [3, 5, 7, 9]\n * ```\n */\nexport function range(start: number, end: number, step = 1): number[] {\n\treturn Array.from({ length: (end - start) / step + 1 }, (_, index) => start + index * step);\n}\n","/**\n * Represents an object capable of representing itself as a JSON object\n *\n * @typeParam T - The JSON type corresponding to {@link JSONEncodable.toJSON} outputs.\n */\nexport interface JSONEncodable<T> {\n\t/**\n\t * Transforms this object to its JSON format\n\t */\n\ttoJSON(): T;\n}\n\n/**\n * Indicates if an object is encodable or not.\n *\n * @param maybeEncodable - The object to check against\n */\nexport function isJSONEncodable(maybeEncodable: unknown): maybeEncodable is JSONEncodable<unknown> {\n\treturn maybeEncodable !== null && typeof maybeEncodable === 'object' && 'toJSON' in maybeEncodable;\n}\n","/**\n * Represents a structure that can be checked against another\n * given structure for equality\n *\n * @typeParam T - The type of object to compare the current object to\n */\nexport interface Equatable<T> {\n\t/**\n\t * Whether or not this is equal to another structure\n\t */\n\tequals(other: T): boolean;\n}\n\n/**\n * Indicates if an object is equatable or not.\n *\n * @param maybeEquatable - The object to check against\n */\nexport function isEquatable(maybeEquatable: unknown): maybeEquatable is Equatable<unknown> {\n\treturn maybeEquatable !== null && typeof maybeEquatable === 'object' && 'equals' in maybeEquatable;\n}\n"],"mappings":";;;;AAaO,SAAS,KAAQ,IAAsB;AAC7C,MAAI;AAEJ,SAAO,MAAO,iBAAiB,GAAG;AACnC;AAJgB;;;ACIT,SAAS,MAAM,OAAe,KAAa,OAAO,GAAa;AACrE,SAAO,MAAM,KAAK,EAAE,SAAS,MAAM,SAAS,OAAO,EAAE,GAAG,CAAC,GAAG,UAAU,QAAQ,QAAQ,IAAI;AAC3F;AAFgB;;;ACAT,SAAS,gBAAgB,gBAAmE;AAClG,SAAO,mBAAmB,QAAQ,OAAO,mBAAmB,YAAY,YAAY;AACrF;AAFgB;;;ACCT,SAAS,YAAY,gBAA+D;AAC1F,SAAO,mBAAmB,QAAQ,OAAO,mBAAmB,YAAY,YAAY;AACrF;AAFgB;","names":[]}
package/package.json ADDED
@@ -0,0 +1,77 @@
1
+ {
2
+ "name": "@discordjs/util",
3
+ "version": "0.1.0",
4
+ "description": "Utilities shared across Discord.js packages",
5
+ "scripts": {
6
+ "build": "tsup",
7
+ "test": "vitest run && tsd",
8
+ "lint": "prettier --check . && TIMING=1 eslint src --ext mjs,js,ts",
9
+ "format": "prettier --write . && TIMING=1 eslint src --ext mjs,js,ts --fix",
10
+ "fmt": "yarn format",
11
+ "docs": "downlevel-dts dist docs/dist --to=3.7 && api-extractor run --local",
12
+ "prepack": "yarn lint && yarn test && yarn build",
13
+ "changelog": "git cliff --prepend ./CHANGELOG.md -u -c ./cliff.toml -r ../../ --include-path 'packages/util/*'",
14
+ "release": "cliff-jumper"
15
+ },
16
+ "main": "./dist/index.js",
17
+ "module": "./dist/index.mjs",
18
+ "types": "./dist/index.d.ts",
19
+ "exports": {
20
+ "import": "./dist/index.mjs",
21
+ "require": "./dist/index.js",
22
+ "types": "./dist/index.d.ts"
23
+ },
24
+ "directories": {
25
+ "lib": "src"
26
+ },
27
+ "files": [
28
+ "dist"
29
+ ],
30
+ "contributors": [
31
+ "Crawl <icrawltogo@gmail.com>",
32
+ "Amish Shah <amishshah.2k@gmail.com>",
33
+ "Vlad Frangu <kingdgrizzle@gmail.com>",
34
+ "SpaceEEC <spaceeec@yahoo.com>",
35
+ "Aura Román <kyradiscord@gmail.com>"
36
+ ],
37
+ "license": "Apache-2.0",
38
+ "keywords": [
39
+ "api",
40
+ "bot",
41
+ "client",
42
+ "node",
43
+ "discordjs"
44
+ ],
45
+ "repository": {
46
+ "type": "git",
47
+ "url": "https://github.com/discordjs/discord.js.git"
48
+ },
49
+ "bugs": {
50
+ "url": "https://github.com/discordjs/discord.js/issues"
51
+ },
52
+ "homepage": "https://discord.js.org",
53
+ "devDependencies": {
54
+ "@favware/cliff-jumper": "^1.8.8",
55
+ "@microsoft/api-extractor": "^7.32.0",
56
+ "@types/node": "^16.11.56",
57
+ "@vitest/coverage-c8": "^0.22.1",
58
+ "cross-env": "^7.0.3",
59
+ "downlevel-dts": "^0.10.1",
60
+ "eslint": "^8.23.0",
61
+ "eslint-config-neon": "^0.1.31",
62
+ "prettier": "^2.7.1",
63
+ "tsd": "^0.23.0",
64
+ "tsup": "^6.2.3",
65
+ "typescript": "^4.8.2",
66
+ "vitest": "^0.22.1"
67
+ },
68
+ "engines": {
69
+ "node": ">=16.9.0"
70
+ },
71
+ "publishConfig": {
72
+ "access": "public"
73
+ },
74
+ "tsd": {
75
+ "directory": "__tests__/types"
76
+ }
77
+ }