Utilities

Historically, rot.js was adding several new methods to JavaScript primordial objects: Array, String, Number, Date, Object and Function. This behavior is now frowned upon, so some of the provided functionality is now moved to the dedicated ROT.Util namespace.

String

A more verbose explanation about how ROT.Util.format works is available on a dedicated string formatting page.

SHOW( ROT.Util.capitalize("hello world") );

Number

The built-in modulus operator (%) yields negative results for negative arguments. Number.prototype.mod is guaranteed to return a positive value.

SHOW( ( 15) % 7, (-15) % 7, ROT.Util.mod( 15, 7), ROT.Util.mod(-15, 7) );

A numeric value often needs to be clamped into a useful range:

SHOW( ROT.Util.clamp( 15), // default range 0..1 ROT.Util.clamp( 15, 0, 255), // custom range ROT.Util.clamp(-15, 0, 255) );