Skip to content

Commit 82ad647

Browse files
committed
tidy comments
1 parent 13aa1c9 commit 82ad647

File tree

4 files changed

+3
-24
lines changed

4 files changed

+3
-24
lines changed

dist/index.cjs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,12 @@ var arrayBack = require('array-back');
1212
* - Find one or more items, return them, remove them from the input array
1313
*
1414
* arr {string[]} - Input array. Only mutated if `options.remove` is set.
15-
* [options.rtol] {boolean} - Enable right-to-left scans. Either that or pass in a custom iterator. TODO.
1615
* [options.remove] {boolean} - Remove from source array
1716
* [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.
1817
* [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.
1918
* @returns string[]
2019
*/
2120

22-
/* TODO: rename to extractFromTo? Rename `options.remove` to `extract`. */
2321
function fromTo (arr, options = {}) {
2422
/* step 1: compute from and to index */
2523
const fromIndex = arr.findIndex(item => {
@@ -92,7 +90,7 @@ function getFromIndex (arr, find) {
9290
const fromFns = arrayBack(find).map(convertToFunction);
9391

9492
if (fromFns.length === 0) {
95-
throw new Error('from/single required') // TODO: obviously broken semantically
93+
throw new Error('from/single required')
9694
}
9795

9896
let fromIndex;
@@ -134,7 +132,6 @@ function positional (arr, fromIndex, options = {}) {
134132

135133
function defaultOutput (val) { return val }
136134

137-
/* TODO: factor out into a FromTo Extractor-derived class as relevant only to from-to. */
138135
const toPresets = {
139136
singleOptionValue (arg, index, argv, valueIndex) {
140137
return valueIndex > 1 || arg.startsWith('--')
@@ -179,9 +176,6 @@ class CommandLineArgs {
179176
}
180177

181178
/* Do the positionals backwards, so removing them doesn't mess up the position config */
182-
/* TODO: factor this behaviour out into a specialised Extractor derived Positional class. Remove hard-coded logic switches like 'positional', logic & behaviour should be passed in. */
183-
/* TODO: Need a "pre-processing" step for Extractor-specific steps like changing the sort order */
184-
/* TODO: Should positionals be processed last to avoid extracting fromTo or single definitions (e.g. --option value) */
185179
const positionals = optionDefinitions.filter(d => d.extractor === 'positional');
186180
positionals.sort((a, b) => b.position - a.position);
187181

index.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { fromTo, single, positional } from './lib/from-to.js'
22

33
function defaultOutput (val) { return val }
44

5-
/* TODO: factor out into a FromTo Extractor-derived class as relevant only to from-to. */
65
const toPresets = {
76
singleOptionValue (arg, index, argv, valueIndex) {
87
return valueIndex > 1 || arg.startsWith('--')
@@ -47,9 +46,6 @@ class CommandLineArgs {
4746
}
4847

4948
/* Do the positionals backwards, so removing them doesn't mess up the position config */
50-
/* TODO: factor this behaviour out into a specialised Extractor derived Positional class. Remove hard-coded logic switches like 'positional', logic & behaviour should be passed in. */
51-
/* TODO: Need a "pre-processing" step for Extractor-specific steps like changing the sort order */
52-
/* TODO: Should positionals be processed last to avoid extracting fromTo or single definitions (e.g. --option value) */
5349
const positionals = optionDefinitions.filter(d => d.extractor === 'positional')
5450
positionals.sort((a, b) => b.position - a.position)
5551

lib/from-to.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,12 @@ import arrayBack from 'array-back'
1010
* - Find one or more items, return them, remove them from the input array
1111
*
1212
* arr {string[]} - Input array. Only mutated if `options.remove` is set.
13-
* [options.rtol] {boolean} - Enable right-to-left scans. Either that or pass in a custom iterator. TODO.
1413
* [options.remove] {boolean} - Remove from source array
1514
* [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.
1615
* [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.
1716
* @returns string[]
1817
*/
1918

20-
/* TODO: rename to extractFromTo? Rename `options.remove` to `extract`. */
2119
function fromTo (arr, options = {}) {
2220
/* step 1: compute from and to index */
2321
const fromIndex = arr.findIndex(item => {
@@ -90,7 +88,7 @@ function getFromIndex (arr, find) {
9088
const fromFns = arrayBack(find).map(convertToFunction)
9189

9290
if (fromFns.length === 0) {
93-
throw new Error('from/single required') // TODO: obviously broken semantically
91+
throw new Error('from/single required')
9492
}
9593

9694
let fromIndex

test/from-to.js

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ test.set('from and to: string inputs', async function () {
77
const arr = ['one', 'here', '--', '--', '--', 'here', '--', '--', '--', 'there']
88
const result = fromTo(arr, {
99
from: 'here',
10-
to: ['rabbit', 'here', 'there'] // "to" implies one or more values expected. TODO: multiplicity config instread? E.g. `1..*` like UML.
10+
to: ['rabbit', 'here', 'there']
1111
})
1212
a.deepEqual(result, ['here', '--', '--', '--'])
1313
a.deepEqual(arr, ['one', 'here', '--', '--', '--', 'here', '--', '--', '--', 'there'])
@@ -49,15 +49,6 @@ test.set('no to, returns all items', async function () {
4949
a.deepEqual(result, ['here', '--', '--', '--', 'here', '--', '--', '--', 'there'])
5050
})
5151

52-
skip.set('from second occurance', async function () {
53-
const arr = ['one', 'here', '--', '--', '--', 'here', '--', '--', '--', 'there']
54-
const result = fromTo(arr, {
55-
from: 'here',
56-
fromOccurance: 2 // TODO: NOT IMPLEMENTED. DEPRECATED? Implement by passing in an array which already starts from the second occurance?
57-
})
58-
a.deepEqual(result, ['here', '--', '--', '--', 'here', '--', '--', '--', 'there'])
59-
})
60-
6152
/* Useful for parsing a --flag. Create new config called "once" and make "from" always imply `toEnd`. Remove toEnd. */
6253
test.set('single, no remove', async function () {
6354
const arr = ['one', 'here', '--', '--', '--', 'here', '--', '--', '--', 'there']

0 commit comments

Comments
 (0)