Registry / developer-tools / lua-format

lua-format

JSON →
library1.6.1-bjsnpmunverified

Lua beautifier and minifier written in JavaScript, supporting Lua 5.1-5.4, FiveM hashed strings, and partial Luau. Current version is 1.6.1-b, with sporadic releases. Key differentiators: supports variable renaming, math solving, and custom indentation. Unlike other Lua formatters that require Lua runtime, this runs entirely in Node.js, making it suitable for build pipelines and online tools.

npm install lua-format
INSTALL
IMPORT
SIG · LUA-FORMAT
L
lua-format
developer-toolsjavascriptv1.6.1-b
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Beautify
import { Beautify } from 'lua-format'
import luamin from 'lua-format'
Package uses named exports; default export is not available.
Minify
import { Minify } from 'lua-format'
const { Minify } = require('lua-format') // Also valid, but ESM import preferred
Both ESM and CJS are supported.
luamin
import * as luamin from 'lua-format'
const luamin = require('lua-format'); // CJS pattern is fine but not ESM
CJS require() works; ESM namespace import also works.

Demonstrates both beautify and minify operations with common configuration options.

import { Beautify, Minify } from 'lua-format'; const code = `local x = 10 + 20 print('hello')`; const beautified = Beautify(code, { RenameVariables: true, RenameGlobals: false, SolveMath: true, Indentation: ' ' }); const minified = Minify(code, { RenameVariables: false }); console.log('Beautified:', beautified); console.log('Minified:', minified);
Debug
Known issues
gotchaMinify may produce invalid Lua when RenameGlobals is enabled if code uses dynamic global access.
fix
Set RenameGlobals to false or ensure all globals are statically referenced.
affects: all
gotchaSolveMath may simplify expressions in ways that break expected type coercion (e.g., string concatenation vs arithmetic).
fix
Disable SolveMath if mathematical transformations are undesired.
affects: all
gotchaThe package has no TypeScript definitions; any TypeScript usage will require custom type declarations.
fix
Create a .d.ts file with 'declare module "lua-format" { export function Beautify(code: string, options?: any): string; export function Minify(code: string, options?: any): string; }'
affects: all
Errors
Common errors & fixes
Cannot find module 'lua-format'
Package not installed.
fix
npm install lua-format
TypeError: luamin.Beautify is not a function
Default import used incorrectly.
fix
Use named import: import { Beautify } from 'lua-format'
Upgrade
Version history
1.6.1-blatest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
46 hits · last 30 days
node
42
Bingbot
1
Resources
lua-format — npm install lua-format · libregistry