Skip to content

Commit 324bd20

Browse files
committed
add function 'reverse'
1 parent 2758368 commit 324bd20

File tree

7 files changed

+64
-1
lines changed

7 files changed

+64
-1
lines changed

CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11

2+
# 1.1.2
3+
4+
2018-03-31
5+
- Add function 'reverse'
6+
27
# 1.1.1
38

49
2017-04-22

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ The plugin extends Less with the following functions:
2222
- [`flatten  `](docs/ref.md#flatten) - returns a one-dimensional list containing all elements of an input list.
2323
- [`join     `](docs/ref.md#join) - joins all elements of a list into a string.
2424
- [`l        `](docs/ref.md#l) - creates a comma or space separated list.
25+
- [`reverse  `](docs/ref.md#reverse) - returns list in reversed order.
2526
- [`slice    `](docs/ref.md#slice) - returns selected portion of a list.
2627
- [`splice   `](docs/ref.md#splice) - replaces or removes selected portion of a list and returns the modified copy.
2728
- [`transpose`](docs/ref.md#transpose) - transposes rows and columns of a list.

docs/ref.md

+32
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,38 @@ at(l(a, b, c), 2); // b
202202

203203
---------------------------------------------------------------
204204

205+
### `reverse`
206+
207+
   Returns list in reversed order.
208+
209+
**Syntax**
210+
```
211+
reverse(list)
212+
```
213+
214+
**Parameters** <dl></dl>
215+
`list` <dl><dd>
216+
Required. The input list.
217+
</dd></dl>
218+
219+
**Returns**
220+
221+
   List in reversed order: from last to first.
222+
223+
**Example**
224+
```less
225+
@list: one, two, three, four;
226+
227+
reverse(@list); // four, three, two, one
228+
229+
230+
@list: black white, one two;
231+
232+
reverse(@list); // one two, black white
233+
```
234+
235+
---------------------------------------------------------------
236+
205237
### `slice`
206238

207239
   Returns selected portion of a list.

lib/main.js

+10
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,16 @@ module.exports = function(less) {
154154

155155
// ....................................................
156156

157+
reverse: function(list) {
158+
if (isArray(list.value)) {
159+
list.value = list.value.reverse();
160+
}
161+
162+
return list;
163+
},
164+
165+
// ....................................................
166+
157167
_inspect: function(list, prefix, postfix) {
158168
prefix = prefix ? prefix.value : "[";
159169
postfix = postfix ? postfix.value : "]";

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "less-plugin-lists",
3-
"version": "1.1.1",
3+
"version": "1.1.2",
44
"description": "list/array manipulation for Less",
55
"homepage": "https://github.com/seven-phases-max/less-plugin-lists",
66
"author": "Max Mikhailov",

test/css/reverse.css

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
reverse {
2+
00: tomato potato, banana apple;
3+
01: black, white;
4+
02: black white;
5+
}

test/less/reverse.less

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
2+
@0: banana apple, tomato potato;
3+
@1: white, black;
4+
@2: white black;
5+
6+
reverse {
7+
00: reverse(@0);
8+
01: reverse(@1);
9+
02: reverse(@2);
10+
}

0 commit comments

Comments
 (0)