@fluxerjs/util 1.1.1 → 1.1.2
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 +11 -1
- package/dist/index.d.ts +11 -1
- package/dist/index.js +28 -0
- package/dist/index.mjs +27 -0
- package/package.json +2 -2
package/dist/index.d.mts
CHANGED
|
@@ -119,6 +119,16 @@ declare class PermissionsBitField extends BitField<PermissionString> {
|
|
|
119
119
|
static Flags: Record<string, number>;
|
|
120
120
|
}
|
|
121
121
|
type PermissionResolvable = BitFieldResolvable<PermissionString>;
|
|
122
|
+
/**
|
|
123
|
+
* Resolve permission(s) to an API bitfield string. Uses BigInt to avoid overflow for flags > 2^31.
|
|
124
|
+
* @param perms - Permission string (e.g. "2048"), number, PermissionString, array of permissions, or PermissionsBitField
|
|
125
|
+
* @returns String bitfield for API (e.g. "8933636165185")
|
|
126
|
+
* @example
|
|
127
|
+
* resolvePermissionsToBitfield('2048'); // "2048"
|
|
128
|
+
* resolvePermissionsToBitfield(PermissionFlags.SendMessages); // "2048"
|
|
129
|
+
* resolvePermissionsToBitfield(['SendMessages', 'ViewChannel']); // combined bitfield
|
|
130
|
+
*/
|
|
131
|
+
declare function resolvePermissionsToBitfield(perms: PermissionResolvable): string;
|
|
122
132
|
|
|
123
133
|
/**
|
|
124
134
|
* Message flag bit values matching the API MessageFlags schema (openapi.json).
|
|
@@ -285,4 +295,4 @@ declare function resolveTenorToImageUrl(tenorViewUrl: string): Promise<TenorMedi
|
|
|
285
295
|
|
|
286
296
|
declare function emitDeprecationWarning(symbol: string, message: string): void;
|
|
287
297
|
|
|
288
|
-
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, parseEmoji, parseRoleMention, resolveColor, resolveTenorToImageUrl, truncate };
|
|
298
|
+
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, parseEmoji, parseRoleMention, resolveColor, resolvePermissionsToBitfield, resolveTenorToImageUrl, truncate };
|
package/dist/index.d.ts
CHANGED
|
@@ -119,6 +119,16 @@ declare class PermissionsBitField extends BitField<PermissionString> {
|
|
|
119
119
|
static Flags: Record<string, number>;
|
|
120
120
|
}
|
|
121
121
|
type PermissionResolvable = BitFieldResolvable<PermissionString>;
|
|
122
|
+
/**
|
|
123
|
+
* Resolve permission(s) to an API bitfield string. Uses BigInt to avoid overflow for flags > 2^31.
|
|
124
|
+
* @param perms - Permission string (e.g. "2048"), number, PermissionString, array of permissions, or PermissionsBitField
|
|
125
|
+
* @returns String bitfield for API (e.g. "8933636165185")
|
|
126
|
+
* @example
|
|
127
|
+
* resolvePermissionsToBitfield('2048'); // "2048"
|
|
128
|
+
* resolvePermissionsToBitfield(PermissionFlags.SendMessages); // "2048"
|
|
129
|
+
* resolvePermissionsToBitfield(['SendMessages', 'ViewChannel']); // combined bitfield
|
|
130
|
+
*/
|
|
131
|
+
declare function resolvePermissionsToBitfield(perms: PermissionResolvable): string;
|
|
122
132
|
|
|
123
133
|
/**
|
|
124
134
|
* Message flag bit values matching the API MessageFlags schema (openapi.json).
|
|
@@ -285,4 +295,4 @@ declare function resolveTenorToImageUrl(tenorViewUrl: string): Promise<TenorMedi
|
|
|
285
295
|
|
|
286
296
|
declare function emitDeprecationWarning(symbol: string, message: string): void;
|
|
287
297
|
|
|
288
|
-
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, parseEmoji, parseRoleMention, resolveColor, resolveTenorToImageUrl, truncate };
|
|
298
|
+
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, parseEmoji, parseRoleMention, resolveColor, resolvePermissionsToBitfield, resolveTenorToImageUrl, truncate };
|
package/dist/index.js
CHANGED
|
@@ -39,6 +39,7 @@ __export(index_exports, {
|
|
|
39
39
|
parseEmoji: () => parseEmoji,
|
|
40
40
|
parseRoleMention: () => parseRoleMention,
|
|
41
41
|
resolveColor: () => resolveColor,
|
|
42
|
+
resolvePermissionsToBitfield: () => resolvePermissionsToBitfield,
|
|
42
43
|
resolveTenorToImageUrl: () => resolveTenorToImageUrl,
|
|
43
44
|
truncate: () => truncate
|
|
44
45
|
});
|
|
@@ -219,6 +220,32 @@ var ALL_PERMISSIONS_BIGINT = (() => {
|
|
|
219
220
|
var PermissionsBitField = class extends BitField {
|
|
220
221
|
static Flags = PermissionFlagsMap;
|
|
221
222
|
};
|
|
223
|
+
function resolvePermissionsToBitfield(perms) {
|
|
224
|
+
if (typeof perms === "string") {
|
|
225
|
+
const num = Number(perms);
|
|
226
|
+
if (!Number.isNaN(num) && perms.trim() !== "") return perms;
|
|
227
|
+
const mapped = PermissionFlagsMap[perms];
|
|
228
|
+
if (mapped !== void 0) return String(mapped);
|
|
229
|
+
throw new RangeError(`Invalid permission string: ${perms}`);
|
|
230
|
+
}
|
|
231
|
+
if (typeof perms === "number") return String(perms);
|
|
232
|
+
if (typeof perms === "bigint") return String(perms);
|
|
233
|
+
if (perms instanceof PermissionsBitField) return String(BigInt(perms.bitfield));
|
|
234
|
+
if (Array.isArray(perms)) {
|
|
235
|
+
let acc = 0n;
|
|
236
|
+
for (const p of perms) {
|
|
237
|
+
let v;
|
|
238
|
+
if (typeof p === "number") v = BigInt(p);
|
|
239
|
+
else if (typeof p === "string") {
|
|
240
|
+
const mapped = PermissionFlagsMap[p];
|
|
241
|
+
v = mapped !== void 0 ? BigInt(mapped) : BigInt(Number(p) || 0);
|
|
242
|
+
} else v = BigInt(p.bitfield);
|
|
243
|
+
acc |= v;
|
|
244
|
+
}
|
|
245
|
+
return String(acc);
|
|
246
|
+
}
|
|
247
|
+
throw new RangeError(`Invalid permission resolvable: ${perms}`);
|
|
248
|
+
}
|
|
222
249
|
|
|
223
250
|
// src/MessageFlagsBitField.ts
|
|
224
251
|
var MessageFlagsBits = {
|
|
@@ -440,6 +467,7 @@ function emitDeprecationWarning(symbol, message) {
|
|
|
440
467
|
parseEmoji,
|
|
441
468
|
parseRoleMention,
|
|
442
469
|
resolveColor,
|
|
470
|
+
resolvePermissionsToBitfield,
|
|
443
471
|
resolveTenorToImageUrl,
|
|
444
472
|
truncate
|
|
445
473
|
});
|
package/dist/index.mjs
CHANGED
|
@@ -173,6 +173,32 @@ var ALL_PERMISSIONS_BIGINT = (() => {
|
|
|
173
173
|
var PermissionsBitField = class extends BitField {
|
|
174
174
|
static Flags = PermissionFlagsMap;
|
|
175
175
|
};
|
|
176
|
+
function resolvePermissionsToBitfield(perms) {
|
|
177
|
+
if (typeof perms === "string") {
|
|
178
|
+
const num = Number(perms);
|
|
179
|
+
if (!Number.isNaN(num) && perms.trim() !== "") return perms;
|
|
180
|
+
const mapped = PermissionFlagsMap[perms];
|
|
181
|
+
if (mapped !== void 0) return String(mapped);
|
|
182
|
+
throw new RangeError(`Invalid permission string: ${perms}`);
|
|
183
|
+
}
|
|
184
|
+
if (typeof perms === "number") return String(perms);
|
|
185
|
+
if (typeof perms === "bigint") return String(perms);
|
|
186
|
+
if (perms instanceof PermissionsBitField) return String(BigInt(perms.bitfield));
|
|
187
|
+
if (Array.isArray(perms)) {
|
|
188
|
+
let acc = 0n;
|
|
189
|
+
for (const p of perms) {
|
|
190
|
+
let v;
|
|
191
|
+
if (typeof p === "number") v = BigInt(p);
|
|
192
|
+
else if (typeof p === "string") {
|
|
193
|
+
const mapped = PermissionFlagsMap[p];
|
|
194
|
+
v = mapped !== void 0 ? BigInt(mapped) : BigInt(Number(p) || 0);
|
|
195
|
+
} else v = BigInt(p.bitfield);
|
|
196
|
+
acc |= v;
|
|
197
|
+
}
|
|
198
|
+
return String(acc);
|
|
199
|
+
}
|
|
200
|
+
throw new RangeError(`Invalid permission resolvable: ${perms}`);
|
|
201
|
+
}
|
|
176
202
|
|
|
177
203
|
// src/MessageFlagsBitField.ts
|
|
178
204
|
var MessageFlagsBits = {
|
|
@@ -393,6 +419,7 @@ export {
|
|
|
393
419
|
parseEmoji,
|
|
394
420
|
parseRoleMention,
|
|
395
421
|
resolveColor,
|
|
422
|
+
resolvePermissionsToBitfield,
|
|
396
423
|
resolveTenorToImageUrl,
|
|
397
424
|
truncate
|
|
398
425
|
};
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"publishConfig": {
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
|
-
"version": "1.1.
|
|
6
|
+
"version": "1.1.2",
|
|
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.1.2"
|
|
24
24
|
},
|
|
25
25
|
"main": "./dist/index.js",
|
|
26
26
|
"module": "./dist/index.mjs",
|