Skip to content

Latest commit

 

History

History
404 lines (296 loc) · 9.59 KB

ref.md

File metadata and controls

404 lines (296 loc) · 9.59 KB

Function Reference


at

   Returns the value at the specified position in a list.

Syntax

at(list, index)

Parameters

list
Required. The input list.
index
Required. A one-base index of the element to return. If index is not a unitless numeric value it's considered to specify the key in a key-value list structure.

Returns

   The value at the specified position in the list.

Example

@list: apple, banana, cherry;

at(@list, 2);       // banana
at(foo bar baz, 3); // baz
at(alone, 1);       // alone

@key-value-list:
     Alice 10px,
     Bob   20px,
     Chuck 30px and his hat,
     Dave  40px;

at(@key-value-list, Bob);   // 20px
at(@key-value-list, Chuck); // 30px and his hat

cat

   Concatenates two or more lists.

Syntax

cat(value1, value2, ... valueN)

Parameters

value1, ..., valueN
Optional. The lists or single values to concatenate. If value argument is a list, its contents are appended to the resulting list. If the argument is anything other than a list, it is appended as a single element.

Returns

   List.

Remarks

The type of the returning list (i.e. if it's comma or whitespace separated) is determined by the type of the first list among arguments. If no lists passed in, the result is comma delimited.

Example

@a: 1, 2;
@b: 3, 4;

cat(1, 2, 3); // 1, 2, 3
cat(1  2, 3); // 1 2 3
cat(@a, @b);  // 1, 2, 3, 4
cat(@a, 3 4); // 1, 2, 3, 4
cat(1 2, @b); // 1 2 3 4

@c: @a @b;
@d: cat(@a, @b);

length(@c); // 2
// but:
length(@d); // 4

flatten

   Returns a one-dimensional list containing all elements of an input list.

Syntax

flatten(list, delimiter)

Parameters

list
Required. The input list.
delimiter
Optional. Specifies a delimiter to be used for the resulting list.
This parameter can be one of: comma, space, ",", " ". If omitted, the resulting list is comma-delimited.

Returns

   The flattened list.

Example

@list: a b, c d;        // two-dimensional list

length(@list);          // 2
length(flatten(@list)); // 4
flatten(@list);         // a, b, c, d
flatten(@list, space);  // a b c d

join

   Joins all elements of a list into a string.

Syntax

join(list, delimiter)

Parameters

list
Required. The input list.
delimiter
Optional. A string to be used to separate list items. If omitted, the elements are delimited with , .

Returns

   String.

Example

@list: 1, 2, 3, 4;

join(@list);           // 1, 2, 3, 4
join(@list, -);        // 1-2-3-4
join(foo bar baz);     // foo, bar, baz
join(foo bar baz, ""); // foobarbaz

join((3 * 11px) of rgb(255, 0, 0), ' '); // 33px of #ff0000

l

   Creates a comma or space separated list.

Syntax

l(value1, value2, ... valueN)

Parameters

value1, ..., valueN
Required. The list value(s).

Returns

   List.

Remarks

  • The purpose of this function is to construct a comma-separated list in place so that it can be passed as a single function or mixing argument
  • As well as allowing both comma or space separated list "literals" to be used directly in complex statements.
  • Function identifiers are not case-sensitive in Less, so L identifier is also valid to use.

Example

at(a  b  c, 2);    // b
at(a, b, c, 2);    // at(a, b, c, 2)
at(l(a, b, c), 2); // b

reverse

   Returns list in reversed order.

Syntax

reverse(list)

Parameters

list
Required. The input list.

Returns

   List in reversed order: from last to first.

Example

@list: one, two, three, four;

reverse(@list);     // four, three, two, one


@list: black white, one two;

reverse(@list);     // one two, black white

slice

   Returns selected portion of a list.

Syntax

slice(list, start, end)

Parameters

list
Required. The input list.
start
Optional. A one-base index to start slicing at. Negative or zero start specifies an offset from the end of the list (with -1 pointing to the last element). If omitted, slice starts at the beginning of the list.
end
Optional. A one-base index to stop slicing at (up to but not including end). Negative or zero end specifies an offset from the end of the list (with -1 pointing to the last element). If omitted, slice continues to the end of the list.

Returns

   The selected portion of a list.

Example

@list: one, two, three, four;

slice(@list,  3);     // three, four
slice(@list,  2,  3); // two
slice(@list, -3);     // two, three, four
slice(@list,  3, -1); // three
slice(@list, -2,  0); // three, four

splice

   Replaces or removes selected portion of a list.

Syntax

splice(list, start, end, value)

Parameters

list
Required. The input list.
start
Optional. A one-base index to start removing elements at. Negative or zero start specifies an offset from the end of the list (with -1 pointing to the last element).
end
Optional. A one-base index to stop removing elements at (up to but not including end). Negative or zero end specifies an offset from the end of the list (with -1 pointing to the last element). If omitted, the start + 1 index is used.
value
Optional. A value to insert into the list in place of the removed elements.

Returns

   Modified list.

Example

@list: one, two, three, four;

splice(@list, 3);         // one, two, four
splice(@list, 2, 4);      // one, four
splice(@list, -3, -2);    // one, three, four
splice(@list, 3, 4, hat); // one, two, hat, four

transpose

Transposes rows and columns of a list.

Syntax

transpose(list)

Parameters

list
Required. The input list

Returns

   Transposed list.

Remarks

   This function assumes only 2-dimensional input lists. Any sub-dimension values pass unchanged.

Example

@list: Alice 1,
       Bob   2,
       Carol 3,
       Dave  4,
       Eve   5;

transpose(@list);        // Alice, Bob, Carol, Dave, Eve 1, 2, 3, 4, 5
at(transpose(@list), 1); // Alice, Bob, Carol, Dave, Eve
at(transpose(@list), 2); // 1, 2, 3, 4, 5

transpose(l(a, b, c) l(1, 2, 3)); // a 1, b 2, c 3

_inspect

   Return a string representation of a list with debug/log formatting.

Syntax

_inspect(list, prefix, postfix)

Parameters

list
Required. The input list.
prefix
Optional. A string to put before the list and all of its nesting lists (if any). If no prefix specified, [ is used.
postfix
Optional. A string to put after the list and all of its nesting lists (if any). If no postfix specified, ] is used.

Returns

   String.

Remarks

   This function is used for the plugin self-tests.

Example

@a: 1 2 3, 4 5 6;

_inspect(@a);            // [[1 2 3], [4 5 6]]
_inspect(transpose(@a)); // [[1, 4] [2, 5] [3, 6]]
_inspect(@a 7);          // [[[1 2 3], [4 5 6]] 7]
_inspect(cat(@a, 7));    // [[1 2 3], [4 5 6], 7]

@b1:     1;
@b2: @b1 2;
@b3: @b2 3;
@b:  @b3 4;

_inspect(@b);            // [[[1 2] 3] 4]
_inspect(flatten(@b));   // [1, 2, 3, 4]