<commit_before># Methods and Functions

Soy methods and functions are called from within Soy
[expressions](expressions.md).

The table below lists basic Soy functions and methods that are available by
default. For Soy functions related to bidirectional text, see
[Bidi Support](../dev/localization#bidi_functions). For information on writing
custom external functions, see
[Creating an External Function](../dev/externs.md).

[TOC]

## Basic Functions

### `checkNotNull(value)` {#checkNotNull}

Throws a runtime exception if the given value is `null` and returns the value
otherwise.

This function is integrated into the type system, so if `value` is typed as a
nullable value, the return value of `checkNotNull` will no longer be nullable.
This can be useful when passing values to templates that expect non nullable
values.

### `keys(legacyObjectMap)` {#keys}

The keys of a [legacy object map](types.md#legacy_object_map) as a list. There
is no guarantee on order.

### `mapToLegacyObjectMap(map)` {#mapToLegacyObjectMap}

Converts a [map](types.md#map) to an equivalent
[legacy_object_map](types.md#legacy_object_map).

Because legacy object maps do not support non-string keys, all of the keys are
coerced to strings in the returned legacy object map.

### `legacyObjectMapToMap(legacyObjectMap)` {#legacyObjectMapToMap}

Converts a [legacy object map](types.md#legacy_object_map) to an equivalent
[map](types.md#map).

### `range([start,] end[, step])` {#range}

Use this to create lists containing arithmetic progressions. It is most often
used in [indexed for loops](control-flow.md#for-indexed). If the `step` argument
is omitted, it defaults to 1. If the `start` argument is omitted, it defaults to
0. The full form returns a list of plain integers `[start, start + step, start +
2 * step, ...]`.

This function behaves identically to the Python `range` builtin function, or the
Closure `goog.array.range` function.

## Math Functions

### `round(number[, numDigitsAfterDecimalPoint])` {#round}

Rounds the given number to an integer.

If `numDigitsAfterDecimalPoint` is positive, round to that number of decimal
places; if `numDigitsAfterDecimalPoint` is negative, round to an integer with
that many 0s at the end.

BEST PRACTICE: Don't use this function to format numbers for display. Prefer
things like [`formatNum`](#formatNum) which are i18n friendly.

### `floor(number)` {#floor}

The floor of the number.

### `ceiling(number)` {#ceiling}

The ceiling of the number.

### `min(number, number)` {#min}

The min of the two numbers.

### `max(number, number)` {#max}

The max of the two numbers.

### `parseInt(str)` {#parseInt}

Parses the string argument as a signed base 10 integer. Returns `null` if the
string cannot be parsed.

### `parseFloat(str)` {#parseFloat}

Parses the string argument as a floating point number. Returns `null` if the
string cannot be parsed.

### `randomInt(rangeArg)` {#randomInt}

A random integer in the range `[0, rangeArg - 1]` (where `rangeArg` must be a
positive integer).

### `sqrt(number)` {#sqrt}
<commit_msg>Update documentation to match signature and implementation changes  of parseInt<commit_after># Methods and Functions

Soy methods and functions are called from within Soy
[expressions](expressions.md).

The table below lists basic Soy functions and methods that are available by
default. For Soy functions related to bidirectional text, see
[Bidi Support](../dev/localization#bidi_functions). For information on writing
custom external functions, see
[Creating an External Function](../dev/externs.md).

[TOC]

## Basic Functions

### `checkNotNull(value)` {#checkNotNull}

Throws a runtime exception if the given value is `null` and returns the value
otherwise.

This function is integrated into the type system, so if `value` is typed as a
nullable value, the return value of `checkNotNull` will no longer be nullable.
This can be useful when passing values to templates that expect non nullable
values.

### `keys(legacyObjectMap)` {#keys}

The keys of a [legacy object map](types.md#legacy_object_map) as a list. There
is no guarantee on order.

### `mapToLegacyObjectMap(map)` {#mapToLegacyObjectMap}

Converts a [map](types.md#map) to an equivalent
[legacy_object_map](types.md#legacy_object_map).

Because legacy object maps do not support non-string keys, all of the keys are
coerced to strings in the returned legacy object map.

### `legacyObjectMapToMap(legacyObjectMap)` {#legacyObjectMapToMap}

Converts a [legacy object map](types.md#legacy_object_map) to an equivalent
[map](types.md#map).

### `range([start,] end[, step])` {#range}

Use this to create lists containing arithmetic progressions. It is most often
used in [indexed for loops](control-flow.md#for-indexed). If the `step` argument
is omitted, it defaults to 1. If the `start` argument is omitted, it defaults to
0. The full form returns a list of plain integers `[start, start + step, start +
2 * step, ...]`.

This function behaves identically to the Python `range` builtin function, or the
Closure `goog.array.range` function.

## Math Functions

### `round(number[, numDigitsAfterDecimalPoint])` {#round}

Rounds the given number to an integer.

If `numDigitsAfterDecimalPoint` is positive, round to that number of decimal
places; if `numDigitsAfterDecimalPoint` is negative, round to an integer with
that many 0s at the end.

BEST PRACTICE: Don't use this function to format numbers for display. Prefer
things like [`formatNum`](#formatNum) which are i18n friendly.

### `floor(number)` {#floor}

The floor of the number.

### `ceiling(number)` {#ceiling}

The ceiling of the number.

### `min(number, number)` {#min}

The min of the two numbers.

### `max(number, number)` {#max}

The max of the two numbers.

### `parseInt(str[, base])` {#parseInt}

Parses the string argument as a signed base 10 integer of the specified base.
Returns `null` if the string cannot be parsed. Base defaults to 10 and must be
between 2 and 36, if specified.

### `parseFloat(str)` {#parseFloat}

Parses the string argument as a floating point number. Returns `null` if the
string cannot be parsed.

### `randomInt(rangeArg)` {#randomInt}

A random integer in the range `[0, rangeArg - 1]` (where `rangeArg` must be a
positive integer).

### `sqrt(number)` {#sqrt}

{'fraction_non_alphanumeric': 0.10273102572245157, 'fraction_numerical': 0.003969514131470308, 'mean_word_length': 5.056730769230769, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6421551', 'n_tokens_mistral': 1929, 'n_tokens_neox': 1837, 'n_words': 813}