JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 1138
  • Score
    100M100P100Q101165F
  • License MIT

Package Exports

  • @rbxts-js/pretty-format
  • @rbxts-js/pretty-format/src/init.lua

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@rbxts-js/pretty-format) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

pretty-format

Upstream: https://github.com/facebook/jest/tree/v27.4.7/packages/pretty-format

Stringify any Luau value

  • Supports Luau builtins and Roblox Instances.
  • Can be extended with user defined plugins.

Roblox Instance Formatting Options

The following options control how Roblox Instance objects are serialized:

printInstanceDefaults [boolean]

Default: true

When true, prints all readable properties of an Instance. When false, only prints properties that differ from their default values.

local prettyFormat = require(Packages.PrettyFormat).default
local RobloxInstance = require(Packages.PrettyFormat).plugins.RobloxInstance

local label = Instance.new("TextLabel")
label.Text = "Hello"

-- With printInstanceDefaults = false, only non-default properties are shown
print(prettyFormat(label, {
    plugins = { RobloxInstance },
    printInstanceDefaults = false,
}))
-- Output: TextLabel { "Text": "Hello" }

printInstanceTags [boolean]

Default: false

When true, prints tags applied to an Instance (via CollectionService:AddTag() or React.Tag). Tags are sorted alphabetically and appear before properties.

local label = Instance.new("TextLabel")
label.Name = "MyLabel"
label:AddTag("Styled")
label:AddTag("Animated")

print(prettyFormat(label, {
    plugins = { RobloxInstance },
    printInstanceDefaults = false,
    printInstanceTags = true,
}))
-- Output:
-- TextLabel {
--   "Tags": Table {
--     "Animated",
--     "Styled",
--   },
--   "Name": "MyLabel",
-- }

useStyledProperties [boolean]

Default: false

When true, reads Instance properties using the GetStyled API, returning computed values after StyleSheet rules are applied. When false, reads properties directly from the Instance.

This is useful when testing styled components to verify that style rules are correctly applied.

-- With useStyledProperties = true, the styled value (from StyleSheet) is shown
-- With useStyledProperties = false, the base property value is shown

Note on Pseudoinstances: Styling infrastructure instances (StyleSheet, StyleRule, StyleLink, StyleDerive) currently appear in serialized output when they are children of a formatted Instance. This behavior is documented and tested in the test suite.


✏️ Notes

  • ⚠️ Our prettyFormat doesn't distinguish between Tables, Arrays, Objects, etc. and prints out all Lua table-like types as Table.
    • For example, an empty array is printed as Table {} and an array with values is printed as Table {1, 2, 3,}.
    • printComplexValue is reduced to just arrays and tables.
  • ❌ Color formatting isn't supported so all related methods are omitted.
  • 🔨 Built-in plugins for prettyFormat are not implemented yet.
  • prettyFormat formats Roblox DateTime objects as a replacement for JS Date.
  • Formats using the Lua native string representations of primitives like nil, nan and inf over the JS null, NaN and Infinity. The tests are modified accordingly.
  • Formatting for any Javascript specific types in are omitted, Symbol, named Function, Error, Date, BigInt, etc.
  • getConfig is rewritten to avoid ternary operators. loop is rewritten with a for loop instead of an iterator.next().
  • Collections.lua deviates from upstream substantially since Lua only has tables. We only have two functions: printTableEntries for formatting key, value pairs and printListItems for formatting arrays.