Metadata utility and utility macros for Flamework
npm install @rbxts/flamework-meta-utilsts
const enum Abc {
A,
B,
C
}
const a = enumKey();
`
Compiles to
`lua
local a = "A";
`
$3
Converts the type into a runtime value.
`ts
const obj = identity<{ foo: "bar" }>();
`
Compiles to
`lua
local obj = identity({ foo = "bar" }); -- which returns the passed param
`
$3
Deunifies a union type T into an array of all constituents
`ts
const constituents = deunify<"a" | "b" | "c">();
`
Compiles to
`lua
local constituents = deunify({"a", "b", "c"}); -- which returns the passed param
`
$3
Repeats the string S N times.
`ts
const line = repeatString<"-", 30>();
`
Compiles to
`lua
local line = "------------------------------";
`
$3
Generates a type guard (if one is not specified) and returns all children of the given instance that pass the guard.
`ts
interface CharacterModel extends Model {
Humanoid: Humanoid;
HumanoidRootPart: Part;
}
const characters = getChildrenOfType(Workspace.Characters);
`
$3
Generates a type guard (if one is not specified) and returns all descendants of the given instance that pass the guard.
`ts
const assetsToPreload = getDescendantsOfType(ReplicatedStorage);
`
$3
Resolves the instance at the given path using Rojo
`ts
const module = getInstanceAtPath("src/client/controllers/mouse.ts");
`
$3
Generates a type guard (if one is not specified) and if the guard passes, returns the casted value. Otherwise returns undefined.
`ts
const value = safeCast(someUnknownValue);
if (value !== undefined)
print("doubled value:", value * 2);
`
`ts
interface CharacterModel extends Model {
Humanoid: Humanoid;
HumanoidRootPart: Part;
}
const character = safeCast(Players.LocalPlayer.Character);
if (character !== undefined)
print("character root:", character.HumanoidRootPart);
``