@fvc/utils
v3.0.3
Published
`@fvc/utils` provides shared utility functions used across the FE-VIS component library. It includes locale-aware text transformation with Azerbaijani character support, CSS custom property resolution for typography props, numeric validation, and a value
Readme
@fvc/utils
@fvc/utils provides shared utility functions used across the FE-VIS component library. It includes locale-aware text transformation with Azerbaijani character support, CSS custom property resolution for typography props, numeric validation, and a value clamping helper.
Installation
bun add @fvc/utilsPeer Dependencies
The package expects these dependencies to be available in the consuming application:
bun add reactImport
import { clamp, cssVarResolver, isNumeric, transformText } from '@fvc/utils';Quick Start
import { transformText, clamp, cssVarResolver, isNumeric } from '@fvc/utils';
transformText('salam', 'uppercase', 'az'); // 'SALAM'
clamp({ value: 150, min: 0, max: 100 }); // 100
cssVarResolver(16); // '16px'
isNumeric('43'); // trueAPI
transformText
Transforms a string with locale-aware casing. Has built-in character mappings for Azerbaijani (az) to correctly handle i ↔ İ and ı ↔ I conversions.
transformText(text: string, transformType: TextTransform, locale?: string): string| Parameter | Type | Default | Description |
| --------------- | --------------- | ------- | --------------------------------------------------------- |
| text | string | — | The input string to transform. |
| transformType | TextTransform | — | 'uppercase', 'lowercase', 'capitalize', 'integer' |
| locale | string | 'az' | BCP 47 locale tag used for case mapping. |
transformText('istanbul', 'uppercase', 'az'); // 'İSTANBUL'
transformText('İstanbul', 'lowercase', 'az'); // 'istanbul'
transformText('hello world', 'capitalize'); // 'Hello World'
transformText('3.14', 'integer'); // '3'clamp
Clamps a numeric value between a minimum and maximum.
clamp({ value: number, min: number, max: number }): numberclamp({ value: -5, min: 0, max: 100 }); // 0
clamp({ value: 50, min: 0, max: 100 }); // 50
clamp({ value: 200, min: 0, max: 100 }); // 100cssVarResolver
Converts a size or weight value to a CSS-compatible string. Numbers are suffixed with px; strings are returned as-is.
cssVarResolver(value?: string | number): string | undefinedcssVarResolver(16); // '16px'
cssVarResolver('1.5rem'); // '1.5rem'
cssVarResolver(undefined); // undefinedisNumeric
Returns true when the value consists entirely of digit characters (0–9).
isNumeric(value?: string | number): booleanisNumeric('100'); // true
isNumeric('10.5'); // false — decimal point is not a digit
isNumeric(''); // falseTypeScript
The package ships with type definitions. No @types/ install needed.
Development
bun run lint
bun run type-check
bun run test
bun run build