@discordjs/formatters 0.1.1-dev.1670026137-a0d6bc4.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/LICENSE +191 -0
- package/README.md +80 -0
- package/dist/index.d.ts +278 -0
- package/dist/index.js +177 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +132 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +69 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,191 @@
|
|
|
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 2021 Noel Buechler
|
|
179
|
+
Copyright 2021 Vlad Frangu
|
|
180
|
+
|
|
181
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
182
|
+
you may not use this file except in compliance with the License.
|
|
183
|
+
You may obtain a copy of the License at
|
|
184
|
+
|
|
185
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
186
|
+
|
|
187
|
+
Unless required by applicable law or agreed to in writing, software
|
|
188
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
189
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
190
|
+
See the License for the specific language governing permissions and
|
|
191
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
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://www.npmjs.com/package/@discordjs/formatters"><img src="https://img.shields.io/npm/v/@discordjs/formatters.svg?maxAge=3600" alt="npm version" /></a>
|
|
10
|
+
<a href="https://www.npmjs.com/package/@discordjs/formatters"><img src="https://img.shields.io/npm/dt/@discordjs/formatters.svg?maxAge=3600" alt="npm downloads" /></a>
|
|
11
|
+
<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>
|
|
12
|
+
<a href="https://codecov.io/gh/discordjs/discord.js" ><img src="https://codecov.io/gh/discordjs/discord.js/branch/main/graph/badge.svg?precision=2&flag=formatters" alt="Code coverage" /></a>
|
|
13
|
+
</p>
|
|
14
|
+
<p>
|
|
15
|
+
<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>
|
|
16
|
+
</p>
|
|
17
|
+
</div>
|
|
18
|
+
|
|
19
|
+
## About
|
|
20
|
+
|
|
21
|
+
`@discordjs/formatters` set of functions to format strings for Discord.
|
|
22
|
+
|
|
23
|
+
## Installation
|
|
24
|
+
|
|
25
|
+
**Node.js 16.9.0 or newer is required.**
|
|
26
|
+
|
|
27
|
+
```sh-session
|
|
28
|
+
npm install @discordjs/formatters
|
|
29
|
+
yarn add @discordjs/formatters
|
|
30
|
+
pnpm add @discordjs/formatters
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## Example usage
|
|
34
|
+
|
|
35
|
+
````ts
|
|
36
|
+
import { codeBlock } from '@discordjs/formatters';
|
|
37
|
+
|
|
38
|
+
const formattedCode = codeBlock('hello world!');
|
|
39
|
+
console.log(formattedCode);
|
|
40
|
+
|
|
41
|
+
// Prints:
|
|
42
|
+
// ```
|
|
43
|
+
// hello world!
|
|
44
|
+
// ```
|
|
45
|
+
````
|
|
46
|
+
|
|
47
|
+
## Links
|
|
48
|
+
|
|
49
|
+
- [Website][website] ([source][website-source])
|
|
50
|
+
- [Documentation][documentation]
|
|
51
|
+
- [Guide][guide] ([source][guide-source])
|
|
52
|
+
See also the [Update Guide][guide-update], including updated and removed items in the library.
|
|
53
|
+
- [discord.js Discord server][discord]
|
|
54
|
+
- [Discord API Discord server][discord-api]
|
|
55
|
+
- [GitHub][source]
|
|
56
|
+
- [npm][npm]
|
|
57
|
+
- [Related libraries][related-libs]
|
|
58
|
+
|
|
59
|
+
## Contributing
|
|
60
|
+
|
|
61
|
+
Before creating an issue, please ensure that it hasn't already been reported/suggested, and double-check the
|
|
62
|
+
[documentation][documentation].
|
|
63
|
+
See [the contribution guide][contributing] if you'd like to submit a PR.
|
|
64
|
+
|
|
65
|
+
## Help
|
|
66
|
+
|
|
67
|
+
If you don't understand something in the documentation, you are experiencing problems, or you just need a gentle nudge in the right direction, please don't hesitate to join our official [discord.js Server][discord].
|
|
68
|
+
|
|
69
|
+
[website]: https://discord.js.org/
|
|
70
|
+
[website-source]: https://github.com/discordjs/discord.js/tree/main/apps/website
|
|
71
|
+
[documentation]: https://discord.js.org/
|
|
72
|
+
[guide]: https://discordjs.guide/
|
|
73
|
+
[guide-source]: https://github.com/discordjs/guide
|
|
74
|
+
[guide-update]: https://discordjs.guide/additional-info/changes-in-v14.html
|
|
75
|
+
[discord]: https://discord.gg/djs
|
|
76
|
+
[discord-api]: https://discord.gg/discord-api
|
|
77
|
+
[source]: https://github.com/discordjs/discord.js/tree/main/packages/formatters
|
|
78
|
+
[npm]: https://www.npmjs.com/package/@discordjs/formatters
|
|
79
|
+
[related-libs]: https://discord.com/developers/docs/topics/community-resources#libraries
|
|
80
|
+
[contributing]: https://github.com/discordjs/discord.js/blob/main/.github/CONTRIBUTING.md
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,278 @@
|
|
|
1
|
+
import { URL } from 'node:url';
|
|
2
|
+
import { Snowflake } from 'discord-api-types/globals';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Wraps the content inside a codeblock with no language
|
|
6
|
+
*
|
|
7
|
+
* @param content - The content to wrap
|
|
8
|
+
*/
|
|
9
|
+
declare function codeBlock<C extends string>(content: C): `\`\`\`\n${C}\n\`\`\``;
|
|
10
|
+
/**
|
|
11
|
+
* Wraps the content inside a codeblock with the specified language
|
|
12
|
+
*
|
|
13
|
+
* @param language - The language for the codeblock
|
|
14
|
+
* @param content - The content to wrap
|
|
15
|
+
*/
|
|
16
|
+
declare function codeBlock<L extends string, C extends string>(language: L, content: C): `\`\`\`${L}\n${C}\n\`\`\``;
|
|
17
|
+
/**
|
|
18
|
+
* Wraps the content inside \`backticks\`, which formats it as inline code
|
|
19
|
+
*
|
|
20
|
+
* @param content - The content to wrap
|
|
21
|
+
*/
|
|
22
|
+
declare function inlineCode<C extends string>(content: C): `\`${C}\``;
|
|
23
|
+
/**
|
|
24
|
+
* Formats the content into italic text
|
|
25
|
+
*
|
|
26
|
+
* @param content - The content to wrap
|
|
27
|
+
*/
|
|
28
|
+
declare function italic<C extends string>(content: C): `_${C}_`;
|
|
29
|
+
/**
|
|
30
|
+
* Formats the content into bold text
|
|
31
|
+
*
|
|
32
|
+
* @param content - The content to wrap
|
|
33
|
+
*/
|
|
34
|
+
declare function bold<C extends string>(content: C): `**${C}**`;
|
|
35
|
+
/**
|
|
36
|
+
* Formats the content into underscored text
|
|
37
|
+
*
|
|
38
|
+
* @param content - The content to wrap
|
|
39
|
+
*/
|
|
40
|
+
declare function underscore<C extends string>(content: C): `__${C}__`;
|
|
41
|
+
/**
|
|
42
|
+
* Formats the content into strike-through text
|
|
43
|
+
*
|
|
44
|
+
* @param content - The content to wrap
|
|
45
|
+
*/
|
|
46
|
+
declare function strikethrough<C extends string>(content: C): `~~${C}~~`;
|
|
47
|
+
/**
|
|
48
|
+
* Formats the content into a quote. This needs to be at the start of the line for Discord to format it
|
|
49
|
+
*
|
|
50
|
+
* @param content - The content to wrap
|
|
51
|
+
*/
|
|
52
|
+
declare function quote<C extends string>(content: C): `> ${C}`;
|
|
53
|
+
/**
|
|
54
|
+
* Formats the content into a block quote. This needs to be at the start of the line for Discord to format it
|
|
55
|
+
*
|
|
56
|
+
* @param content - The content to wrap
|
|
57
|
+
*/
|
|
58
|
+
declare function blockQuote<C extends string>(content: C): `>>> ${C}`;
|
|
59
|
+
/**
|
|
60
|
+
* Wraps the URL into `<>`, which stops it from embedding
|
|
61
|
+
*
|
|
62
|
+
* @param url - The URL to wrap
|
|
63
|
+
*/
|
|
64
|
+
declare function hideLinkEmbed<C extends string>(url: C): `<${C}>`;
|
|
65
|
+
/**
|
|
66
|
+
* Wraps the URL into `<>`, which stops it from embedding
|
|
67
|
+
*
|
|
68
|
+
* @param url - The URL to wrap
|
|
69
|
+
*/
|
|
70
|
+
declare function hideLinkEmbed(url: URL): `<${string}>`;
|
|
71
|
+
/**
|
|
72
|
+
* Formats the content and the URL into a masked URL
|
|
73
|
+
*
|
|
74
|
+
* @param content - The content to display
|
|
75
|
+
* @param url - The URL the content links to
|
|
76
|
+
*/
|
|
77
|
+
declare function hyperlink<C extends string>(content: C, url: URL): `[${C}](${string})`;
|
|
78
|
+
/**
|
|
79
|
+
* Formats the content and the URL into a masked URL
|
|
80
|
+
*
|
|
81
|
+
* @param content - The content to display
|
|
82
|
+
* @param url - The URL the content links to
|
|
83
|
+
*/
|
|
84
|
+
declare function hyperlink<C extends string, U extends string>(content: C, url: U): `[${C}](${U})`;
|
|
85
|
+
/**
|
|
86
|
+
* Formats the content and the URL into a masked URL
|
|
87
|
+
*
|
|
88
|
+
* @param content - The content to display
|
|
89
|
+
* @param url - The URL the content links to
|
|
90
|
+
* @param title - The title shown when hovering on the masked link
|
|
91
|
+
*/
|
|
92
|
+
declare function hyperlink<C extends string, T extends string>(content: C, url: URL, title: T): `[${C}](${string} "${T}")`;
|
|
93
|
+
/**
|
|
94
|
+
* Formats the content and the URL into a masked URL
|
|
95
|
+
*
|
|
96
|
+
* @param content - The content to display
|
|
97
|
+
* @param url - The URL the content links to
|
|
98
|
+
* @param title - The title shown when hovering on the masked link
|
|
99
|
+
*/
|
|
100
|
+
declare function hyperlink<C extends string, U extends string, T extends string>(content: C, url: U, title: T): `[${C}](${U} "${T}")`;
|
|
101
|
+
/**
|
|
102
|
+
* Wraps the content inside spoiler (hidden text)
|
|
103
|
+
*
|
|
104
|
+
* @param content - The content to wrap
|
|
105
|
+
*/
|
|
106
|
+
declare function spoiler<C extends string>(content: C): `||${C}||`;
|
|
107
|
+
/**
|
|
108
|
+
* Formats a user ID into a user mention
|
|
109
|
+
*
|
|
110
|
+
* @param userId - The user ID to format
|
|
111
|
+
*/
|
|
112
|
+
declare function userMention<C extends Snowflake>(userId: C): `<@${C}>`;
|
|
113
|
+
/**
|
|
114
|
+
* Formats a channel ID into a channel mention
|
|
115
|
+
*
|
|
116
|
+
* @param channelId - The channel ID to format
|
|
117
|
+
*/
|
|
118
|
+
declare function channelMention<C extends Snowflake>(channelId: C): `<#${C}>`;
|
|
119
|
+
/**
|
|
120
|
+
* Formats a role ID into a role mention
|
|
121
|
+
*
|
|
122
|
+
* @param roleId - The role ID to format
|
|
123
|
+
*/
|
|
124
|
+
declare function roleMention<C extends Snowflake>(roleId: C): `<@&${C}>`;
|
|
125
|
+
/**
|
|
126
|
+
* Formats an application command name, subcommand group name, subcommand name, and ID into an application command mention
|
|
127
|
+
*
|
|
128
|
+
* @param commandName - The application command name to format
|
|
129
|
+
* @param subcommandGroupName - The subcommand group name to format
|
|
130
|
+
* @param subcommandName - The subcommand name to format
|
|
131
|
+
* @param commandId - The application command ID to format
|
|
132
|
+
*/
|
|
133
|
+
declare function chatInputApplicationCommandMention<N extends string, G extends string, S extends string, I extends Snowflake>(commandName: N, subcommandGroupName: G, subcommandName: S, commandId: I): `</${N} ${G} ${S}:${I}>`;
|
|
134
|
+
/**
|
|
135
|
+
* Formats an application command name, subcommand name, and ID into an application command mention
|
|
136
|
+
*
|
|
137
|
+
* @param commandName - The application command name to format
|
|
138
|
+
* @param subcommandName - The subcommand name to format
|
|
139
|
+
* @param commandId - The application command ID to format
|
|
140
|
+
*/
|
|
141
|
+
declare function chatInputApplicationCommandMention<N extends string, S extends string, I extends Snowflake>(commandName: N, subcommandName: S, commandId: I): `</${N} ${S}:${I}>`;
|
|
142
|
+
/**
|
|
143
|
+
* Formats an application command name and ID into an application command mention
|
|
144
|
+
*
|
|
145
|
+
* @param commandName - The application command name to format
|
|
146
|
+
* @param commandId - The application command ID to format
|
|
147
|
+
*/
|
|
148
|
+
declare function chatInputApplicationCommandMention<N extends string, I extends Snowflake>(commandName: N, commandId: I): `</${N}:${I}>`;
|
|
149
|
+
/**
|
|
150
|
+
* Formats an emoji ID into a fully qualified emoji identifier
|
|
151
|
+
*
|
|
152
|
+
* @param emojiId - The emoji ID to format
|
|
153
|
+
*/
|
|
154
|
+
declare function formatEmoji<C extends Snowflake>(emojiId: C, animated?: false): `<:_:${C}>`;
|
|
155
|
+
/**
|
|
156
|
+
* Formats an emoji ID into a fully qualified emoji identifier
|
|
157
|
+
*
|
|
158
|
+
* @param emojiId - The emoji ID to format
|
|
159
|
+
* @param animated - Whether the emoji is animated or not. Defaults to `false`
|
|
160
|
+
*/
|
|
161
|
+
declare function formatEmoji<C extends Snowflake>(emojiId: C, animated?: true): `<a:_:${C}>`;
|
|
162
|
+
/**
|
|
163
|
+
* Formats an emoji ID into a fully qualified emoji identifier
|
|
164
|
+
*
|
|
165
|
+
* @param emojiId - The emoji ID to format
|
|
166
|
+
* @param animated - Whether the emoji is animated or not. Defaults to `false`
|
|
167
|
+
*/
|
|
168
|
+
declare function formatEmoji<C extends Snowflake>(emojiId: C, animated?: boolean): `<:_:${C}>` | `<a:_:${C}>`;
|
|
169
|
+
/**
|
|
170
|
+
* Formats a channel link for a direct message channel.
|
|
171
|
+
*
|
|
172
|
+
* @param channelId - The channel's id
|
|
173
|
+
*/
|
|
174
|
+
declare function channelLink<C extends Snowflake>(channelId: C): `https://discord.com/channels/@me/${C}`;
|
|
175
|
+
/**
|
|
176
|
+
* Formats a channel link for a guild channel.
|
|
177
|
+
*
|
|
178
|
+
* @param channelId - The channel's id
|
|
179
|
+
* @param guildId - The guild's id
|
|
180
|
+
*/
|
|
181
|
+
declare function channelLink<C extends Snowflake, G extends Snowflake>(channelId: C, guildId: G): `https://discord.com/channels/${G}/${C}`;
|
|
182
|
+
/**
|
|
183
|
+
* Formats a message link for a direct message channel.
|
|
184
|
+
*
|
|
185
|
+
* @param channelId - The channel's id
|
|
186
|
+
* @param messageId - The message's id
|
|
187
|
+
*/
|
|
188
|
+
declare function messageLink<C extends Snowflake, M extends Snowflake>(channelId: C, messageId: M): `https://discord.com/channels/@me/${C}/${M}`;
|
|
189
|
+
/**
|
|
190
|
+
* Formats a message link for a guild channel.
|
|
191
|
+
*
|
|
192
|
+
* @param channelId - The channel's id
|
|
193
|
+
* @param messageId - The message's id
|
|
194
|
+
* @param guildId - The guild's id
|
|
195
|
+
*/
|
|
196
|
+
declare function messageLink<C extends Snowflake, M extends Snowflake, G extends Snowflake>(channelId: C, messageId: M, guildId: G): `https://discord.com/channels/${G}/${C}/${M}`;
|
|
197
|
+
/**
|
|
198
|
+
* Formats a date into a short date-time string
|
|
199
|
+
*
|
|
200
|
+
* @param date - The date to format, defaults to the current time
|
|
201
|
+
*/
|
|
202
|
+
declare function time(date?: Date): `<t:${bigint}>`;
|
|
203
|
+
/**
|
|
204
|
+
* Formats a date given a format style
|
|
205
|
+
*
|
|
206
|
+
* @param date - The date to format
|
|
207
|
+
* @param style - The style to use
|
|
208
|
+
*/
|
|
209
|
+
declare function time<S extends TimestampStylesString>(date: Date, style: S): `<t:${bigint}:${S}>`;
|
|
210
|
+
/**
|
|
211
|
+
* Formats the given timestamp into a short date-time string
|
|
212
|
+
*
|
|
213
|
+
* @param seconds - The time to format, represents an UNIX timestamp in seconds
|
|
214
|
+
*/
|
|
215
|
+
declare function time<C extends number>(seconds: C): `<t:${C}>`;
|
|
216
|
+
/**
|
|
217
|
+
* Formats the given timestamp into a short date-time string
|
|
218
|
+
*
|
|
219
|
+
* @param seconds - The time to format, represents an UNIX timestamp in seconds
|
|
220
|
+
* @param style - The style to use
|
|
221
|
+
*/
|
|
222
|
+
declare function time<C extends number, S extends TimestampStylesString>(seconds: C, style: S): `<t:${C}:${S}>`;
|
|
223
|
+
/**
|
|
224
|
+
* The {@link https://discord.com/developers/docs/reference#message-formatting-timestamp-styles | message formatting timestamp styles} supported by Discord
|
|
225
|
+
*/
|
|
226
|
+
declare const TimestampStyles: {
|
|
227
|
+
/**
|
|
228
|
+
* Short time format, consisting of hours and minutes, e.g. 16:20
|
|
229
|
+
*/
|
|
230
|
+
readonly ShortTime: "t";
|
|
231
|
+
/**
|
|
232
|
+
* Long time format, consisting of hours, minutes, and seconds, e.g. 16:20:30
|
|
233
|
+
*/
|
|
234
|
+
readonly LongTime: "T";
|
|
235
|
+
/**
|
|
236
|
+
* Short date format, consisting of day, month, and year, e.g. 20/04/2021
|
|
237
|
+
*/
|
|
238
|
+
readonly ShortDate: "d";
|
|
239
|
+
/**
|
|
240
|
+
* Long date format, consisting of day, month, and year, e.g. 20 April 2021
|
|
241
|
+
*/
|
|
242
|
+
readonly LongDate: "D";
|
|
243
|
+
/**
|
|
244
|
+
* Short date-time format, consisting of short date and short time formats, e.g. 20 April 2021 16:20
|
|
245
|
+
*/
|
|
246
|
+
readonly ShortDateTime: "f";
|
|
247
|
+
/**
|
|
248
|
+
* Long date-time format, consisting of long date and short time formats, e.g. Tuesday, 20 April 2021 16:20
|
|
249
|
+
*/
|
|
250
|
+
readonly LongDateTime: "F";
|
|
251
|
+
/**
|
|
252
|
+
* Relative time format, consisting of a relative duration format, e.g. 2 months ago
|
|
253
|
+
*/
|
|
254
|
+
readonly RelativeTime: "R";
|
|
255
|
+
};
|
|
256
|
+
/**
|
|
257
|
+
* The possible values, see {@link TimestampStyles} for more information
|
|
258
|
+
*/
|
|
259
|
+
type TimestampStylesString = typeof TimestampStyles[keyof typeof TimestampStyles];
|
|
260
|
+
/**
|
|
261
|
+
* An enum with all the available faces from Discord's native slash commands
|
|
262
|
+
*/
|
|
263
|
+
declare enum Faces {
|
|
264
|
+
/**
|
|
265
|
+
* ¯\\_(ツ)\\_/¯
|
|
266
|
+
*/
|
|
267
|
+
Shrug = "\u00AF\\_(\u30C4)\\_/\u00AF",
|
|
268
|
+
/**
|
|
269
|
+
* (╯°□°)╯︵ ┻━┻
|
|
270
|
+
*/
|
|
271
|
+
Tableflip = "(\u256F\u00B0\u25A1\u00B0\uFF09\u256F\uFE35 \u253B\u2501\u253B",
|
|
272
|
+
/**
|
|
273
|
+
* ┬─┬ ノ( ゜-゜ノ)
|
|
274
|
+
*/
|
|
275
|
+
Unflip = "\u252C\u2500\u252C \u30CE( \u309C-\u309C\u30CE)"
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
export { Faces, TimestampStyles, TimestampStylesString, blockQuote, bold, channelLink, channelMention, chatInputApplicationCommandMention, codeBlock, formatEmoji, hideLinkEmbed, hyperlink, inlineCode, italic, messageLink, quote, roleMention, spoiler, strikethrough, time, underscore, userMention };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,177 @@
|
|
|
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
|
+
Faces: () => Faces,
|
|
25
|
+
TimestampStyles: () => TimestampStyles,
|
|
26
|
+
blockQuote: () => blockQuote,
|
|
27
|
+
bold: () => bold,
|
|
28
|
+
channelLink: () => channelLink,
|
|
29
|
+
channelMention: () => channelMention,
|
|
30
|
+
chatInputApplicationCommandMention: () => chatInputApplicationCommandMention,
|
|
31
|
+
codeBlock: () => codeBlock,
|
|
32
|
+
formatEmoji: () => formatEmoji,
|
|
33
|
+
hideLinkEmbed: () => hideLinkEmbed,
|
|
34
|
+
hyperlink: () => hyperlink,
|
|
35
|
+
inlineCode: () => inlineCode,
|
|
36
|
+
italic: () => italic,
|
|
37
|
+
messageLink: () => messageLink,
|
|
38
|
+
quote: () => quote,
|
|
39
|
+
roleMention: () => roleMention,
|
|
40
|
+
spoiler: () => spoiler,
|
|
41
|
+
strikethrough: () => strikethrough,
|
|
42
|
+
time: () => time,
|
|
43
|
+
underscore: () => underscore,
|
|
44
|
+
userMention: () => userMention
|
|
45
|
+
});
|
|
46
|
+
module.exports = __toCommonJS(src_exports);
|
|
47
|
+
|
|
48
|
+
// src/formatters.ts
|
|
49
|
+
function codeBlock(language, content) {
|
|
50
|
+
return typeof content === "undefined" ? `\`\`\`
|
|
51
|
+
${language}
|
|
52
|
+
\`\`\`` : `\`\`\`${language}
|
|
53
|
+
${content}
|
|
54
|
+
\`\`\``;
|
|
55
|
+
}
|
|
56
|
+
__name(codeBlock, "codeBlock");
|
|
57
|
+
function inlineCode(content) {
|
|
58
|
+
return `\`${content}\``;
|
|
59
|
+
}
|
|
60
|
+
__name(inlineCode, "inlineCode");
|
|
61
|
+
function italic(content) {
|
|
62
|
+
return `_${content}_`;
|
|
63
|
+
}
|
|
64
|
+
__name(italic, "italic");
|
|
65
|
+
function bold(content) {
|
|
66
|
+
return `**${content}**`;
|
|
67
|
+
}
|
|
68
|
+
__name(bold, "bold");
|
|
69
|
+
function underscore(content) {
|
|
70
|
+
return `__${content}__`;
|
|
71
|
+
}
|
|
72
|
+
__name(underscore, "underscore");
|
|
73
|
+
function strikethrough(content) {
|
|
74
|
+
return `~~${content}~~`;
|
|
75
|
+
}
|
|
76
|
+
__name(strikethrough, "strikethrough");
|
|
77
|
+
function quote(content) {
|
|
78
|
+
return `> ${content}`;
|
|
79
|
+
}
|
|
80
|
+
__name(quote, "quote");
|
|
81
|
+
function blockQuote(content) {
|
|
82
|
+
return `>>> ${content}`;
|
|
83
|
+
}
|
|
84
|
+
__name(blockQuote, "blockQuote");
|
|
85
|
+
function hideLinkEmbed(url) {
|
|
86
|
+
return `<${url}>`;
|
|
87
|
+
}
|
|
88
|
+
__name(hideLinkEmbed, "hideLinkEmbed");
|
|
89
|
+
function hyperlink(content, url, title) {
|
|
90
|
+
return title ? `[${content}](${url} "${title}")` : `[${content}](${url})`;
|
|
91
|
+
}
|
|
92
|
+
__name(hyperlink, "hyperlink");
|
|
93
|
+
function spoiler(content) {
|
|
94
|
+
return `||${content}||`;
|
|
95
|
+
}
|
|
96
|
+
__name(spoiler, "spoiler");
|
|
97
|
+
function userMention(userId) {
|
|
98
|
+
return `<@${userId}>`;
|
|
99
|
+
}
|
|
100
|
+
__name(userMention, "userMention");
|
|
101
|
+
function channelMention(channelId) {
|
|
102
|
+
return `<#${channelId}>`;
|
|
103
|
+
}
|
|
104
|
+
__name(channelMention, "channelMention");
|
|
105
|
+
function roleMention(roleId) {
|
|
106
|
+
return `<@&${roleId}>`;
|
|
107
|
+
}
|
|
108
|
+
__name(roleMention, "roleMention");
|
|
109
|
+
function chatInputApplicationCommandMention(commandName, subcommandGroupName, subcommandName, commandId) {
|
|
110
|
+
if (typeof commandId !== "undefined") {
|
|
111
|
+
return `</${commandName} ${subcommandGroupName} ${subcommandName}:${commandId}>`;
|
|
112
|
+
}
|
|
113
|
+
if (typeof subcommandName !== "undefined") {
|
|
114
|
+
return `</${commandName} ${subcommandGroupName}:${subcommandName}>`;
|
|
115
|
+
}
|
|
116
|
+
return `</${commandName}:${subcommandGroupName}>`;
|
|
117
|
+
}
|
|
118
|
+
__name(chatInputApplicationCommandMention, "chatInputApplicationCommandMention");
|
|
119
|
+
function formatEmoji(emojiId, animated = false) {
|
|
120
|
+
return `<${animated ? "a" : ""}:_:${emojiId}>`;
|
|
121
|
+
}
|
|
122
|
+
__name(formatEmoji, "formatEmoji");
|
|
123
|
+
function channelLink(channelId, guildId) {
|
|
124
|
+
return `https://discord.com/channels/${guildId ?? "@me"}/${channelId}`;
|
|
125
|
+
}
|
|
126
|
+
__name(channelLink, "channelLink");
|
|
127
|
+
function messageLink(channelId, messageId, guildId) {
|
|
128
|
+
return `${typeof guildId === "undefined" ? channelLink(channelId) : channelLink(channelId, guildId)}/${messageId}`;
|
|
129
|
+
}
|
|
130
|
+
__name(messageLink, "messageLink");
|
|
131
|
+
function time(timeOrSeconds, style) {
|
|
132
|
+
if (typeof timeOrSeconds !== "number") {
|
|
133
|
+
timeOrSeconds = Math.floor((timeOrSeconds?.getTime() ?? Date.now()) / 1e3);
|
|
134
|
+
}
|
|
135
|
+
return typeof style === "string" ? `<t:${timeOrSeconds}:${style}>` : `<t:${timeOrSeconds}>`;
|
|
136
|
+
}
|
|
137
|
+
__name(time, "time");
|
|
138
|
+
var TimestampStyles = {
|
|
139
|
+
ShortTime: "t",
|
|
140
|
+
LongTime: "T",
|
|
141
|
+
ShortDate: "d",
|
|
142
|
+
LongDate: "D",
|
|
143
|
+
ShortDateTime: "f",
|
|
144
|
+
LongDateTime: "F",
|
|
145
|
+
RelativeTime: "R"
|
|
146
|
+
};
|
|
147
|
+
var Faces = /* @__PURE__ */ ((Faces2) => {
|
|
148
|
+
Faces2["Shrug"] = "\xAF\\_(\u30C4)\\_/\xAF";
|
|
149
|
+
Faces2["Tableflip"] = "(\u256F\xB0\u25A1\xB0\uFF09\u256F\uFE35 \u253B\u2501\u253B";
|
|
150
|
+
Faces2["Unflip"] = "\u252C\u2500\u252C \u30CE( \u309C-\u309C\u30CE)";
|
|
151
|
+
return Faces2;
|
|
152
|
+
})(Faces || {});
|
|
153
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
154
|
+
0 && (module.exports = {
|
|
155
|
+
Faces,
|
|
156
|
+
TimestampStyles,
|
|
157
|
+
blockQuote,
|
|
158
|
+
bold,
|
|
159
|
+
channelLink,
|
|
160
|
+
channelMention,
|
|
161
|
+
chatInputApplicationCommandMention,
|
|
162
|
+
codeBlock,
|
|
163
|
+
formatEmoji,
|
|
164
|
+
hideLinkEmbed,
|
|
165
|
+
hyperlink,
|
|
166
|
+
inlineCode,
|
|
167
|
+
italic,
|
|
168
|
+
messageLink,
|
|
169
|
+
quote,
|
|
170
|
+
roleMention,
|
|
171
|
+
spoiler,
|
|
172
|
+
strikethrough,
|
|
173
|
+
time,
|
|
174
|
+
underscore,
|
|
175
|
+
userMention
|
|
176
|
+
});
|
|
177
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/formatters.ts"],"sourcesContent":["export * from './formatters.js';\n","import type { URL } from 'node:url';\nimport type { Snowflake } from 'discord-api-types/globals';\n\n/**\n * Wraps the content inside a codeblock with no language\n *\n * @param content - The content to wrap\n */\nexport function codeBlock<C extends string>(content: C): `\\`\\`\\`\\n${C}\\n\\`\\`\\``;\n\n/**\n * Wraps the content inside a codeblock with the specified language\n *\n * @param language - The language for the codeblock\n * @param content - The content to wrap\n */\nexport function codeBlock<L extends string, C extends string>(language: L, content: C): `\\`\\`\\`${L}\\n${C}\\n\\`\\`\\``;\nexport function codeBlock(language: string, content?: string): string {\n\treturn typeof content === 'undefined' ? `\\`\\`\\`\\n${language}\\n\\`\\`\\`` : `\\`\\`\\`${language}\\n${content}\\n\\`\\`\\``;\n}\n\n/**\n * Wraps the content inside \\`backticks\\`, which formats it as inline code\n *\n * @param content - The content to wrap\n */\nexport function inlineCode<C extends string>(content: C): `\\`${C}\\`` {\n\treturn `\\`${content}\\``;\n}\n\n/**\n * Formats the content into italic text\n *\n * @param content - The content to wrap\n */\nexport function italic<C extends string>(content: C): `_${C}_` {\n\treturn `_${content}_`;\n}\n\n/**\n * Formats the content into bold text\n *\n * @param content - The content to wrap\n */\nexport function bold<C extends string>(content: C): `**${C}**` {\n\treturn `**${content}**`;\n}\n\n/**\n * Formats the content into underscored text\n *\n * @param content - The content to wrap\n */\nexport function underscore<C extends string>(content: C): `__${C}__` {\n\treturn `__${content}__`;\n}\n\n/**\n * Formats the content into strike-through text\n *\n * @param content - The content to wrap\n */\nexport function strikethrough<C extends string>(content: C): `~~${C}~~` {\n\treturn `~~${content}~~`;\n}\n\n/**\n * Formats the content into a quote. This needs to be at the start of the line for Discord to format it\n *\n * @param content - The content to wrap\n */\nexport function quote<C extends string>(content: C): `> ${C}` {\n\treturn `> ${content}`;\n}\n\n/**\n * Formats the content into a block quote. This needs to be at the start of the line for Discord to format it\n *\n * @param content - The content to wrap\n */\nexport function blockQuote<C extends string>(content: C): `>>> ${C}` {\n\treturn `>>> ${content}`;\n}\n\n/**\n * Wraps the URL into `<>`, which stops it from embedding\n *\n * @param url - The URL to wrap\n */\nexport function hideLinkEmbed<C extends string>(url: C): `<${C}>`;\n\n/**\n * Wraps the URL into `<>`, which stops it from embedding\n *\n * @param url - The URL to wrap\n */\nexport function hideLinkEmbed(url: URL): `<${string}>`;\nexport function hideLinkEmbed(url: URL | string) {\n\treturn `<${url}>`;\n}\n\n/**\n * Formats the content and the URL into a masked URL\n *\n * @param content - The content to display\n * @param url - The URL the content links to\n */\nexport function hyperlink<C extends string>(content: C, url: URL): `[${C}](${string})`;\n\n/**\n * Formats the content and the URL into a masked URL\n *\n * @param content - The content to display\n * @param url - The URL the content links to\n */\nexport function hyperlink<C extends string, U extends string>(content: C, url: U): `[${C}](${U})`;\n\n/**\n * Formats the content and the URL into a masked URL\n *\n * @param content - The content to display\n * @param url - The URL the content links to\n * @param title - The title shown when hovering on the masked link\n */\nexport function hyperlink<C extends string, T extends string>(\n\tcontent: C,\n\turl: URL,\n\ttitle: T,\n): `[${C}](${string} \"${T}\")`;\n\n/**\n * Formats the content and the URL into a masked URL\n *\n * @param content - The content to display\n * @param url - The URL the content links to\n * @param title - The title shown when hovering on the masked link\n */\nexport function hyperlink<C extends string, U extends string, T extends string>(\n\tcontent: C,\n\turl: U,\n\ttitle: T,\n): `[${C}](${U} \"${T}\")`;\nexport function hyperlink(content: string, url: URL | string, title?: string) {\n\treturn title ? `[${content}](${url} \"${title}\")` : `[${content}](${url})`;\n}\n\n/**\n * Wraps the content inside spoiler (hidden text)\n *\n * @param content - The content to wrap\n */\nexport function spoiler<C extends string>(content: C): `||${C}||` {\n\treturn `||${content}||`;\n}\n\n/**\n * Formats a user ID into a user mention\n *\n * @param userId - The user ID to format\n */\nexport function userMention<C extends Snowflake>(userId: C): `<@${C}>` {\n\treturn `<@${userId}>`;\n}\n\n/**\n * Formats a channel ID into a channel mention\n *\n * @param channelId - The channel ID to format\n */\nexport function channelMention<C extends Snowflake>(channelId: C): `<#${C}>` {\n\treturn `<#${channelId}>`;\n}\n\n/**\n * Formats a role ID into a role mention\n *\n * @param roleId - The role ID to format\n */\nexport function roleMention<C extends Snowflake>(roleId: C): `<@&${C}>` {\n\treturn `<@&${roleId}>`;\n}\n\n/**\n * Formats an application command name, subcommand group name, subcommand name, and ID into an application command mention\n *\n * @param commandName - The application command name to format\n * @param subcommandGroupName - The subcommand group name to format\n * @param subcommandName - The subcommand name to format\n * @param commandId - The application command ID to format\n */\nexport function chatInputApplicationCommandMention<\n\tN extends string,\n\tG extends string,\n\tS extends string,\n\tI extends Snowflake,\n>(commandName: N, subcommandGroupName: G, subcommandName: S, commandId: I): `</${N} ${G} ${S}:${I}>`;\n\n/**\n * Formats an application command name, subcommand name, and ID into an application command mention\n *\n * @param commandName - The application command name to format\n * @param subcommandName - The subcommand name to format\n * @param commandId - The application command ID to format\n */\nexport function chatInputApplicationCommandMention<N extends string, S extends string, I extends Snowflake>(\n\tcommandName: N,\n\tsubcommandName: S,\n\tcommandId: I,\n): `</${N} ${S}:${I}>`;\n\n/**\n * Formats an application command name and ID into an application command mention\n *\n * @param commandName - The application command name to format\n * @param commandId - The application command ID to format\n */\nexport function chatInputApplicationCommandMention<N extends string, I extends Snowflake>(\n\tcommandName: N,\n\tcommandId: I,\n): `</${N}:${I}>`;\n\n/**\n * Formats an application command name, subcommand group name, subcommand name, and ID into an application command mention\n *\n * @param commandName - The application command name to format\n * @param subcommandGroupName - The subcommand group name to format\n * @param subcommandName - The subcommand name to format\n * @param commandId - The application command ID to format\n */\nexport function chatInputApplicationCommandMention<\n\tN extends string,\n\tG extends Snowflake | string,\n\tS extends Snowflake | string,\n\tI extends Snowflake,\n>(\n\tcommandName: N,\n\tsubcommandGroupName: G,\n\tsubcommandName?: S,\n\tcommandId?: I,\n): `</${N} ${G} ${S}:${I}>` | `</${N} ${G}:${S}>` | `</${N}:${G}>` {\n\tif (typeof commandId !== 'undefined') {\n\t\treturn `</${commandName} ${subcommandGroupName} ${subcommandName!}:${commandId}>`;\n\t}\n\n\tif (typeof subcommandName !== 'undefined') {\n\t\treturn `</${commandName} ${subcommandGroupName}:${subcommandName}>`;\n\t}\n\n\treturn `</${commandName}:${subcommandGroupName}>`;\n}\n\n/**\n * Formats an emoji ID into a fully qualified emoji identifier\n *\n * @param emojiId - The emoji ID to format\n */\nexport function formatEmoji<C extends Snowflake>(emojiId: C, animated?: false): `<:_:${C}>`;\n\n/**\n * Formats an emoji ID into a fully qualified emoji identifier\n *\n * @param emojiId - The emoji ID to format\n * @param animated - Whether the emoji is animated or not. Defaults to `false`\n */\nexport function formatEmoji<C extends Snowflake>(emojiId: C, animated?: true): `<a:_:${C}>`;\n\n/**\n * Formats an emoji ID into a fully qualified emoji identifier\n *\n * @param emojiId - The emoji ID to format\n * @param animated - Whether the emoji is animated or not. Defaults to `false`\n */\nexport function formatEmoji<C extends Snowflake>(emojiId: C, animated?: boolean): `<:_:${C}>` | `<a:_:${C}>`;\n\n/**\n * Formats an emoji ID into a fully qualified emoji identifier\n *\n * @param emojiId - The emoji ID to format\n * @param animated - Whether the emoji is animated or not. Defaults to `false`\n */\nexport function formatEmoji<C extends Snowflake>(emojiId: C, animated = false): `<:_:${C}>` | `<a:_:${C}>` {\n\treturn `<${animated ? 'a' : ''}:_:${emojiId}>`;\n}\n\n/**\n * Formats a channel link for a direct message channel.\n *\n * @param channelId - The channel's id\n */\nexport function channelLink<C extends Snowflake>(channelId: C): `https://discord.com/channels/@me/${C}`;\n\n/**\n * Formats a channel link for a guild channel.\n *\n * @param channelId - The channel's id\n * @param guildId - The guild's id\n */\nexport function channelLink<C extends Snowflake, G extends Snowflake>(\n\tchannelId: C,\n\tguildId: G,\n): `https://discord.com/channels/${G}/${C}`;\n\nexport function channelLink<C extends Snowflake, G extends Snowflake>(\n\tchannelId: C,\n\tguildId?: G,\n): `https://discord.com/channels/@me/${C}` | `https://discord.com/channels/${G}/${C}` {\n\treturn `https://discord.com/channels/${guildId ?? '@me'}/${channelId}`;\n}\n\n/**\n * Formats a message link for a direct message channel.\n *\n * @param channelId - The channel's id\n * @param messageId - The message's id\n */\nexport function messageLink<C extends Snowflake, M extends Snowflake>(\n\tchannelId: C,\n\tmessageId: M,\n): `https://discord.com/channels/@me/${C}/${M}`;\n\n/**\n * Formats a message link for a guild channel.\n *\n * @param channelId - The channel's id\n * @param messageId - The message's id\n * @param guildId - The guild's id\n */\nexport function messageLink<C extends Snowflake, M extends Snowflake, G extends Snowflake>(\n\tchannelId: C,\n\tmessageId: M,\n\tguildId: G,\n): `https://discord.com/channels/${G}/${C}/${M}`;\n\nexport function messageLink<C extends Snowflake, M extends Snowflake, G extends Snowflake>(\n\tchannelId: C,\n\tmessageId: M,\n\tguildId?: G,\n): `https://discord.com/channels/@me/${C}/${M}` | `https://discord.com/channels/${G}/${C}/${M}` {\n\treturn `${typeof guildId === 'undefined' ? channelLink(channelId) : channelLink(channelId, guildId)}/${messageId}`;\n}\n\n/**\n * Formats a date into a short date-time string\n *\n * @param date - The date to format, defaults to the current time\n */\nexport function time(date?: Date): `<t:${bigint}>`;\n\n/**\n * Formats a date given a format style\n *\n * @param date - The date to format\n * @param style - The style to use\n */\nexport function time<S extends TimestampStylesString>(date: Date, style: S): `<t:${bigint}:${S}>`;\n\n/**\n * Formats the given timestamp into a short date-time string\n *\n * @param seconds - The time to format, represents an UNIX timestamp in seconds\n */\nexport function time<C extends number>(seconds: C): `<t:${C}>`;\n\n/**\n * Formats the given timestamp into a short date-time string\n *\n * @param seconds - The time to format, represents an UNIX timestamp in seconds\n * @param style - The style to use\n */\nexport function time<C extends number, S extends TimestampStylesString>(seconds: C, style: S): `<t:${C}:${S}>`;\nexport function time(timeOrSeconds?: Date | number, style?: TimestampStylesString): string {\n\tif (typeof timeOrSeconds !== 'number') {\n\t\t// eslint-disable-next-line no-param-reassign\n\t\ttimeOrSeconds = Math.floor((timeOrSeconds?.getTime() ?? Date.now()) / 1_000);\n\t}\n\n\treturn typeof style === 'string' ? `<t:${timeOrSeconds}:${style}>` : `<t:${timeOrSeconds}>`;\n}\n\n/**\n * The {@link https://discord.com/developers/docs/reference#message-formatting-timestamp-styles | message formatting timestamp styles} supported by Discord\n */\nexport const TimestampStyles = {\n\t/**\n\t * Short time format, consisting of hours and minutes, e.g. 16:20\n\t */\n\tShortTime: 't',\n\n\t/**\n\t * Long time format, consisting of hours, minutes, and seconds, e.g. 16:20:30\n\t */\n\tLongTime: 'T',\n\n\t/**\n\t * Short date format, consisting of day, month, and year, e.g. 20/04/2021\n\t */\n\tShortDate: 'd',\n\n\t/**\n\t * Long date format, consisting of day, month, and year, e.g. 20 April 2021\n\t */\n\tLongDate: 'D',\n\n\t/**\n\t * Short date-time format, consisting of short date and short time formats, e.g. 20 April 2021 16:20\n\t */\n\tShortDateTime: 'f',\n\n\t/**\n\t * Long date-time format, consisting of long date and short time formats, e.g. Tuesday, 20 April 2021 16:20\n\t */\n\tLongDateTime: 'F',\n\n\t/**\n\t * Relative time format, consisting of a relative duration format, e.g. 2 months ago\n\t */\n\tRelativeTime: 'R',\n} as const;\n\n/**\n * The possible values, see {@link TimestampStyles} for more information\n */\nexport type TimestampStylesString = typeof TimestampStyles[keyof typeof TimestampStyles];\n\n/**\n * An enum with all the available faces from Discord's native slash commands\n */\nexport enum Faces {\n\t/**\n\t * ¯\\\\_(ツ)\\\\_/¯\n\t */\n\tShrug = '¯\\\\_(ツ)\\\\_/¯',\n\n\t/**\n\t * (╯°□°)╯︵ ┻━┻\n\t */\n\tTableflip = '(╯°□°)╯︵ ┻━┻',\n\n\t/**\n\t * ┬─┬ ノ( ゜-゜ノ)\n\t */\n\tUnflip = '┬─┬ ノ( ゜-゜ノ)',\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACiBO,SAAS,UAAU,UAAkB,SAA0B;AACrE,SAAO,OAAO,YAAY,cAAc;AAAA,EAAW;AAAA,UAAqB,SAAS;AAAA,EAAa;AAAA;AAC/F;AAFgB;AAST,SAAS,WAA6B,SAAwB;AACpE,SAAO,KAAK;AACb;AAFgB;AAST,SAAS,OAAyB,SAAsB;AAC9D,SAAO,IAAI;AACZ;AAFgB;AAST,SAAS,KAAuB,SAAwB;AAC9D,SAAO,KAAK;AACb;AAFgB;AAST,SAAS,WAA6B,SAAwB;AACpE,SAAO,KAAK;AACb;AAFgB;AAST,SAAS,cAAgC,SAAwB;AACvE,SAAO,KAAK;AACb;AAFgB;AAST,SAAS,MAAwB,SAAsB;AAC7D,SAAO,KAAK;AACb;AAFgB;AAST,SAAS,WAA6B,SAAwB;AACpE,SAAO,OAAO;AACf;AAFgB;AAiBT,SAAS,cAAc,KAAmB;AAChD,SAAO,IAAI;AACZ;AAFgB;AA6CT,SAAS,UAAU,SAAiB,KAAmB,OAAgB;AAC7E,SAAO,QAAQ,IAAI,YAAY,QAAQ,YAAY,IAAI,YAAY;AACpE;AAFgB;AAST,SAAS,QAA0B,SAAwB;AACjE,SAAO,KAAK;AACb;AAFgB;AAST,SAAS,YAAiC,QAAsB;AACtE,SAAO,KAAK;AACb;AAFgB;AAST,SAAS,eAAoC,WAAyB;AAC5E,SAAO,KAAK;AACb;AAFgB;AAST,SAAS,YAAiC,QAAuB;AACvE,SAAO,MAAM;AACd;AAFgB;AAmDT,SAAS,mCAMf,aACA,qBACA,gBACA,WACkE;AAClE,MAAI,OAAO,cAAc,aAAa;AACrC,WAAO,KAAK,eAAe,uBAAuB,kBAAmB;AAAA,EACtE;AAEA,MAAI,OAAO,mBAAmB,aAAa;AAC1C,WAAO,KAAK,eAAe,uBAAuB;AAAA,EACnD;AAEA,SAAO,KAAK,eAAe;AAC5B;AApBgB;AAmDT,SAAS,YAAiC,SAAY,WAAW,OAAmC;AAC1G,SAAO,IAAI,WAAW,MAAM,QAAQ;AACrC;AAFgB;AAsBT,SAAS,YACf,WACA,SACqF;AACrF,SAAO,gCAAgC,WAAW,SAAS;AAC5D;AALgB;AA+BT,SAAS,YACf,WACA,WACA,SAC+F;AAC/F,SAAO,GAAG,OAAO,YAAY,cAAc,YAAY,SAAS,IAAI,YAAY,WAAW,OAAO,KAAK;AACxG;AANgB;AAqCT,SAAS,KAAK,eAA+B,OAAuC;AAC1F,MAAI,OAAO,kBAAkB,UAAU;AAEtC,oBAAgB,KAAK,OAAO,eAAe,QAAQ,KAAK,KAAK,IAAI,KAAK,GAAK;AAAA,EAC5E;AAEA,SAAO,OAAO,UAAU,WAAW,MAAM,iBAAiB,WAAW,MAAM;AAC5E;AAPgB;AAYT,IAAM,kBAAkB;AAAA,EAI9B,WAAW;AAAA,EAKX,UAAU;AAAA,EAKV,WAAW;AAAA,EAKX,UAAU;AAAA,EAKV,eAAe;AAAA,EAKf,cAAc;AAAA,EAKd,cAAc;AACf;AAUO,IAAK,QAAL,kBAAKA,WAAL;AAIN,EAAAA,OAAA,WAAQ;AAKR,EAAAA,OAAA,eAAY;AAKZ,EAAAA,OAAA,YAAS;AAdE,SAAAA;AAAA,GAAA;","names":["Faces"]}
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
+
|
|
4
|
+
// src/formatters.ts
|
|
5
|
+
function codeBlock(language, content) {
|
|
6
|
+
return typeof content === "undefined" ? `\`\`\`
|
|
7
|
+
${language}
|
|
8
|
+
\`\`\`` : `\`\`\`${language}
|
|
9
|
+
${content}
|
|
10
|
+
\`\`\``;
|
|
11
|
+
}
|
|
12
|
+
__name(codeBlock, "codeBlock");
|
|
13
|
+
function inlineCode(content) {
|
|
14
|
+
return `\`${content}\``;
|
|
15
|
+
}
|
|
16
|
+
__name(inlineCode, "inlineCode");
|
|
17
|
+
function italic(content) {
|
|
18
|
+
return `_${content}_`;
|
|
19
|
+
}
|
|
20
|
+
__name(italic, "italic");
|
|
21
|
+
function bold(content) {
|
|
22
|
+
return `**${content}**`;
|
|
23
|
+
}
|
|
24
|
+
__name(bold, "bold");
|
|
25
|
+
function underscore(content) {
|
|
26
|
+
return `__${content}__`;
|
|
27
|
+
}
|
|
28
|
+
__name(underscore, "underscore");
|
|
29
|
+
function strikethrough(content) {
|
|
30
|
+
return `~~${content}~~`;
|
|
31
|
+
}
|
|
32
|
+
__name(strikethrough, "strikethrough");
|
|
33
|
+
function quote(content) {
|
|
34
|
+
return `> ${content}`;
|
|
35
|
+
}
|
|
36
|
+
__name(quote, "quote");
|
|
37
|
+
function blockQuote(content) {
|
|
38
|
+
return `>>> ${content}`;
|
|
39
|
+
}
|
|
40
|
+
__name(blockQuote, "blockQuote");
|
|
41
|
+
function hideLinkEmbed(url) {
|
|
42
|
+
return `<${url}>`;
|
|
43
|
+
}
|
|
44
|
+
__name(hideLinkEmbed, "hideLinkEmbed");
|
|
45
|
+
function hyperlink(content, url, title) {
|
|
46
|
+
return title ? `[${content}](${url} "${title}")` : `[${content}](${url})`;
|
|
47
|
+
}
|
|
48
|
+
__name(hyperlink, "hyperlink");
|
|
49
|
+
function spoiler(content) {
|
|
50
|
+
return `||${content}||`;
|
|
51
|
+
}
|
|
52
|
+
__name(spoiler, "spoiler");
|
|
53
|
+
function userMention(userId) {
|
|
54
|
+
return `<@${userId}>`;
|
|
55
|
+
}
|
|
56
|
+
__name(userMention, "userMention");
|
|
57
|
+
function channelMention(channelId) {
|
|
58
|
+
return `<#${channelId}>`;
|
|
59
|
+
}
|
|
60
|
+
__name(channelMention, "channelMention");
|
|
61
|
+
function roleMention(roleId) {
|
|
62
|
+
return `<@&${roleId}>`;
|
|
63
|
+
}
|
|
64
|
+
__name(roleMention, "roleMention");
|
|
65
|
+
function chatInputApplicationCommandMention(commandName, subcommandGroupName, subcommandName, commandId) {
|
|
66
|
+
if (typeof commandId !== "undefined") {
|
|
67
|
+
return `</${commandName} ${subcommandGroupName} ${subcommandName}:${commandId}>`;
|
|
68
|
+
}
|
|
69
|
+
if (typeof subcommandName !== "undefined") {
|
|
70
|
+
return `</${commandName} ${subcommandGroupName}:${subcommandName}>`;
|
|
71
|
+
}
|
|
72
|
+
return `</${commandName}:${subcommandGroupName}>`;
|
|
73
|
+
}
|
|
74
|
+
__name(chatInputApplicationCommandMention, "chatInputApplicationCommandMention");
|
|
75
|
+
function formatEmoji(emojiId, animated = false) {
|
|
76
|
+
return `<${animated ? "a" : ""}:_:${emojiId}>`;
|
|
77
|
+
}
|
|
78
|
+
__name(formatEmoji, "formatEmoji");
|
|
79
|
+
function channelLink(channelId, guildId) {
|
|
80
|
+
return `https://discord.com/channels/${guildId ?? "@me"}/${channelId}`;
|
|
81
|
+
}
|
|
82
|
+
__name(channelLink, "channelLink");
|
|
83
|
+
function messageLink(channelId, messageId, guildId) {
|
|
84
|
+
return `${typeof guildId === "undefined" ? channelLink(channelId) : channelLink(channelId, guildId)}/${messageId}`;
|
|
85
|
+
}
|
|
86
|
+
__name(messageLink, "messageLink");
|
|
87
|
+
function time(timeOrSeconds, style) {
|
|
88
|
+
if (typeof timeOrSeconds !== "number") {
|
|
89
|
+
timeOrSeconds = Math.floor((timeOrSeconds?.getTime() ?? Date.now()) / 1e3);
|
|
90
|
+
}
|
|
91
|
+
return typeof style === "string" ? `<t:${timeOrSeconds}:${style}>` : `<t:${timeOrSeconds}>`;
|
|
92
|
+
}
|
|
93
|
+
__name(time, "time");
|
|
94
|
+
var TimestampStyles = {
|
|
95
|
+
ShortTime: "t",
|
|
96
|
+
LongTime: "T",
|
|
97
|
+
ShortDate: "d",
|
|
98
|
+
LongDate: "D",
|
|
99
|
+
ShortDateTime: "f",
|
|
100
|
+
LongDateTime: "F",
|
|
101
|
+
RelativeTime: "R"
|
|
102
|
+
};
|
|
103
|
+
var Faces = /* @__PURE__ */ ((Faces2) => {
|
|
104
|
+
Faces2["Shrug"] = "\xAF\\_(\u30C4)\\_/\xAF";
|
|
105
|
+
Faces2["Tableflip"] = "(\u256F\xB0\u25A1\xB0\uFF09\u256F\uFE35 \u253B\u2501\u253B";
|
|
106
|
+
Faces2["Unflip"] = "\u252C\u2500\u252C \u30CE( \u309C-\u309C\u30CE)";
|
|
107
|
+
return Faces2;
|
|
108
|
+
})(Faces || {});
|
|
109
|
+
export {
|
|
110
|
+
Faces,
|
|
111
|
+
TimestampStyles,
|
|
112
|
+
blockQuote,
|
|
113
|
+
bold,
|
|
114
|
+
channelLink,
|
|
115
|
+
channelMention,
|
|
116
|
+
chatInputApplicationCommandMention,
|
|
117
|
+
codeBlock,
|
|
118
|
+
formatEmoji,
|
|
119
|
+
hideLinkEmbed,
|
|
120
|
+
hyperlink,
|
|
121
|
+
inlineCode,
|
|
122
|
+
italic,
|
|
123
|
+
messageLink,
|
|
124
|
+
quote,
|
|
125
|
+
roleMention,
|
|
126
|
+
spoiler,
|
|
127
|
+
strikethrough,
|
|
128
|
+
time,
|
|
129
|
+
underscore,
|
|
130
|
+
userMention
|
|
131
|
+
};
|
|
132
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/formatters.ts"],"sourcesContent":["import type { URL } from 'node:url';\nimport type { Snowflake } from 'discord-api-types/globals';\n\n/**\n * Wraps the content inside a codeblock with no language\n *\n * @param content - The content to wrap\n */\nexport function codeBlock<C extends string>(content: C): `\\`\\`\\`\\n${C}\\n\\`\\`\\``;\n\n/**\n * Wraps the content inside a codeblock with the specified language\n *\n * @param language - The language for the codeblock\n * @param content - The content to wrap\n */\nexport function codeBlock<L extends string, C extends string>(language: L, content: C): `\\`\\`\\`${L}\\n${C}\\n\\`\\`\\``;\nexport function codeBlock(language: string, content?: string): string {\n\treturn typeof content === 'undefined' ? `\\`\\`\\`\\n${language}\\n\\`\\`\\`` : `\\`\\`\\`${language}\\n${content}\\n\\`\\`\\``;\n}\n\n/**\n * Wraps the content inside \\`backticks\\`, which formats it as inline code\n *\n * @param content - The content to wrap\n */\nexport function inlineCode<C extends string>(content: C): `\\`${C}\\`` {\n\treturn `\\`${content}\\``;\n}\n\n/**\n * Formats the content into italic text\n *\n * @param content - The content to wrap\n */\nexport function italic<C extends string>(content: C): `_${C}_` {\n\treturn `_${content}_`;\n}\n\n/**\n * Formats the content into bold text\n *\n * @param content - The content to wrap\n */\nexport function bold<C extends string>(content: C): `**${C}**` {\n\treturn `**${content}**`;\n}\n\n/**\n * Formats the content into underscored text\n *\n * @param content - The content to wrap\n */\nexport function underscore<C extends string>(content: C): `__${C}__` {\n\treturn `__${content}__`;\n}\n\n/**\n * Formats the content into strike-through text\n *\n * @param content - The content to wrap\n */\nexport function strikethrough<C extends string>(content: C): `~~${C}~~` {\n\treturn `~~${content}~~`;\n}\n\n/**\n * Formats the content into a quote. This needs to be at the start of the line for Discord to format it\n *\n * @param content - The content to wrap\n */\nexport function quote<C extends string>(content: C): `> ${C}` {\n\treturn `> ${content}`;\n}\n\n/**\n * Formats the content into a block quote. This needs to be at the start of the line for Discord to format it\n *\n * @param content - The content to wrap\n */\nexport function blockQuote<C extends string>(content: C): `>>> ${C}` {\n\treturn `>>> ${content}`;\n}\n\n/**\n * Wraps the URL into `<>`, which stops it from embedding\n *\n * @param url - The URL to wrap\n */\nexport function hideLinkEmbed<C extends string>(url: C): `<${C}>`;\n\n/**\n * Wraps the URL into `<>`, which stops it from embedding\n *\n * @param url - The URL to wrap\n */\nexport function hideLinkEmbed(url: URL): `<${string}>`;\nexport function hideLinkEmbed(url: URL | string) {\n\treturn `<${url}>`;\n}\n\n/**\n * Formats the content and the URL into a masked URL\n *\n * @param content - The content to display\n * @param url - The URL the content links to\n */\nexport function hyperlink<C extends string>(content: C, url: URL): `[${C}](${string})`;\n\n/**\n * Formats the content and the URL into a masked URL\n *\n * @param content - The content to display\n * @param url - The URL the content links to\n */\nexport function hyperlink<C extends string, U extends string>(content: C, url: U): `[${C}](${U})`;\n\n/**\n * Formats the content and the URL into a masked URL\n *\n * @param content - The content to display\n * @param url - The URL the content links to\n * @param title - The title shown when hovering on the masked link\n */\nexport function hyperlink<C extends string, T extends string>(\n\tcontent: C,\n\turl: URL,\n\ttitle: T,\n): `[${C}](${string} \"${T}\")`;\n\n/**\n * Formats the content and the URL into a masked URL\n *\n * @param content - The content to display\n * @param url - The URL the content links to\n * @param title - The title shown when hovering on the masked link\n */\nexport function hyperlink<C extends string, U extends string, T extends string>(\n\tcontent: C,\n\turl: U,\n\ttitle: T,\n): `[${C}](${U} \"${T}\")`;\nexport function hyperlink(content: string, url: URL | string, title?: string) {\n\treturn title ? `[${content}](${url} \"${title}\")` : `[${content}](${url})`;\n}\n\n/**\n * Wraps the content inside spoiler (hidden text)\n *\n * @param content - The content to wrap\n */\nexport function spoiler<C extends string>(content: C): `||${C}||` {\n\treturn `||${content}||`;\n}\n\n/**\n * Formats a user ID into a user mention\n *\n * @param userId - The user ID to format\n */\nexport function userMention<C extends Snowflake>(userId: C): `<@${C}>` {\n\treturn `<@${userId}>`;\n}\n\n/**\n * Formats a channel ID into a channel mention\n *\n * @param channelId - The channel ID to format\n */\nexport function channelMention<C extends Snowflake>(channelId: C): `<#${C}>` {\n\treturn `<#${channelId}>`;\n}\n\n/**\n * Formats a role ID into a role mention\n *\n * @param roleId - The role ID to format\n */\nexport function roleMention<C extends Snowflake>(roleId: C): `<@&${C}>` {\n\treturn `<@&${roleId}>`;\n}\n\n/**\n * Formats an application command name, subcommand group name, subcommand name, and ID into an application command mention\n *\n * @param commandName - The application command name to format\n * @param subcommandGroupName - The subcommand group name to format\n * @param subcommandName - The subcommand name to format\n * @param commandId - The application command ID to format\n */\nexport function chatInputApplicationCommandMention<\n\tN extends string,\n\tG extends string,\n\tS extends string,\n\tI extends Snowflake,\n>(commandName: N, subcommandGroupName: G, subcommandName: S, commandId: I): `</${N} ${G} ${S}:${I}>`;\n\n/**\n * Formats an application command name, subcommand name, and ID into an application command mention\n *\n * @param commandName - The application command name to format\n * @param subcommandName - The subcommand name to format\n * @param commandId - The application command ID to format\n */\nexport function chatInputApplicationCommandMention<N extends string, S extends string, I extends Snowflake>(\n\tcommandName: N,\n\tsubcommandName: S,\n\tcommandId: I,\n): `</${N} ${S}:${I}>`;\n\n/**\n * Formats an application command name and ID into an application command mention\n *\n * @param commandName - The application command name to format\n * @param commandId - The application command ID to format\n */\nexport function chatInputApplicationCommandMention<N extends string, I extends Snowflake>(\n\tcommandName: N,\n\tcommandId: I,\n): `</${N}:${I}>`;\n\n/**\n * Formats an application command name, subcommand group name, subcommand name, and ID into an application command mention\n *\n * @param commandName - The application command name to format\n * @param subcommandGroupName - The subcommand group name to format\n * @param subcommandName - The subcommand name to format\n * @param commandId - The application command ID to format\n */\nexport function chatInputApplicationCommandMention<\n\tN extends string,\n\tG extends Snowflake | string,\n\tS extends Snowflake | string,\n\tI extends Snowflake,\n>(\n\tcommandName: N,\n\tsubcommandGroupName: G,\n\tsubcommandName?: S,\n\tcommandId?: I,\n): `</${N} ${G} ${S}:${I}>` | `</${N} ${G}:${S}>` | `</${N}:${G}>` {\n\tif (typeof commandId !== 'undefined') {\n\t\treturn `</${commandName} ${subcommandGroupName} ${subcommandName!}:${commandId}>`;\n\t}\n\n\tif (typeof subcommandName !== 'undefined') {\n\t\treturn `</${commandName} ${subcommandGroupName}:${subcommandName}>`;\n\t}\n\n\treturn `</${commandName}:${subcommandGroupName}>`;\n}\n\n/**\n * Formats an emoji ID into a fully qualified emoji identifier\n *\n * @param emojiId - The emoji ID to format\n */\nexport function formatEmoji<C extends Snowflake>(emojiId: C, animated?: false): `<:_:${C}>`;\n\n/**\n * Formats an emoji ID into a fully qualified emoji identifier\n *\n * @param emojiId - The emoji ID to format\n * @param animated - Whether the emoji is animated or not. Defaults to `false`\n */\nexport function formatEmoji<C extends Snowflake>(emojiId: C, animated?: true): `<a:_:${C}>`;\n\n/**\n * Formats an emoji ID into a fully qualified emoji identifier\n *\n * @param emojiId - The emoji ID to format\n * @param animated - Whether the emoji is animated or not. Defaults to `false`\n */\nexport function formatEmoji<C extends Snowflake>(emojiId: C, animated?: boolean): `<:_:${C}>` | `<a:_:${C}>`;\n\n/**\n * Formats an emoji ID into a fully qualified emoji identifier\n *\n * @param emojiId - The emoji ID to format\n * @param animated - Whether the emoji is animated or not. Defaults to `false`\n */\nexport function formatEmoji<C extends Snowflake>(emojiId: C, animated = false): `<:_:${C}>` | `<a:_:${C}>` {\n\treturn `<${animated ? 'a' : ''}:_:${emojiId}>`;\n}\n\n/**\n * Formats a channel link for a direct message channel.\n *\n * @param channelId - The channel's id\n */\nexport function channelLink<C extends Snowflake>(channelId: C): `https://discord.com/channels/@me/${C}`;\n\n/**\n * Formats a channel link for a guild channel.\n *\n * @param channelId - The channel's id\n * @param guildId - The guild's id\n */\nexport function channelLink<C extends Snowflake, G extends Snowflake>(\n\tchannelId: C,\n\tguildId: G,\n): `https://discord.com/channels/${G}/${C}`;\n\nexport function channelLink<C extends Snowflake, G extends Snowflake>(\n\tchannelId: C,\n\tguildId?: G,\n): `https://discord.com/channels/@me/${C}` | `https://discord.com/channels/${G}/${C}` {\n\treturn `https://discord.com/channels/${guildId ?? '@me'}/${channelId}`;\n}\n\n/**\n * Formats a message link for a direct message channel.\n *\n * @param channelId - The channel's id\n * @param messageId - The message's id\n */\nexport function messageLink<C extends Snowflake, M extends Snowflake>(\n\tchannelId: C,\n\tmessageId: M,\n): `https://discord.com/channels/@me/${C}/${M}`;\n\n/**\n * Formats a message link for a guild channel.\n *\n * @param channelId - The channel's id\n * @param messageId - The message's id\n * @param guildId - The guild's id\n */\nexport function messageLink<C extends Snowflake, M extends Snowflake, G extends Snowflake>(\n\tchannelId: C,\n\tmessageId: M,\n\tguildId: G,\n): `https://discord.com/channels/${G}/${C}/${M}`;\n\nexport function messageLink<C extends Snowflake, M extends Snowflake, G extends Snowflake>(\n\tchannelId: C,\n\tmessageId: M,\n\tguildId?: G,\n): `https://discord.com/channels/@me/${C}/${M}` | `https://discord.com/channels/${G}/${C}/${M}` {\n\treturn `${typeof guildId === 'undefined' ? channelLink(channelId) : channelLink(channelId, guildId)}/${messageId}`;\n}\n\n/**\n * Formats a date into a short date-time string\n *\n * @param date - The date to format, defaults to the current time\n */\nexport function time(date?: Date): `<t:${bigint}>`;\n\n/**\n * Formats a date given a format style\n *\n * @param date - The date to format\n * @param style - The style to use\n */\nexport function time<S extends TimestampStylesString>(date: Date, style: S): `<t:${bigint}:${S}>`;\n\n/**\n * Formats the given timestamp into a short date-time string\n *\n * @param seconds - The time to format, represents an UNIX timestamp in seconds\n */\nexport function time<C extends number>(seconds: C): `<t:${C}>`;\n\n/**\n * Formats the given timestamp into a short date-time string\n *\n * @param seconds - The time to format, represents an UNIX timestamp in seconds\n * @param style - The style to use\n */\nexport function time<C extends number, S extends TimestampStylesString>(seconds: C, style: S): `<t:${C}:${S}>`;\nexport function time(timeOrSeconds?: Date | number, style?: TimestampStylesString): string {\n\tif (typeof timeOrSeconds !== 'number') {\n\t\t// eslint-disable-next-line no-param-reassign\n\t\ttimeOrSeconds = Math.floor((timeOrSeconds?.getTime() ?? Date.now()) / 1_000);\n\t}\n\n\treturn typeof style === 'string' ? `<t:${timeOrSeconds}:${style}>` : `<t:${timeOrSeconds}>`;\n}\n\n/**\n * The {@link https://discord.com/developers/docs/reference#message-formatting-timestamp-styles | message formatting timestamp styles} supported by Discord\n */\nexport const TimestampStyles = {\n\t/**\n\t * Short time format, consisting of hours and minutes, e.g. 16:20\n\t */\n\tShortTime: 't',\n\n\t/**\n\t * Long time format, consisting of hours, minutes, and seconds, e.g. 16:20:30\n\t */\n\tLongTime: 'T',\n\n\t/**\n\t * Short date format, consisting of day, month, and year, e.g. 20/04/2021\n\t */\n\tShortDate: 'd',\n\n\t/**\n\t * Long date format, consisting of day, month, and year, e.g. 20 April 2021\n\t */\n\tLongDate: 'D',\n\n\t/**\n\t * Short date-time format, consisting of short date and short time formats, e.g. 20 April 2021 16:20\n\t */\n\tShortDateTime: 'f',\n\n\t/**\n\t * Long date-time format, consisting of long date and short time formats, e.g. Tuesday, 20 April 2021 16:20\n\t */\n\tLongDateTime: 'F',\n\n\t/**\n\t * Relative time format, consisting of a relative duration format, e.g. 2 months ago\n\t */\n\tRelativeTime: 'R',\n} as const;\n\n/**\n * The possible values, see {@link TimestampStyles} for more information\n */\nexport type TimestampStylesString = typeof TimestampStyles[keyof typeof TimestampStyles];\n\n/**\n * An enum with all the available faces from Discord's native slash commands\n */\nexport enum Faces {\n\t/**\n\t * ¯\\\\_(ツ)\\\\_/¯\n\t */\n\tShrug = '¯\\\\_(ツ)\\\\_/¯',\n\n\t/**\n\t * (╯°□°)╯︵ ┻━┻\n\t */\n\tTableflip = '(╯°□°)╯︵ ┻━┻',\n\n\t/**\n\t * ┬─┬ ノ( ゜-゜ノ)\n\t */\n\tUnflip = '┬─┬ ノ( ゜-゜ノ)',\n}\n"],"mappings":";;;;AAiBO,SAAS,UAAU,UAAkB,SAA0B;AACrE,SAAO,OAAO,YAAY,cAAc;AAAA,EAAW;AAAA,UAAqB,SAAS;AAAA,EAAa;AAAA;AAC/F;AAFgB;AAST,SAAS,WAA6B,SAAwB;AACpE,SAAO,KAAK;AACb;AAFgB;AAST,SAAS,OAAyB,SAAsB;AAC9D,SAAO,IAAI;AACZ;AAFgB;AAST,SAAS,KAAuB,SAAwB;AAC9D,SAAO,KAAK;AACb;AAFgB;AAST,SAAS,WAA6B,SAAwB;AACpE,SAAO,KAAK;AACb;AAFgB;AAST,SAAS,cAAgC,SAAwB;AACvE,SAAO,KAAK;AACb;AAFgB;AAST,SAAS,MAAwB,SAAsB;AAC7D,SAAO,KAAK;AACb;AAFgB;AAST,SAAS,WAA6B,SAAwB;AACpE,SAAO,OAAO;AACf;AAFgB;AAiBT,SAAS,cAAc,KAAmB;AAChD,SAAO,IAAI;AACZ;AAFgB;AA6CT,SAAS,UAAU,SAAiB,KAAmB,OAAgB;AAC7E,SAAO,QAAQ,IAAI,YAAY,QAAQ,YAAY,IAAI,YAAY;AACpE;AAFgB;AAST,SAAS,QAA0B,SAAwB;AACjE,SAAO,KAAK;AACb;AAFgB;AAST,SAAS,YAAiC,QAAsB;AACtE,SAAO,KAAK;AACb;AAFgB;AAST,SAAS,eAAoC,WAAyB;AAC5E,SAAO,KAAK;AACb;AAFgB;AAST,SAAS,YAAiC,QAAuB;AACvE,SAAO,MAAM;AACd;AAFgB;AAmDT,SAAS,mCAMf,aACA,qBACA,gBACA,WACkE;AAClE,MAAI,OAAO,cAAc,aAAa;AACrC,WAAO,KAAK,eAAe,uBAAuB,kBAAmB;AAAA,EACtE;AAEA,MAAI,OAAO,mBAAmB,aAAa;AAC1C,WAAO,KAAK,eAAe,uBAAuB;AAAA,EACnD;AAEA,SAAO,KAAK,eAAe;AAC5B;AApBgB;AAmDT,SAAS,YAAiC,SAAY,WAAW,OAAmC;AAC1G,SAAO,IAAI,WAAW,MAAM,QAAQ;AACrC;AAFgB;AAsBT,SAAS,YACf,WACA,SACqF;AACrF,SAAO,gCAAgC,WAAW,SAAS;AAC5D;AALgB;AA+BT,SAAS,YACf,WACA,WACA,SAC+F;AAC/F,SAAO,GAAG,OAAO,YAAY,cAAc,YAAY,SAAS,IAAI,YAAY,WAAW,OAAO,KAAK;AACxG;AANgB;AAqCT,SAAS,KAAK,eAA+B,OAAuC;AAC1F,MAAI,OAAO,kBAAkB,UAAU;AAEtC,oBAAgB,KAAK,OAAO,eAAe,QAAQ,KAAK,KAAK,IAAI,KAAK,GAAK;AAAA,EAC5E;AAEA,SAAO,OAAO,UAAU,WAAW,MAAM,iBAAiB,WAAW,MAAM;AAC5E;AAPgB;AAYT,IAAM,kBAAkB;AAAA,EAI9B,WAAW;AAAA,EAKX,UAAU;AAAA,EAKV,WAAW;AAAA,EAKX,UAAU;AAAA,EAKV,eAAe;AAAA,EAKf,cAAc;AAAA,EAKd,cAAc;AACf;AAUO,IAAK,QAAL,kBAAKA,WAAL;AAIN,EAAAA,OAAA,WAAQ;AAKR,EAAAA,OAAA,eAAY;AAKZ,EAAAA,OAAA,YAAS;AAdE,SAAAA;AAAA,GAAA;","names":["Faces"]}
|
package/package.json
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@discordjs/formatters",
|
|
3
|
+
"version": "0.1.1-dev.1670026137-a0d6bc4.0",
|
|
4
|
+
"description": "A set of functions to format strings for Discord.",
|
|
5
|
+
"scripts": {
|
|
6
|
+
"test": "vitest run",
|
|
7
|
+
"build": "tsup",
|
|
8
|
+
"lint": "prettier --check . && cross-env TIMING=1 eslint src __tests__ --ext .mjs,.js,.ts --format=pretty",
|
|
9
|
+
"format": "prettier --write . && cross-env TIMING=1 eslint src __tests__ --ext .mjs,.js,.ts --fix --format=pretty",
|
|
10
|
+
"docs": "api-extractor run --local",
|
|
11
|
+
"prepack": "yarn build && yarn lint",
|
|
12
|
+
"changelog": "git cliff --prepend ./CHANGELOG.md -u -c ./cliff.toml -r ../../ --include-path 'packages/formatters/*'",
|
|
13
|
+
"release": "cliff-jumper"
|
|
14
|
+
},
|
|
15
|
+
"main": "./dist/index.js",
|
|
16
|
+
"module": "./dist/index.mjs",
|
|
17
|
+
"typings": "./dist/index.d.ts",
|
|
18
|
+
"exports": {
|
|
19
|
+
"import": "./dist/index.mjs",
|
|
20
|
+
"require": "./dist/index.js",
|
|
21
|
+
"types": "./dist/index.d.ts"
|
|
22
|
+
},
|
|
23
|
+
"directories": {
|
|
24
|
+
"lib": "src",
|
|
25
|
+
"test": "__tests__"
|
|
26
|
+
},
|
|
27
|
+
"files": [
|
|
28
|
+
"dist"
|
|
29
|
+
],
|
|
30
|
+
"contributors": [
|
|
31
|
+
"Crawl <icrawltogo@gmail.com>",
|
|
32
|
+
"SpaceEEC <spaceeec@yahoo.com>",
|
|
33
|
+
"Vlad Frangu <kingdgrizzle@gmail.com>",
|
|
34
|
+
"Aura Román <kyradiscord@gmail.com>"
|
|
35
|
+
],
|
|
36
|
+
"license": "Apache-2.0",
|
|
37
|
+
"keywords": [],
|
|
38
|
+
"repository": {
|
|
39
|
+
"type": "git",
|
|
40
|
+
"url": "git+https://github.com/discordjs/discord.js.git"
|
|
41
|
+
},
|
|
42
|
+
"bugs": {
|
|
43
|
+
"url": "https://github.com/discordjs/discord.js/issues"
|
|
44
|
+
},
|
|
45
|
+
"homepage": "https://discord.js.org",
|
|
46
|
+
"dependencies": {
|
|
47
|
+
"discord-api-types": "^0.37.20"
|
|
48
|
+
},
|
|
49
|
+
"devDependencies": {
|
|
50
|
+
"@favware/cliff-jumper": "^1.8.8",
|
|
51
|
+
"@microsoft/api-extractor": "^7.32.0",
|
|
52
|
+
"@types/node": "^16.18.3",
|
|
53
|
+
"@vitest/coverage-c8": "^0.25.3",
|
|
54
|
+
"cross-env": "^7.0.3",
|
|
55
|
+
"eslint": "^8.28.0",
|
|
56
|
+
"eslint-config-neon": "^0.1.40",
|
|
57
|
+
"eslint-formatter-pretty": "^4.1.0",
|
|
58
|
+
"prettier": "^2.8.0",
|
|
59
|
+
"tsup": "^6.5.0",
|
|
60
|
+
"typescript": "^4.9.3",
|
|
61
|
+
"vitest": "^0.25.3"
|
|
62
|
+
},
|
|
63
|
+
"engines": {
|
|
64
|
+
"node": ">=16.9.0"
|
|
65
|
+
},
|
|
66
|
+
"publishConfig": {
|
|
67
|
+
"access": "public"
|
|
68
|
+
}
|
|
69
|
+
}
|