» Language: Values
Values are the data that Sentinel policies operate on. You can create this
data yourself, for example by just typing the number
42, or you may access
this data from an external source to make policy decisions.
Values have a type, which determines what kind of operatins can be performed on the data. Example types are booleans (true and false), numbers, and strings (text).
This page documents all the available value types. You can also convert between types.
A boolean is a value that is either true or false.
A boolean value is created literally with
As a policy language, booleans are central to the behavior of Sentinel. Booleans are used as conditions in if statements, are the result of rules, and more. The ultimate result of a Sentinel policy is true or false.
An integer is a whole number.
An integer is a 64-bit value. This means it can represent numbers from -9,223,372,036,854,775,808 to 9,223,372,036,854,775,808.
Integers are created by typing them out literally with no
separators (such as a comma). An optional prefix can set a non-decimal base:
0 for octal, and
0x for hexadecimal. In hexadecimal literals, letters
A-F represent values 10 to 15.
Example integers are shown below:
42 0600 0xBadFace 170141183460469
Integers are used for math and numerical comparison.
A float is a number with a decimal point. It has an integer part, a decimal point, a fractional part, and optionally an exponent part. Example floats are shown below:
0. 72.40 072.40 // == 72.40 2.71828 1.e+0 6.67428e-11 1E6 .25 .12345E+5
Floats are IEEE-754 64-bit floating point numbers.
Strings are text values.
Strings are created by wrapping text in double quotes, such as
Within the quotes, any character may appear except newline and an unescaped
double quote. The text between the quotes is the value.
Because Sentinel policies must be UTF-8 encoded text, strings themselves are
UTF-8 encoded text. This means you can put any value UTF-8 character into
a string, such as
You can have a string with a literal double-quote by escaping it with
a backslash. For example:
"they said \"hello\"" turns into the value
they said "hello".
Backslash escapes can be used for much more than only escaping a double quote.
\n, a literal backslash is
\\, and many more. The full list
of available backslash escapes can be found
in the language specification.
`abc` // same as "abc" `\n \n` // same as "\\n\n\\n" "\n" "\"" // same as `"` "Hello, world!\n" "日本語" "\u65e5本\U00008a9e" "\xff\u00FF" "\uD800" // illegal: surrogate half "\U00110000" // illegal: invalid Unicode code point
Strings support indexing. Indexing a string will access that byte in the string as if the string were a byte array. This is an important distinction: it will not access the character at that position if you're using multi-byte characters.
Strings support slicing to efficiently create substrings.
» Type Conversion
The built-in functions
string convert a value to a value of
that type. Some examples are shown below followed by a list of exact rules
for type conversion.
int(42) // 42 int("42") // 42 int(42.8) // 42 float(1.2) // 1.2 float(1) // 1.0 float("4.2") // 4.2 string("foo") // "foo" string(88) // "88" string(0xF) // "15"
- Integer values are unchanged
- String values are converted according to the syntax of integer literals
- Float values are rounded down to their nearest integer value
- Float values are unchanged
- Integer values are converted to the nearest equivalent floating point value
- String values are converted according to the syntax of float literals
- String values are unchanged
- Integer values are converted to the base 10 string representation
- Float values are converted to a string formatted
xxx.xxxwith a precision of 6. This is equivalent to
%ffor C's sprintf.
For any other unspecified type, the result is the