mirror of
https://github.com/ershisan99/DevToysWeb.git
synced 2025-12-17 04:59:23 +00:00
perf(bundle): drop fp-ts
This commit is contained in:
16
lib/base.ts
16
lib/base.ts
@@ -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, ",");
|
||||
|
||||
Reference in New Issue
Block a user