Utility functions for different data types and operations.
This package published as utils module in umd.
<script src="https://unpkg.com/@termehui/utils"></script>npm i @termehui/utilsReplace all non-numeric character in string with separator character.
import { unifySeparator } from "@termehui/utils";
unifySeparator("-3,233,312.33", "/"); // -3/233/312.33
unifySeparator("123 , 456", ","); // 123,456Format number with separator.
import { formatNumber } from "@termehui/utils";
formatNumber(12345.456, ","); // 12,345.345
formatNumber("-3214.222", ","); // -3,214.222Extract numeric character from string.
Caution: this function extract all numeric characters (-, [0-9], .)/ for parsing number use parseNumber function.
import { extractNumeric } from "@termehui/utils";
extractNumeric("$ 12345.00002"); // "12345.00002"
extractNumeric("Balance is : -32123.0001"); // "-32123.0001"
parseNumber("with none - string number ."); // "-."Parse number from string.
import { parseNumber } from "@termehui/utils";
parseNumber("$ 12345.00002"); // 12345.00002
parseNumber("with none . string number -"); // NaNCreate a deep clone of object.
function deepClone<T = any>(v: unknown): T;Return alter for empty value.
Make slugify string from strings. join multiple strings and remove spaces.
Search for value in replacement object and return replacement if found, otherwise returns value itself.
Note: you can use * key in replacement to define default value if no replacement is defined.
Truncate string and add ... to end of string if string length bigger than truncate length.
Convert value to string. if falsy value passed this function returns empty string.
Concatenate non-falsy value with space.
Helper class to generate colors for svg shape and chart.
import { ColorSpace } from "@termehui/utils";
enum Color {
Primary,
Red,
}
const colors = new ColorSpace<Color>();
colors.AddColor(Color.Primary, "red", "orange", 255, 10, 0);
const red = colors.color(Color.Primary);
const palette = colors.all();
const alpha = colors.alpha(Color.Primary, 0.5);
const linearAlphaBG = colors.linearAlpha(Color.Primary, svgContext, svgArea);
const linearBG = colors.linear(Color.Primary, svgContext, svgArea);
const linearIBG = colors.linearInverse(Color.Primary, svgContext, svgArea);
const radialBG = colors.radial(Color.Primary, svgContext, svgArea);
const radialIBG = colors.radialInverse(Color.Primary, svgContext, svgArea);