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: lib/node_modules/@stdlib/slice/seq2slice/README.md
+36-27
Original file line number
Diff line number
Diff line change
@@ -42,12 +42,12 @@ var seq2slice = require( '@stdlib/slice/seq2slice' );
42
42
43
43
<aname="main"></a>
44
44
45
-
#### seq2slice( str, len )
45
+
#### seq2slice( str, len, strict )
46
46
47
47
Converts a subsequence string to a [`Slice`][@stdlib/slice/ctor] object, where `len` specifies the maximum number of elements allowed in the slice.
48
48
49
49
```javascript
50
-
var s =seq2slice( ':5', 10 );
50
+
var s =seq2slice( ':5', 10, false );
51
51
// returns <Slice>
52
52
53
53
var v =s.start;
@@ -77,7 +77,7 @@ where
77
77
- The `end` keyword resolves to the provided length `len`. Thus, `:-1` is equivalent to `:end-1`, `:-2` is equivalent to `:end-2`, and so on and so forth. The exception is when performing a division operation when the `increment` is less than zero; in which case, `end` is equal to `len-1` in order to preserve user expectations when `end/d` equals a whole number and slicing from right-to-left. The result from a division operation is **rounded down** to the nearest integer value.
78
78
79
79
```javascript
80
-
var s =seq2slice( 'end:2:-1', 10 );
80
+
var s =seq2slice( 'end:2:-1', 10, false );
81
81
// returns <Slice>
82
82
83
83
var v =s.start;
@@ -89,7 +89,7 @@ v = s.stop;
89
89
v =s.step;
90
90
// returns -1
91
91
92
-
s =seq2slice( 'end-2:2:-1', 10 );
92
+
s =seq2slice( 'end-2:2:-1', 10, false );
93
93
// returns <Slice>
94
94
95
95
v =s.start;
@@ -101,7 +101,7 @@ v = s.stop;
101
101
v =s.step;
102
102
// returns -1
103
103
104
-
s =seq2slice( 'end/2:2:-1', 10 );
104
+
s =seq2slice( 'end/2:2:-1', 10, false );
105
105
// returns <Slice>
106
106
107
107
v =s.start;
@@ -114,6 +114,15 @@ v = s.step;
114
114
// returns -1
115
115
```
116
116
117
+
When `strict` is `true`, the function throws an error if a subsequence string resolves to a slice exceeding index bounds.
118
+
119
+
<!-- run throws: true -->
120
+
121
+
```javascript
122
+
var s =seq2slice( '10:20', 10, true );
123
+
// throws <RangeError>
124
+
```
125
+
117
126
</section>
118
127
119
128
<!-- /.usage -->
@@ -125,8 +134,8 @@ v = s.step;
125
134
## Notes
126
135
127
136
- When `len` is zero, the function always returns a Slice object equivalent to `0:0:<increment>`.
128
-
-The resolved slice start is clamped to the slice index bounds (i.e., `[0, len)`).
129
-
-The resolved slice end is upper bound clamped to `len` (i.e., one greater than the last possible index).
137
+
-When `strict` is `false`, the resolved slice start is clamped to the slice index bounds (i.e., `[0, len)`).
138
+
-When `strict` is `false`, the resolved slice end is upper bound clamped to `len` (i.e., one greater than the last possible index).
130
139
- When the increment is negative, the resolved slice end value may be `null`, thus indicating that a non-empty slice should include the first index.
131
140
- The function ensures that results satisfy the convention that `:n` combined with `n:` is equivalent to `:` (i.e., selecting all elements). This convention matches Python slice semantics, but diverges from the MATLAB convention where `:n` and `n:` overlap by one element.
132
141
- Unlike MATLAB, but like Python, the subsequence string is upper-bound exclusive. For example, in Python, `0:2` corresponds to the sequence `{0,1}`. In MATLAB, `1:3` corresponds to `{1,2,3}`.
@@ -146,83 +155,83 @@ v = s.step;
146
155
```javascript
147
156
var seq2slice =require( '@stdlib/slice/seq2slice' );
Copy file name to clipboardExpand all lines: lib/node_modules/@stdlib/slice/seq2slice/docs/types/index.d.ts
+9-6
Original file line number
Diff line number
Diff line change
@@ -43,9 +43,9 @@ import { Slice } from '@stdlib/types/slice';
43
43
* - Both `start` and `stop` can use the `end` keyword (e.g., `end-2::2`, `end-3:`, etc), which supports basic subtraction and division.
44
44
* - The `end` keyword resolves to the provided length `len`. Thus, `:-1` is equivalent to `:end-1`, `:-2` is equivalent to `:end-2`, and so on and so forth. The exception is when performing a division operation when the `increment` is less than zero; in which case, `end` is equal to `len-1` in order to preserve user expectations when `end/d` equals a whole number and slicing from right-to-left. The result from a division operation is **rounded down** to the nearest integer value.
45
45
*
46
-
* - The resolved slice start is clamped to the slice index bounds (i.e., `[0, len)`).
46
+
* - When `strict` is `false`, the resolved slice start is clamped to the slice index bounds (i.e., `[0, len)`).
47
47
*
48
-
* - The resolved slice end is upper bound clamped to `len` (i.e., one greater than the last possible index).
48
+
* - When `strict` is `false`, the resolved slice end is upper bound clamped to `len` (i.e., one greater than the last possible index).
49
49
*
50
50
* - When the increment is negative, the resolved slice end value may be `null`, thus indicating that a non-empty slice should include the first index.
51
51
*
@@ -55,12 +55,15 @@ import { Slice } from '@stdlib/types/slice';
55
55
*
56
56
* @param str - input string
57
57
* @param len - maximum number of elements allowed in the slice
0 commit comments