rbxts-transformer-wd-globals
v0.0.7
Published
A TypeScript transformer for Roblox TS that adds global definitions.
Readme
rbxts-transformer-wd-globals
Automatically import polyfill utilities when using Object and String methods in roblox-ts, reducing boilerplate by managing imports for you.
Overview
This transformer automatically detects usage of Object and String polyfill methods and adds the necessary imports from @rbxts/luau-polyfill at compile time.
Features
- ✨ Automatic import management for polyfill utilities
- 🔍 Smart detection of existing imports (prevents duplicates)
- ⚡ Zero runtime overhead (transforms at compile-time)
- 🎯 Supports Object and String polyfill methods
- 📦 Combined imports when multiple types are used
Installation
npm install rbxts-transformer-wd-globalsConfigure in your tsconfig.json
Add the transformer to your tsconfig.json:
{
"compilerOptions": {
...
"plugins": [
{
"transform": "rbxts-transformer-wd-globals",
}
]
},
"include": [..., "node_modules/rbxts-transformer-wd-globals"]
}Usage
Basic Usage
The transformer automatically detects when you use Object or String methods and adds the necessary imports:
// Instead of manually importing:
import { Object } from "@rbxts/luau-polyfill";
import { String } from "@rbxts/luau-polyfill";
const keys = Object.keys({ a: 1, b: 2, c: 3 });
const trimmed = String.trim(" hello ");
// You can just write:
const keys = Object.keys({ a: 1, b: 2, c: 3 });
const trimmed = String.trim(" hello ");
// The transformer automatically adds the imports for you!Examples
Single Type Usage
Input (TypeScript):
const keys = Object.keys({ name: "John", age: 30 });
console.log(keys);Output (After transformation):
import { Object } from "@rbxts/luau-polyfill";
const keys = Object.keys({ name: "John", age: 30 });
console.log(keys);Multiple Types Usage
Input (TypeScript):
const obj = { name: "John", age: 30 };
const keys = Object.keys(obj);
const trimmed = String.trim(" hello world ");Output (After transformation):
import { Object, String } from "@rbxts/luau-polyfill";
const obj = { name: "John", age: 30 };
const keys = Object.keys(obj);
const trimmed = String.trim(" hello world ");Smart Import Detection
Input (TypeScript):
import { Object } from "my-custom-library";
const keys = Object.keys(obj); // Uses existing import
const trimmed = String.trim(" test "); // Needs new importOutput (After transformation):
import { String } from "@rbxts/luau-polyfill";
import { Object } from "my-custom-library";
const keys = Object.keys(obj); // Uses existing import
const trimmed = String.trim(" test "); // Uses new importLicense
MIT
