Skip to content

Commit

Permalink
Drop @proc7ts/push-iterator dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
surol committed Oct 9, 2020
1 parent 2343f78 commit 88bde6b
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 34 deletions.
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@run-z/optionz",
"version": "1.1.0",
"version": "2.0.0-dev.0",
"description": "Run-z command line options parser",
"keywords": [
"cli",
Expand Down Expand Up @@ -36,7 +36,6 @@
},
"dependencies": {
"@proc7ts/primitives": "^1.1.0",
"@proc7ts/push-iterator": "^2.0.0",
"string-width": "^4.2.0",
"wrap-ansi": "^7.0.0"
},
Expand Down
15 changes: 6 additions & 9 deletions src/help/help-formatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
* @packageDocumentation
* @module @run-z/optionz/help
*/
import { flatMapIt, itsReduction } from '@proc7ts/push-iterator';
import stringWidth from 'string-width';
import wrapAnsi from 'wrap-ansi';
import { clz } from '../colors';
Expand All @@ -19,14 +18,12 @@ export class ZHelpFormatter {
* @param options A list of options meta to format.
*/
usageWidth(options: ZOptionMeta.List): number {
return itsReduction(
flatMapIt(
options,
([, { usage }]) => usage,
),
(prev, usage) => Math.max(prev, stringWidth(usage)),
0,
);
return options
.flatMap(([, { usage }]) => usage)
.reduce(
(prev, usage) => Math.max(prev, stringWidth(usage)),
0,
);
}

/**
Expand Down
37 changes: 15 additions & 22 deletions src/option-syntax.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
* @module @run-z/optionz
*/
import { isArrayOfElements } from '@proc7ts/primitives';
import { filterIt, flatMapIt } from '@proc7ts/push-iterator';
import { ZOptionInput } from './option-input';

/**
Expand All @@ -20,7 +19,7 @@ export type ZOptionSyntax =
*
* @returns An iterable of option inputs. May be empty if the command line argument has another syntax.
*/
(this: void, args: readonly [string, ...string[]]) => Iterable<ZOptionInput>;
(this: void, args: readonly [string, ...string[]]) => readonly ZOptionInput[];

/**
* @internal
Expand Down Expand Up @@ -114,33 +113,27 @@ function zOptionSyntaxBy(syntax: ZOptionSyntax | readonly ZOptionSyntax[]): ZOpt
return syntax;
}

return args => {
return (args: readonly [string, ...string[]]): readonly ZOptionInput[] => {

const tried: ZOptionInput[] = [];

return filterIt(
flatMapIt(
syntax,
p => p(args),
),
input => {
// Prevent input duplicates
if (tried.some(t => ZOptionInput.equal(t, input))) {
return false;
}

tried.push(input);

return true;
},
);
return syntax.flatMap(p => p(args)).filter(input => {
// Prevent input duplicates
if (tried.some(t => ZOptionInput.equal(t, input))) {
return false;
}

tried.push(input);

return true;
});
};
}

/**
* @internal
*/
function longZOptionSyntax(args: readonly [string, ...string[]]): Iterable<ZOptionInput> {
function longZOptionSyntax(args: readonly [string, ...string[]]): readonly ZOptionInput[] {

let [name] = args;

Expand Down Expand Up @@ -181,7 +174,7 @@ function longZOptionSyntax(args: readonly [string, ...string[]]): Iterable<ZOpti
/**
* @internal
*/
function shortZOptionSyntax(args: readonly [string, ...string[]]): Iterable<ZOptionInput> {
function shortZOptionSyntax(args: readonly [string, ...string[]]): readonly ZOptionInput[] {

let [name] = args;

Expand Down Expand Up @@ -243,7 +236,7 @@ function shortZOptionSyntax(args: readonly [string, ...string[]]): Iterable<ZOpt
/**
* @internal
*/
function anyZOptionSyntax(args: readonly [string, ...string[]]): Iterable<ZOptionInput> {
function anyZOptionSyntax(args: readonly [string, ...string[]]): readonly ZOptionInput[] {

const [name] = args;
const values = ZOptionInput.valuesOf(args, 1);
Expand Down
3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
"importHelpers": true,
"noEmitHelpers": true,
"lib": [
"ES2018"
"ES2018",
"ES2019.Array"
],
"types": [
"jest",
Expand Down

0 comments on commit 88bde6b

Please sign in to comment.