@fluxerjs/util 1.1.9 → 1.2.1
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/dist/index.d.mts +27 -2
- package/dist/index.d.ts +27 -2
- package/dist/index.js +24 -0
- package/dist/index.mjs +22 -0
- package/package.json +3 -3
package/dist/index.d.mts
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* Flags with values exceeding 2^30 may exhibit unexpected behavior. For permission-style
|
|
6
6
|
* bitfields with more than 30 bits, consider using BigInt-based implementations.
|
|
7
7
|
*/
|
|
8
|
-
type BitFieldResolvable<S extends string> = S | number | BitField<S> | (S | number | BitField<S>)[];
|
|
8
|
+
type BitFieldResolvable<S extends string> = S | bigint | number | BitField<S> | (S | number | BitField<S>)[];
|
|
9
9
|
declare class BitField<S extends string> {
|
|
10
10
|
static Flags: Record<string, number>;
|
|
11
11
|
defaultBit: number;
|
|
@@ -259,6 +259,31 @@ declare function parseEmoji(emoji: string): {
|
|
|
259
259
|
name: string;
|
|
260
260
|
animated?: boolean;
|
|
261
261
|
} | null;
|
|
262
|
+
/**
|
|
263
|
+
* Parse a user mention string or raw snowflake and extract the user ID.
|
|
264
|
+
* Supports: <@123456789012345678>, <@!123456789012345678>, or raw 17–19 digit snowflake.
|
|
265
|
+
* @param arg - String that may contain a user mention or raw user ID
|
|
266
|
+
* @returns The user ID if valid, otherwise null
|
|
267
|
+
* @example
|
|
268
|
+
* parseUserMention('<@!123456789012345678>'); // '123456789012345678'
|
|
269
|
+
* parseUserMention('<@123456789012345678>'); // '123456789012345678'
|
|
270
|
+
* parseUserMention('123456789012345678'); // '123456789012345678'
|
|
271
|
+
*/
|
|
272
|
+
declare function parseUserMention(arg: string): string | null;
|
|
273
|
+
/**
|
|
274
|
+
* Parse prefix command content into command name and args.
|
|
275
|
+
* Returns null if content does not start with the prefix.
|
|
276
|
+
* @param content - Raw message content
|
|
277
|
+
* @param prefix - Command prefix (e.g. '!')
|
|
278
|
+
* @returns { command, args } or null
|
|
279
|
+
* @example
|
|
280
|
+
* parsePrefixCommand('!ping', '!'); // { command: 'ping', args: [] }
|
|
281
|
+
* parsePrefixCommand('!hello world', '!'); // { command: 'hello', args: ['world'] }
|
|
282
|
+
*/
|
|
283
|
+
declare function parsePrefixCommand(content: string, prefix: string): {
|
|
284
|
+
command: string;
|
|
285
|
+
args: string[];
|
|
286
|
+
} | null;
|
|
262
287
|
/**
|
|
263
288
|
* Parse a role mention string (e.g. <@&123456>) and extract the role ID.
|
|
264
289
|
* @param arg - String that may contain a role mention
|
|
@@ -301,4 +326,4 @@ declare function resolveTenorToImageUrl(tenorViewUrl: string): Promise<TenorMedi
|
|
|
301
326
|
|
|
302
327
|
declare function emitDeprecationWarning(symbol: string, message: string): void;
|
|
303
328
|
|
|
304
|
-
export { ALL_PERMISSIONS_BIGINT, BitField, type BitFieldResolvable, FLUXER_EPOCH, MessageFlagsBitField, MessageFlagsBits, type MessageFlagsResolvable, type MessageFlagsString, PermissionFlags, PermissionFlagsMap, type PermissionResolvable, type PermissionString, PermissionsBitField, SnowflakeUtil, type TenorMediaResult, UserFlagsBitField, UserFlagsBits, type UserFlagsResolvable, type UserFlagsString, emitDeprecationWarning, escapeMarkdown, formatColor, formatEmoji, formatTimestamp, getUnicodeFromShortcode, parseEmoji, parseRoleMention, resolveColor, resolvePermissionsToBitfield, resolveTenorToImageUrl, truncate };
|
|
329
|
+
export { ALL_PERMISSIONS_BIGINT, BitField, type BitFieldResolvable, FLUXER_EPOCH, MessageFlagsBitField, MessageFlagsBits, type MessageFlagsResolvable, type MessageFlagsString, PermissionFlags, PermissionFlagsMap, type PermissionResolvable, type PermissionString, PermissionsBitField, SnowflakeUtil, type TenorMediaResult, UserFlagsBitField, UserFlagsBits, type UserFlagsResolvable, type UserFlagsString, emitDeprecationWarning, escapeMarkdown, formatColor, formatEmoji, formatTimestamp, getUnicodeFromShortcode, parseEmoji, parsePrefixCommand, parseRoleMention, parseUserMention, resolveColor, resolvePermissionsToBitfield, resolveTenorToImageUrl, truncate };
|
package/dist/index.d.ts
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* Flags with values exceeding 2^30 may exhibit unexpected behavior. For permission-style
|
|
6
6
|
* bitfields with more than 30 bits, consider using BigInt-based implementations.
|
|
7
7
|
*/
|
|
8
|
-
type BitFieldResolvable<S extends string> = S | number | BitField<S> | (S | number | BitField<S>)[];
|
|
8
|
+
type BitFieldResolvable<S extends string> = S | bigint | number | BitField<S> | (S | number | BitField<S>)[];
|
|
9
9
|
declare class BitField<S extends string> {
|
|
10
10
|
static Flags: Record<string, number>;
|
|
11
11
|
defaultBit: number;
|
|
@@ -259,6 +259,31 @@ declare function parseEmoji(emoji: string): {
|
|
|
259
259
|
name: string;
|
|
260
260
|
animated?: boolean;
|
|
261
261
|
} | null;
|
|
262
|
+
/**
|
|
263
|
+
* Parse a user mention string or raw snowflake and extract the user ID.
|
|
264
|
+
* Supports: <@123456789012345678>, <@!123456789012345678>, or raw 17–19 digit snowflake.
|
|
265
|
+
* @param arg - String that may contain a user mention or raw user ID
|
|
266
|
+
* @returns The user ID if valid, otherwise null
|
|
267
|
+
* @example
|
|
268
|
+
* parseUserMention('<@!123456789012345678>'); // '123456789012345678'
|
|
269
|
+
* parseUserMention('<@123456789012345678>'); // '123456789012345678'
|
|
270
|
+
* parseUserMention('123456789012345678'); // '123456789012345678'
|
|
271
|
+
*/
|
|
272
|
+
declare function parseUserMention(arg: string): string | null;
|
|
273
|
+
/**
|
|
274
|
+
* Parse prefix command content into command name and args.
|
|
275
|
+
* Returns null if content does not start with the prefix.
|
|
276
|
+
* @param content - Raw message content
|
|
277
|
+
* @param prefix - Command prefix (e.g. '!')
|
|
278
|
+
* @returns { command, args } or null
|
|
279
|
+
* @example
|
|
280
|
+
* parsePrefixCommand('!ping', '!'); // { command: 'ping', args: [] }
|
|
281
|
+
* parsePrefixCommand('!hello world', '!'); // { command: 'hello', args: ['world'] }
|
|
282
|
+
*/
|
|
283
|
+
declare function parsePrefixCommand(content: string, prefix: string): {
|
|
284
|
+
command: string;
|
|
285
|
+
args: string[];
|
|
286
|
+
} | null;
|
|
262
287
|
/**
|
|
263
288
|
* Parse a role mention string (e.g. <@&123456>) and extract the role ID.
|
|
264
289
|
* @param arg - String that may contain a role mention
|
|
@@ -301,4 +326,4 @@ declare function resolveTenorToImageUrl(tenorViewUrl: string): Promise<TenorMedi
|
|
|
301
326
|
|
|
302
327
|
declare function emitDeprecationWarning(symbol: string, message: string): void;
|
|
303
328
|
|
|
304
|
-
export { ALL_PERMISSIONS_BIGINT, BitField, type BitFieldResolvable, FLUXER_EPOCH, MessageFlagsBitField, MessageFlagsBits, type MessageFlagsResolvable, type MessageFlagsString, PermissionFlags, PermissionFlagsMap, type PermissionResolvable, type PermissionString, PermissionsBitField, SnowflakeUtil, type TenorMediaResult, UserFlagsBitField, UserFlagsBits, type UserFlagsResolvable, type UserFlagsString, emitDeprecationWarning, escapeMarkdown, formatColor, formatEmoji, formatTimestamp, getUnicodeFromShortcode, parseEmoji, parseRoleMention, resolveColor, resolvePermissionsToBitfield, resolveTenorToImageUrl, truncate };
|
|
329
|
+
export { ALL_PERMISSIONS_BIGINT, BitField, type BitFieldResolvable, FLUXER_EPOCH, MessageFlagsBitField, MessageFlagsBits, type MessageFlagsResolvable, type MessageFlagsString, PermissionFlags, PermissionFlagsMap, type PermissionResolvable, type PermissionString, PermissionsBitField, SnowflakeUtil, type TenorMediaResult, UserFlagsBitField, UserFlagsBits, type UserFlagsResolvable, type UserFlagsString, emitDeprecationWarning, escapeMarkdown, formatColor, formatEmoji, formatTimestamp, getUnicodeFromShortcode, parseEmoji, parsePrefixCommand, parseRoleMention, parseUserMention, resolveColor, resolvePermissionsToBitfield, resolveTenorToImageUrl, truncate };
|
package/dist/index.js
CHANGED
|
@@ -38,7 +38,9 @@ __export(index_exports, {
|
|
|
38
38
|
formatTimestamp: () => formatTimestamp,
|
|
39
39
|
getUnicodeFromShortcode: () => getUnicodeFromShortcode,
|
|
40
40
|
parseEmoji: () => parseEmoji,
|
|
41
|
+
parsePrefixCommand: () => parsePrefixCommand,
|
|
41
42
|
parseRoleMention: () => parseRoleMention,
|
|
43
|
+
parseUserMention: () => parseUserMention,
|
|
42
44
|
resolveColor: () => resolveColor,
|
|
43
45
|
resolvePermissionsToBitfield: () => resolvePermissionsToBitfield,
|
|
44
46
|
resolveTenorToImageUrl: () => resolveTenorToImageUrl,
|
|
@@ -361,6 +363,26 @@ function parseEmoji(emoji) {
|
|
|
361
363
|
}
|
|
362
364
|
return { id: null, name: trimmed };
|
|
363
365
|
}
|
|
366
|
+
function parseUserMention(arg) {
|
|
367
|
+
if (arg == null || typeof arg !== "string") return null;
|
|
368
|
+
const trimmed = arg.trim();
|
|
369
|
+
if (trimmed.length === 0) return null;
|
|
370
|
+
const mentionMatch = trimmed.match(/^<@!?(\d{17,19})>$/);
|
|
371
|
+
if (mentionMatch) return mentionMatch[1];
|
|
372
|
+
if (/^\d{17,19}$/.test(trimmed)) return trimmed;
|
|
373
|
+
return null;
|
|
374
|
+
}
|
|
375
|
+
function parsePrefixCommand(content, prefix) {
|
|
376
|
+
if (content == null || typeof content !== "string") return null;
|
|
377
|
+
const trimmed = content.trim();
|
|
378
|
+
if (!trimmed.startsWith(prefix)) return null;
|
|
379
|
+
const rest = trimmed.slice(prefix.length).trim();
|
|
380
|
+
if (rest.length === 0) return null;
|
|
381
|
+
const parts = rest.split(/\s+/);
|
|
382
|
+
const command = parts[0]?.toLowerCase() ?? "";
|
|
383
|
+
const args = parts.slice(1);
|
|
384
|
+
return { command, args };
|
|
385
|
+
}
|
|
364
386
|
function parseRoleMention(arg) {
|
|
365
387
|
if (arg == null || typeof arg !== "string") return null;
|
|
366
388
|
const match = arg.trim().match(/^<@&(\d{17,19})>$/);
|
|
@@ -478,7 +500,9 @@ function emitDeprecationWarning(symbol, message) {
|
|
|
478
500
|
formatTimestamp,
|
|
479
501
|
getUnicodeFromShortcode,
|
|
480
502
|
parseEmoji,
|
|
503
|
+
parsePrefixCommand,
|
|
481
504
|
parseRoleMention,
|
|
505
|
+
parseUserMention,
|
|
482
506
|
resolveColor,
|
|
483
507
|
resolvePermissionsToBitfield,
|
|
484
508
|
resolveTenorToImageUrl,
|
package/dist/index.mjs
CHANGED
|
@@ -313,6 +313,26 @@ function parseEmoji(emoji) {
|
|
|
313
313
|
}
|
|
314
314
|
return { id: null, name: trimmed };
|
|
315
315
|
}
|
|
316
|
+
function parseUserMention(arg) {
|
|
317
|
+
if (arg == null || typeof arg !== "string") return null;
|
|
318
|
+
const trimmed = arg.trim();
|
|
319
|
+
if (trimmed.length === 0) return null;
|
|
320
|
+
const mentionMatch = trimmed.match(/^<@!?(\d{17,19})>$/);
|
|
321
|
+
if (mentionMatch) return mentionMatch[1];
|
|
322
|
+
if (/^\d{17,19}$/.test(trimmed)) return trimmed;
|
|
323
|
+
return null;
|
|
324
|
+
}
|
|
325
|
+
function parsePrefixCommand(content, prefix) {
|
|
326
|
+
if (content == null || typeof content !== "string") return null;
|
|
327
|
+
const trimmed = content.trim();
|
|
328
|
+
if (!trimmed.startsWith(prefix)) return null;
|
|
329
|
+
const rest = trimmed.slice(prefix.length).trim();
|
|
330
|
+
if (rest.length === 0) return null;
|
|
331
|
+
const parts = rest.split(/\s+/);
|
|
332
|
+
const command = parts[0]?.toLowerCase() ?? "";
|
|
333
|
+
const args = parts.slice(1);
|
|
334
|
+
return { command, args };
|
|
335
|
+
}
|
|
316
336
|
function parseRoleMention(arg) {
|
|
317
337
|
if (arg == null || typeof arg !== "string") return null;
|
|
318
338
|
const match = arg.trim().match(/^<@&(\d{17,19})>$/);
|
|
@@ -429,7 +449,9 @@ export {
|
|
|
429
449
|
formatTimestamp,
|
|
430
450
|
getUnicodeFromShortcode,
|
|
431
451
|
parseEmoji,
|
|
452
|
+
parsePrefixCommand,
|
|
432
453
|
parseRoleMention,
|
|
454
|
+
parseUserMention,
|
|
433
455
|
resolveColor,
|
|
434
456
|
resolvePermissionsToBitfield,
|
|
435
457
|
resolveTenorToImageUrl,
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"publishConfig": {
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
|
-
"version": "1.1
|
|
6
|
+
"version": "1.2.1",
|
|
7
7
|
"description": "Shared utilities for @fluxerjs/core",
|
|
8
8
|
"repository": {
|
|
9
9
|
"type": "git",
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
],
|
|
21
21
|
"license": "Apache-2.0",
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@fluxerjs/types": "1.1
|
|
23
|
+
"@fluxerjs/types": "1.2.1"
|
|
24
24
|
},
|
|
25
25
|
"main": "./dist/index.js",
|
|
26
26
|
"module": "./dist/index.mjs",
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
"vitest": "^4.0.18"
|
|
42
42
|
},
|
|
43
43
|
"scripts": {
|
|
44
|
-
"build": "pnpm exec tsx ../../scripts/generate-emoji-shortcodes.ts && tsup
|
|
44
|
+
"build": "pnpm exec tsx ../../scripts/generate-emoji-shortcodes.ts && tsup",
|
|
45
45
|
"clean": "rm -rf dist",
|
|
46
46
|
"lint": "eslint src --max-warnings 0 --config ../../eslint.config.js",
|
|
47
47
|
"lint:fix": "eslint src --fix --config ../../eslint.config.js",
|