Skip to content

Conformance Examples 0.1.0 — Transforms: transform-size

size-list

Returns the number of elements in a list.

Template

{{ xs | size }}

Context

{
    "xs": [
        1,
        2,
        3,
        4
    ]
}

Output

4

size-empty-list

The size of an empty list is zero.

Template

{{ xs | size }}

Context

{
    "xs": []
}

Output

0

size-string

Liquid-compatible: the character count of a string.

Template

{{ s | size }}

Context

{
    "s": "hello"
}

Output

5

size-struct-is-null

A struct input is neither list nor string, so the result is null.

Template

{{ o | size }}

Context

{
    "o": {
        "a": 1
    }
}

Output

null

size-number-is-null

A non-string primitive (number) is neither list nor string, so the result is null.

Template

{{ n | size }}

Context

{
    "n": 5
}

Output

null

size-astral-string-counts-code-points

A surrogate-pair (astral) character counts as one code point, not two UTF-16 units.

Template

{{ s | size }}

Context

{
    "s": "a😀b"
}

Output

3

size-lone-surrogate-counts-as-one

An unpaired (lone) surrogate counts as a single code-point-sized unit, not zero and not an error.

Template

{{ s | size }}

Context

{
    "s": "a?b"
}

Output

3

Source fixture: transforms/transform-size.json