perf(bundle): drop fp-ts

This commit is contained in:
rusconn
2024-09-19 01:45:04 +09:00
parent f12adfa296
commit ddaed4a08b
4 changed files with 11 additions and 16 deletions

View File

@@ -1,5 +1,3 @@
import { chunksOf, intersperse } from "fp-ts/Array";
const match = (regex: RegExp) => (x: string) => regex.test(x);
export const isDecimal = match(/^[0-9]*$/);
@@ -8,10 +6,16 @@ export const isOctal = match(/^[0-7]*$/);
export const isBinary = match(/^[0-1]*$/);
const formatNumber = (digits: number, sep: string) => (s: string) => {
const a = [...s].reverse();
const b = chunksOf(digits)(a);
const c = intersperse([sep])(b);
return c.flat().reverse().join("");
const head = ((s.length - 1) % digits) + 1;
const buf = [];
buf.push(s.substring(0, head));
for (let i = head; i < s.length; i += digits) {
buf.push(sep, s.substring(i, i + digits));
}
return buf.join("");
};
export const formatDecimal = formatNumber(3, ",");