Easy CSS Transform Builder

0.1.0 · active · verified Sun Apr 19

easy-css-transform-builder is a JavaScript/TypeScript utility library designed to simplify the creation of complex CSS `transform` values. It enables developers to define various transform properties like `translateX`, `scale`, `rotate3d`, and `skewY` within a simple JavaScript object, which the library then serializes into a valid CSS `transform` string. The current version is 0.1.0, indicating it is in its initial release phase without an established release cadence, and it ships with TypeScript types for enhanced developer experience. Its key differentiator is its straightforward, fluent API for programmatically generating CSS transform strings, making it particularly useful for dynamic styling and animation integrations within JavaScript-driven UI frameworks, as illustrated by its usage examples.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart initializes the transform builder with default units and demonstrates how to apply multiple CSS transform properties from an object into a single CSS transform string.

import { createCSSTransformBuilder } from 'easy-css-transform-builder';

// Initialize the builder, optionally setting default units.
const builder = createCSSTransformBuilder({
  length: 'px', // Default for length values
  angle: 'deg'  // Default for angle values
});

// Define your transform properties as an object.
const transformProperties = {
  translateX: 30,
  scale: 2.8,
  rotate3d: [1, 0, 0, 60],
  skewY: '40rad' // Units can be explicitly provided as strings
};

// Generate the CSS transform string.
const cssTransformString = builder(transformProperties);

console.log(cssTransformString);
// Expected output: translateX(30px) scale(2.8) rotate3d(1, 0, 0, 60deg) skewY(40rad)

// Example of dynamic usage (e.g., in a React component's style prop)
const myElementStyle = {
  transform: builder({
    translateX: 100,
    rotate: '45deg'
  })
};
// In a real application, you'd apply myElementStyle to an element.
console.log('Dynamic style transform:', myElementStyle.transform);

view raw JSON →