DOM and styles API
addCssUnit Units
Adds CSS units to numbers or numeric strings.
Signature
ts
export function addCssUnit(value?: string | number | null, unit = "px"): string;Example
ts
import { addCssUnit } from "@fast-china/utils";
const result = addCssUnit(12);Input
| Input | Type | Required / default | Description |
|---|---|---|---|
value | string | number | null | Optional | Number, numeric string, or CSS value with units; nullish values return an empty string. |
unit | unknown | Optional; defaults to "px" | Unit for nonzero numbers; defaults to px. |
Returns
| Value | Type | Description |
|---|---|---|
result | string | Zero always becomes "0"; nonnumeric strings remain unchanged. |
serializeStyle Styles
Serializes style strings, objects, or nested arrays into inline CSS.
Signature
ts
export function serializeStyle(styles: StyleInput): string;Example
ts
import { serializeStyle } from "@fast-china/utils";
const result = serializeStyle({ color: "red", width: 12 });Input
| Input | Type | Required / default | Description |
|---|---|---|---|
styles | StyleInput | Required | Possibly nested style input; later declarations override earlier ones through the CSS cascade. |
Returns
| Value | Type | Description |
|---|---|---|
result | string | Space-separated CSS declarations ending in semicolons. |
