UNPKG

@selfcommunity/react-ui

Version:

React UI Components to integrate a Community created with SelfCommunity Platform.

13 lines (12 loc) 608 B
import { Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime"; export const DEFAULT_COUNTERS_LIMIT = 3; export function numberFormatter(num) { const surplus = num === DEFAULT_COUNTERS_LIMIT ? 1 : num < DEFAULT_COUNTERS_LIMIT ? num : num - DEFAULT_COUNTERS_LIMIT; if (surplus > 999999) { return _jsxs(_Fragment, { children: ["+", (Math.abs(surplus) / 1000000).toFixed(1), "M"] }); } else if (surplus > 999) { return _jsxs(_Fragment, { children: ["+", (Math.abs(surplus) / 1000).toFixed(1), "K"] }); } return _jsxs(_Fragment, { children: ["+", surplus] }); }