Utilities for Welcomer client and bot, such as text parsers.
npm install @welcomer-bot/utilsTo install from GitHub Packages, create a .npmrc file in your project root:
@welcomer-bot:registry=https://npm.pkg.github.com
Then authenticate with GitHub Packages using a personal access token with read:packages scope.
import {
parseMention,
parseMentions,
parseChannelMention,
parseRoleMention,
escapeMarkdown,
truncateText,
capitalizeFirst,
cleanWhitespace
} from '@welcomer-bot/utils';
// Parse Discord mentions
const userId = parseMention('<@123456789>'); // '123456789'
const userIds = parseMentions('<@123> and <@456>'); // ['123', '456']
const channelId = parseChannelMention('<#123456789>'); // '123456789'
const roleId = parseRoleMention('<@&123456789>'); // '123456789'
// Text utilities
const escaped = escapeMarkdown('*bold* _italic_'); // '\\*bold\\* \\_italic\\_'
const truncated = truncateText('Long text here', 10); // 'Long te...'
const capitalized = capitalizeFirst('hello'); // 'Hello'
const cleaned = cleanWhitespace(' hello world '); // 'hello world'Parses a Discord user mention and returns the user ID.
Parses multiple Discord user mentions and returns an array of user IDs.
Parses a Discord channel mention and returns the channel ID.
Parses a Discord role mention and returns the role ID.
Escapes markdown special characters in text.
Truncates text to the specified length, appending an ellipsis (default: '...').
Capitalizes the first letter of a string.
Removes extra whitespace from text and trims leading/trailing spaces.
npm installnpm testnpm run lintnpm run buildThis package is automatically published to GitHub Packages when a new release is created on GitHub.
To create a new release:
- Update the version in
package.json - Create a new tag:
git tag v1.0.0 - Push the tag:
git push origin v1.0.0 - Create a release on GitHub with the tag
The GitHub Actions workflow will automatically build, test, and publish the package.
MIT