CORE
Values and Validation
Runtime validation and type conversion for OOXML specification value types
OOXML defines strict value types for measurements, colors, and other data. @office-open/core provides validation functions that normalize and validate these values.
Measurement Validators
TWIP Measurements
TWIP (twentieth of a point) is the standard unit in WordprocessingML.
import { twipsMeasureValue, signedTwipsMeasureValue } from "@office-open/core";
twipsMeasureValue(1440); // "1440" (1 inch)
signedTwipsMeasureValue(-720); // "-720"
Point Measurements
import { hpsMeasureValue, pointMeasureValue, eighthPointMeasureValue } from "@office-open/core";
hpsMeasureValue(24); // font size in half-points
pointMeasureValue(12); // 12 points
eighthPointMeasureValue(96); // 96 eighth-points = 12 points
Universal Measure
Accepts values with unit suffixes: mm, cm, in, pt, pc, pi.
import { universalMeasureValue, positiveUniversalMeasureValue } from "@office-open/core";
universalMeasureValue("25.4mm"); // "25.4mm"
universalMeasureValue("1in"); // "1in"
positiveUniversalMeasureValue("72pt"); // "72pt"
Numeric Validators
| Function | Input | Output |
|---|---|---|
decimalNumber(val) | number | Integer (floored) |
unsignedDecimalNumber(val) | number | Positive integer |
Hex Validators
| Function | Input | Description |
|---|---|---|
hexColorValue(val) | string | Validates hex color, supports "auto" |
hexBinary(val, length) | string, number | Hex binary with fixed length |
longHexNumber(val) | string | 4-byte hex (8 chars) |
shortHexNumber(val) | string | 2-byte hex (4 chars) |
uCharHexNumber(val) | string | 1-byte hex (2 chars) |
import { hexColorValue, shortHexNumber } from "@office-open/core";
hexColorValue("FF0000"); // "#FF0000"
hexColorValue("auto"); // "auto"
shortHexNumber("0013"); // "0013"
Percentage
import { percentageValue, measurementOrPercentValue } from "@office-open/core";
percentageValue("50%"); // "50%"
measurementOrPercentValue("25.4mm"); // "25.4mm"
measurementOrPercentValue("100%"); // "100%"
Date and Time
import { dateTimeValue } from "@office-open/core";
dateTimeValue(new Date("2025-01-01")); // "2025-01-01T00:00:00.000Z"
Theme Constants
ThemeColor
Predefined theme color indices used in color references:
import { ThemeColor } from "@office-open/core";
// ThemeColor.DARK1 — dark primary
// ThemeColor.LIGHT1 — light primary
// ThemeColor.DARK2 — dark secondary
// ThemeColor.LIGHT2 — light secondary
// ThemeColor.ACCENT1-6 — accent colors
// ThemeColor.HYPERLINK — hyperlink color
// ThemeColor.FOLLOWED_HYPERLINK
ThemeFont
Predefined theme font indices:
import { ThemeFont } from "@office-open/core";
// ThemeFont.MAJOR_EAST_ASIA
// ThemeFont.MAJOR_ASCII
// ThemeFont.MAJOR_HIGH_ANSI
// ThemeFont.MINOR_EAST_ASIA
// ThemeFont.MINOR_ASCII
// ThemeFont.MINOR_HIGH_ANSI