You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+57-1Lines changed: 57 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,7 +4,7 @@ Parses and compiles CSS nth-checks to highly optimized functions.
4
4
5
5
### About
6
6
7
-
This module can be used to parse & compile nth-checks, as they are found in CSS 3's `nth-child()` and `nth-last-of-type()`.
7
+
This module can be used to parse & compile nth-checks, as they are found in CSS 3's `nth-child()` and `nth-last-of-type()`. It can be used to check if a given index matches a given nth-rule, or to generate a sequence of indices matching a given nth-rule.
8
8
9
9
`nth-check` focusses on speed, providing optimized functions for different kinds of nth-child formulas, while still following the [spec](http://www.w3.org/TR/css3-selectors/#nth-child-pseudo).
10
10
@@ -64,6 +64,62 @@ check(5); // `false`
64
64
check(6); // `true`
65
65
```
66
66
67
+
##### `generate([a, b])`
68
+
69
+
Returns a function that produces a monotonously increasing sequence of indices.
70
+
71
+
If the sequence has an end, the returned function will return `null` after the last index in the sequence.
72
+
73
+
**Example:** An always increasing sequence
74
+
75
+
```js
76
+
constgen=nthCheck.generate([2, 3]);
77
+
78
+
gen(); // `1`
79
+
gen(); // `3`
80
+
gen(); // `5`
81
+
gen(); // `8`
82
+
gen(); // `11`
83
+
```
84
+
85
+
**Example:** With an end value
86
+
87
+
```js
88
+
constgen=nthCheck.generate([-2, 5]);
89
+
90
+
gen(); // 0
91
+
gen(); // 2
92
+
gen(); // 4
93
+
gen(); // null
94
+
```
95
+
96
+
##### `sequence(formula)`
97
+
98
+
Parses and compiles a formula to a generator that produces a sequence of indices. Combination of `parse` and `generate`.
0 commit comments