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/from-to.js
+34-17Lines changed: 34 additions & 17 deletions
Original file line number
Diff line number
Diff line change
@@ -1,20 +1,36 @@
1
1
importarrayBackfrom'array-back'
2
2
3
-
/**
4
-
* Similar to find-replace with two exceptions:
5
-
* - fromTo finds multiple items, find-replace finds single items
6
-
* - fromTo offers the option to remove, find-replace offers option to remove and/or replace.
7
-
*
8
-
* Scenarios you can perform
9
-
* - Find one or more items and return (all return values are arrays)
10
-
* - Find one or more items, return them, remove them from the input array
11
-
*
12
-
* arr {string[]} - Input array. Only mutated if `options.remove` is set.
13
-
* [options.remove] {boolean} - Remove from source array
14
-
* [options.from] {string[]|function[]} - String literal or a [findIndex](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/findIndex) callback function.
15
-
* [options.to] {string[]|function[]} - A "Stop Here" function. Set one or more strings as the terminating arg. Or, from the function `fn(arg, index, argv, valueIndex)`, return true for the first arg that is out of range. Set `inclusive` to also include it. To will always search to the end of the input array.
16
-
* @returns string[]
17
-
*/
3
+
/*☭
4
+
## from-to
5
+
6
+
Similar to find-replace with two exceptions:
7
+
8
+
- fromTo finds multiple items, find-replace finds single items
9
+
- fromTo offers the option to remove, find-replace offers option to remove and/or replace.
10
+
11
+
Scenarios you can perform
12
+
13
+
- Find one or more items and return (all return values are arrays)
14
+
- Find one or more items, return them, remove them from the input array
15
+
16
+
- **Type:** `function`
17
+
- **Returns:** `string[]`
18
+
19
+
arr {string[]} - Input array. Only mutated if `options.remove` is set.
20
+
[options.remove] {boolean} - Remove from source array
21
+
[options.from] {string[]|function[]} - String literal or a [findIndex](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/findIndex) callback function.
22
+
[options.to] {string[]|function[]} - A "Stop Here" function. Set one or more strings as the terminating arg. Or, from the function `fn(arg, index, argv, valueIndex)`, return true for the first arg that is out of range. Set `inclusive` to also include it. To will always search to the end of the input array.
23
+
24
+
¬
25
+
Param
26
+
Type
27
+
Description
28
+
¬
29
+
[options]
30
+
`object`
31
+
Description
32
+
¬
33
+
*/
18
34
19
35
functionfromTo(arr,options={}){
20
36
/* step 1: compute from and to index */
@@ -84,8 +100,8 @@ function convertToFunction (fn) {
84
100
/**
85
101
* Find the first value which matches the supplied `find` definition (one or more string or functions).
0 commit comments