enerthya.dev-common
v1.0.1
Published
Foundation utilities for the Enerthya ecosystem. Inspired by Loritta's common module.
Maintainers
Readme
enerthya.dev-common
Foundation utilities for the Enerthya ecosystem.
Inspired by Loritta's common module (LorittaBot/Loritta), adapted for Node.js/JavaScript.
Install
npm install enerthya.dev-commonWhat's inside
src/
├── index.js ← main entry point, exports everything
├── utils/
│ ├── StringUtils.js ← string helpers: truncate, capitalize, escape, detect URLs
│ ├── TimeUtils.js ← time helpers: formatTime, formatUptime, durationToMillis
│ ├── ArrayUtils.js ← array helpers: chunk, shuffle, deduplicate, partition
│ ├── RandomUtils.js ← random helpers: randomInt, randomIntBetween, chance
│ └── AsyncUtils.js ← async helpers: sleep, withTimeout, retry, batchProcess
├── constants/
│ └── index.js ← DISCORD limits, TIME constants, PACKAGE metadata
└── structures/
└── PackageValidator.js ← validates package folder structure at runtimeUsage
const { StringUtils, TimeUtils, ArrayUtils, sleep, chunk, formatTime } = require("enerthya.dev-common");
// String utilities
StringUtils.truncate("Hello World", 8); // "Hello..."
StringUtils.isHexColor("#FF5733"); // true
StringUtils.containsDiscordInvite("discord.gg/abc"); // true
// Time utilities
TimeUtils.formatTime(3661); // "1 hora, 1 minuto, 1 segundo"
TimeUtils.formatTimeShort(3661); // "1h 1m 1s"
TimeUtils.durationToMillis("1:30:00"); // 5400000
// Array utilities
ArrayUtils.chunk([1,2,3,4,5], 2); // [[1,2],[3,4],[5]]
ArrayUtils.deduplicate([1,2,2,3]); // [1,2,3]
ArrayUtils.randomPick(["a","b","c"]); // random element
// Random utilities
RandomUtils.randomIntBetween(1, 6); // dice roll
RandomUtils.chance(0.3); // true ~30% of the time
// Async utilities
await sleep(1000); // wait 1 second
await AsyncUtils.retry(fn, 3, 500); // retry up to 3x
// Convenience top-level exports
const { sleep, chunk, randomInt, formatTime } = require("enerthya.dev-common");Running tests
node test.jsNo external dependencies required. Uses only Node.js built-in assert.
Inspired by
Loritta — common module by MrPowerGamerBR.
Adapted for JavaScript/Node.js for the Enerthya project.
