@fallencodes/seyfert-utils 1.0.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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Liam L
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,2 @@
1
+ # Seyfert Utils
2
+ A collection of various utility/helper code I use in my Seyfert projects.
@@ -0,0 +1,26 @@
1
+ import { Container, ContainerBuilderComponents, Section, Separator, TextDisplay } from 'seyfert';
2
+ import { ButtonStyle, Spacing } from 'seyfert/lib/types/index.js';
3
+ export declare function createTextDisplay(content: string): TextDisplay;
4
+ type SectionAccessory = ({
5
+ url?: string;
6
+ type: 'button';
7
+ label?: string;
8
+ skuId?: string;
9
+ customId?: string;
10
+ style: ButtonStyle;
11
+ disabled?: boolean;
12
+ }) | ({
13
+ url: string;
14
+ type: 'thumbnail';
15
+ spoiler?: boolean;
16
+ description?: string;
17
+ });
18
+ export declare function createTextSection(content: string, accessory: SectionAccessory): Section;
19
+ export declare function createSeparator(spacing?: Spacing, divider?: boolean): Separator;
20
+ interface ContainerOptions {
21
+ color?: number | string;
22
+ spoiler?: boolean;
23
+ }
24
+ export declare function createContainer(components: ContainerBuilderComponents[], options?: ContainerOptions): Container;
25
+ export {};
26
+ //# sourceMappingURL=components.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"components.d.ts","sourceRoot":"","sources":["../src/components.ts"],"names":[],"mappings":"AAAA,OAAO,EAAU,SAAS,EAAE,0BAA0B,EAAE,OAAO,EAAE,SAAS,EAAE,WAAW,EAAa,MAAM,SAAS,CAAC;AACpH,OAAO,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAC;AAElE,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,MAAM,GAAG,WAAW,CAE9D;AAED,KAAK,gBAAgB,GAAG,CAAC;IACrB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,QAAQ,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,KAAK,EAAE,WAAW,CAAC;IACnB,QAAQ,CAAC,EAAE,OAAO,CAAC;CACtB,CAAC,GAAG,CAAC;IACF,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,WAAW,CAAC;IAClB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,WAAW,CAAC,EAAE,MAAM,CAAC;CACxB,CAAC,CAAA;AAEF,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,gBAAgB,GAAG,OAAO,CAqBvF;AAED,wBAAgB,eAAe,CAAC,OAAO,CAAC,EAAE,OAAO,EAAE,OAAO,CAAC,EAAE,OAAO,aAEnE;AAED,UAAU,gBAAgB;IACtB,KAAK,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IACxB,OAAO,CAAC,EAAE,OAAO,CAAC;CACrB;AAED,wBAAgB,eAAe,CAAC,UAAU,EAAE,0BAA0B,EAAE,EAAE,OAAO,CAAC,EAAE,gBAAgB,GAAG,SAAS,CAW/G"}
@@ -0,0 +1,48 @@
1
+ import { Button, Container, Section, Separator, TextDisplay, Thumbnail } from 'seyfert';
2
+ export function createTextDisplay(content) {
3
+ return new TextDisplay({ content });
4
+ }
5
+ ;
6
+ export function createTextSection(content, accessory) {
7
+ const section = new Section().addComponents(new TextDisplay({ content }));
8
+ switch (accessory.type) {
9
+ case 'button':
10
+ section.setAccessory(new Button({
11
+ url: accessory.url,
12
+ label: accessory.label,
13
+ style: accessory.style,
14
+ sku_id: accessory.skuId,
15
+ disabled: accessory.disabled,
16
+ custom_id: accessory.customId
17
+ }));
18
+ break;
19
+ case 'thumbnail':
20
+ section.setAccessory(new Thumbnail({
21
+ spoiler: accessory.spoiler,
22
+ media: { url: accessory.url },
23
+ description: accessory.description
24
+ }));
25
+ break;
26
+ }
27
+ ;
28
+ return section;
29
+ }
30
+ ;
31
+ export function createSeparator(spacing, divider) {
32
+ return new Separator({ spacing, divider });
33
+ }
34
+ ;
35
+ export function createContainer(components, options) {
36
+ const container = new Container({ spoiler: options?.spoiler }).setComponents(components);
37
+ if (options?.color) {
38
+ let color;
39
+ if (typeof options.color === 'number')
40
+ color = options.color;
41
+ if (typeof options.color === 'string')
42
+ color = parseInt(options.color.toString().replace('#', '0x'));
43
+ container.setColor(color);
44
+ }
45
+ ;
46
+ return container;
47
+ }
48
+ ;
@@ -0,0 +1,3 @@
1
+ export * from './utilities.js';
2
+ export * from './components.js';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,iBAAiB,CAAC"}
package/build/index.js ADDED
@@ -0,0 +1,2 @@
1
+ export * from './utilities.js';
2
+ export * from './components.js';
@@ -0,0 +1,10 @@
1
+ import { User, GuildMember } from 'seyfert';
2
+ export declare function s(content: string): string;
3
+ export declare function randomId(length: number): string;
4
+ export declare function wait(time: number): Promise<unknown>;
5
+ export declare function isValidSnowflake(snowflake: string): boolean;
6
+ export declare function truncateString(string: string, maxLength?: number): string;
7
+ type NameType = 'display' | 'display-s' | 'display-username' | 'display-username-s' | 'username-id' | 'username-id-s';
8
+ export declare function name(user: User | GuildMember, type?: NameType): string;
9
+ export {};
10
+ //# sourceMappingURL=utilities.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utilities.d.ts","sourceRoot":"","sources":["../src/utilities.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,IAAI,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAG5C,wBAAgB,CAAC,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAEzC;AAGD,wBAAgB,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAE/C;AAGD,wBAAgB,IAAI,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAEnD;AAGD,wBAAgB,gBAAgB,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAI3D;AAGD,wBAAgB,cAAc,CAAC,MAAM,EAAE,MAAM,EAAE,SAAS,GAAE,MAAY,GAAG,MAAM,CAI9E;AAED,KAAK,QAAQ,GACX,SAAS,GACT,WAAW,GACX,kBAAkB,GAClB,oBAAoB,GACpB,aAAa,GACb,eAAe,CAAA;AAGjB,wBAAgB,IAAI,CAAC,IAAI,EAAE,IAAI,GAAG,WAAW,EAAE,IAAI,GAAE,QAAoB,GAAG,MAAM,CAWjF"}
@@ -0,0 +1,49 @@
1
+ import { DiscordSnowflake, Snowflake } from '@sapphire/snowflake';
2
+ import { customAlphabet } from 'nanoid';
3
+ import { length, slice } from 'multibyte';
4
+ import { User } from 'seyfert';
5
+ /* Sanitises a string, disabling all simple Discord markdown by prepending "\". */
6
+ export function s(content) {
7
+ return content.replace(/`/g, '\\`').replace(/\*/g, '\\*').replace(/\|/g, '\\|').replace(/_/g, '\\_');
8
+ }
9
+ ;
10
+ /* Generates a random alphanumeric string with the provided length. */
11
+ export function randomId(length) {
12
+ return customAlphabet('0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz')(length);
13
+ }
14
+ ;
15
+ /* Pauses code execution for the provided milliseconds, allowing for in-line code pauses. */
16
+ export function wait(time) {
17
+ return new Promise((resolve) => setTimeout(resolve, time));
18
+ }
19
+ ;
20
+ /* Checks if a provided string is a valid Discord snowflake. */
21
+ export function isValidSnowflake(snowflake) {
22
+ if (!/^\d{17,19}$/.test(snowflake))
23
+ return false;
24
+ const epoch = DiscordSnowflake.generate({ timestamp: DiscordSnowflake.epoch });
25
+ return Snowflake.compare(epoch, snowflake) < 0 && Snowflake.compare(snowflake, DiscordSnowflake.generate()) < 0;
26
+ }
27
+ ;
28
+ /* Truncates a string using UTF-8 safe encoding. */
29
+ export function truncateString(string, maxLength = 100) {
30
+ const strLength = length(string);
31
+ if (strLength <= maxLength)
32
+ return string;
33
+ return `${slice(string, 0, maxLength - 3)}...`;
34
+ }
35
+ ;
36
+ /* Formats a User or GuildMember username or display name with or without sanitisation. */
37
+ export function name(user, type = 'display') {
38
+ const display = user instanceof User ? user.globalName : user.displayName;
39
+ switch (type) {
40
+ case 'display': return display ?? user.username;
41
+ case 'display-s': return s(display ?? user.username);
42
+ case 'display-username': return display ? `${display} (${user.username})` : user.username;
43
+ case 'display-username-s': return s(display ? `${display} (${user.username})` : user.username);
44
+ case 'username-id': return `${user.username} (${user.id})`;
45
+ case 'username-id-s': return s(`${user.username} (${user.id})`);
46
+ }
47
+ ;
48
+ }
49
+ ;
package/package.json ADDED
@@ -0,0 +1,39 @@
1
+ {
2
+ "name": "@fallencodes/seyfert-utils",
3
+ "type": "module",
4
+ "version": "1.0.0",
5
+ "license": "MIT",
6
+ "description": "A collection of various utility/helper code I use in my Seyfert projects.",
7
+ "engines": {
8
+ "node": ">=22"
9
+ },
10
+ "publishConfig": {
11
+ "access": "public"
12
+ },
13
+ "repository": {
14
+ "url": "https://github.com/TheFallenSpirit/seyfert-utils"
15
+ },
16
+ "author": {
17
+ "name": "Liam L",
18
+ "email": "thefallenspirit@outlook.com",
19
+ "url": "https://github.com/TheFallenSpirit"
20
+ },
21
+ "files": [
22
+ "build",
23
+ "LICENSE",
24
+ "README.md"
25
+ ],
26
+ "dependencies": {
27
+ "@sapphire/snowflake": "^3.5.5",
28
+ "multibyte": "^1.0.5",
29
+ "nanoid": "^5.1.6",
30
+ "seyfert": "^4.0.0"
31
+ },
32
+ "devDependencies": {
33
+ "@types/node": "^25.0.3",
34
+ "typescript": "^5.9.3"
35
+ },
36
+ "scripts": {
37
+ "build": "rm -r build; tsc"
38
+ }
39
+ }