mirror of
https://github.com/pezkuwichain/pezkuwi-common.git
synced 2026-10-21 19:16:19 +00:00
formatDecimal split digits with /(\d+?)(?=(\d{3})+(?!\d)|$)/g, whose
lookahead rescans the rest of a digit run at every position: quadratic in
the run's length (CodeQL js/polynomial-redos, high; inherited unchanged
from upstream). 20k digits took 258 ms, 200k about 25 s.
A loop now finds the same groups: within each digit run a group ends where
the digits left are a positive multiple of three, or at the end of the
string. Identical output to the pattern on 210,000 random inputs plus the
edge cases (letters around digits, short runs, negatives); 200k digits take
7 ms. The new spec case for a 60k-digit number fails on the old code.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@pezkuwi/util
Various useful utility functions that are used across all projects in the @pezkuwi namespace. It provides utility functions with additional safety checks, allowing not only for consistent coding, but also reducing the general boilerplate.
Usage
Installation -
yarn add @pezkuwi/util
Functions can be imported directly from the package, e.g.
import { isHex } from '@pezkuwi/util';