Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

comline

Package Overview
Dependencies
Maintainers
0
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

comline - npm Package Compare versions

Comparing version 0.1.1 to 0.1.2

30

dist/cli.d.ts

@@ -0,1 +1,3 @@

import { Flat, ToPath, Tree, TreeMap, TreePath } from 'treetrunks';
export * from 'treetrunks';
import { z, ZodSchema } from 'zod';

@@ -5,28 +7,2 @@

declare function required<T>(arg: T): [`required`, T];
declare function optional<T>(arg: T): [`optional`, T];
type TreeContents = Readonly<{
[key: string]: Tree | null;
}>;
type OptionalTree = [`optional`, TreeContents];
type RequiredTree = [`required`, TreeContents];
type Tree = OptionalTree | RequiredTree;
type TreePath<T extends Tree> = {
[K in keyof T[1]]: T[0] extends `required` ? T[1][K] extends Tree ? [K extends `$${string}` ? string & {} : K, ...TreePath<T[1][K]>] : [K extends `$${string}` ? string & {} : K] : (T[1][K] extends Tree ? [K extends `$${string}` ? string & {} : K, ...TreePath<T[1][K]>] : [K extends `$${string}` ? string & {} : K]) | [];
}[keyof T[1]];
type TreePathName<T extends Tree> = {
[K in keyof T[1]]: T[0] extends `required` ? T[1][K] extends Tree ? [K, ...TreePathName<T[1][K]>] : [K] : (T[1][K] extends Tree ? [K, ...TreePathName<T[1][K]>] : [K]) | [];
}[keyof T[1]];
type Flat<R extends {
[K in PropertyKey]: any;
}> = {
[K in keyof R]: R[K];
};
type TreeMap<T extends Tree, P> = {
[K in Join<TreePathName<T>, `/`>]: P;
};
type Join<Arr extends any[], Separator extends string = ``> = Arr extends [] ? `` : Arr extends [infer First extends string] ? First : Arr extends [infer First extends string, ...infer Rest extends string[]] ? `${First}${Separator}${Join<Rest, Separator>}` : string;
type ToPath<S extends string, D extends string> = S extends `${infer T extends string}${D}${infer U extends string}` ? T extends `$${string}` ? [string & {}, ...ToPath<U, D>] : [T, ...ToPath<U, D>] : S extends `$${string}` ? [string & {}] : [S];
type MySplit = ToPath<`hello/$world/good/morning`, `/`>;
type EncapsulationOptions = {

@@ -102,2 +78,2 @@ console?: boolean;

export { type CliOption, type CliOptionValue, type CliParseOutput, type CliRoutes, type CommandLineInterface, type EncapsulationOptions, type Flag, type Flat, type Join, type MySplit, type OptionalTree, type OptionsGroup, type RequiredTree, type ToPath, type Tree, type TreeContents, type TreeMap, type TreePath, type TreePathName, cli, encapsulate, optional, parseArrayOption, parseBooleanOption, parseNumberOption, parseStringOption, required };
export { type CliOption, type CliOptionValue, type CliParseOutput, type CliRoutes, type CommandLineInterface, type EncapsulationOptions, type Flag, type OptionsGroup, cli, encapsulate, parseArrayOption, parseBooleanOption, parseNumberOption, parseStringOption };

20

dist/cli.js
// src/cli.ts
import * as fs from "node:fs";
import * as path from "node:path";
import {z} from "zod";
import {zodToJsonSchema} from "zod-to-json-schema";
import { z } from "zod";
import { zodToJsonSchema } from "zod-to-json-schema";

@@ -231,3 +231,3 @@ // src/option-parsers.ts

}
// src/tree.ts
// ../treetrunks/src/treetrunks.ts
function required(arg) {

@@ -247,3 +247,3 @@ return [`required`, arg];

// src/cli.ts
function retrieveArgValue(argument, flag2) {
function retrieveArgValue(argument, flag) {
const isSwitch = argument.startsWith(`--`);

@@ -255,4 +255,4 @@ const [key, value] = argument.split(`=`);

retrievedValue = ``;
} else if (flag2) {
retrievedValue = key.split(``).filter((s) => s === flag2).map(() => `,`).join(``).substring(1);
} else if (flag) {
retrievedValue = key.split(``).filter((s) => s === flag).map(() => `,`).join(``).substring(1);
}

@@ -295,5 +295,5 @@ }

const [key, config] = entry;
const { flag: flag2, required: required2, description, example } = config;
const { flag, required: required2, description, example } = config;
const parse = `parse` in config ? config.parse : parseStringOption;
const argumentInstances = passed.filter((arg) => arg.startsWith(`--${key}`) || arg.startsWith(`-`) && !arg.startsWith(`--`) && flag2 && arg.split(`=`)[0].includes(flag2));
const argumentInstances = passed.filter((arg) => arg.startsWith(`--${key}`) || arg.startsWith(`-`) && !arg.startsWith(`--`) && flag && arg.split(`=`)[0].includes(flag));
switch (argumentInstances.length) {

@@ -307,7 +307,7 @@ case 0:

case 1: {
const retrievedValue = retrieveArgValue(argumentInstances[0], flag2);
const retrievedValue = retrieveArgValue(argumentInstances[0], flag);
return [key, parse(retrievedValue)];
}
default: {
const retrievedValues = argumentInstances.map((arg) => retrieveArgValue(arg, flag2)).join(`,`);
const retrievedValues = argumentInstances.map((arg) => retrieveArgValue(arg, flag)).join(`,`);
return [key, parse(retrievedValues)];

@@ -314,0 +314,0 @@ }

{
"name": "comline",
"version": "0.1.1",
"version": "0.1.2",
"license": "MIT",

@@ -21,12 +21,13 @@ "author": {

"zod": "3.23.8",
"zod-to-json-schema": "3.23.3"
"zod-to-json-schema": "3.23.3",
"treetrunks": "0.0.0"
},
"devDependencies": {
"@types/bun": "1.1.9",
"@types/node": "22.5.5",
"@types/node": "22.7.5",
"@types/tmp": "0.2.6",
"bun-types": "1.1.30",
"concurrently": "9.0.1",
"tmp": "0.2.3",
"tsup": "8.2.4",
"vitest": "2.1.1"
"tsup": "8.3.0",
"vitest": "2.1.3"
},

@@ -44,4 +45,5 @@ "scripts": {

"test:once": "vitest run",
"test:coverage": "echo no test coverage yet"
"test:coverage": "echo no test coverage yet",
"postversion": "biome format --write package.json"
}
}
import * as fs from "node:fs"
import * as path from "node:path"
import type { Flat, ToPath, Tree, TreeMap, TreePath } from "treetrunks"
import type { ZodSchema } from "zod"

@@ -11,8 +12,7 @@ import { z } from "zod"

import { retrievePositionalArgs } from "./retrieve-positional-args"
import type { Flat, ToPath, Tree, TreeMap, TreePath } from "./tree"
export * from "./encapsulate"
export * from "./flag"
export type * from "./flag"
export * from "./option-parsers"
export * from "./tree"
export * from "treetrunks"

@@ -19,0 +19,0 @@ export type CliOptionValue =

@@ -1,2 +0,2 @@

import type { Join, Tree, TreePath, TreePathName } from "./tree"
import type { Join, Tree, TreePath, TreePathName } from "treetrunks"

@@ -3,0 +3,0 @@ export function retrievePositionalArgs<PositionalArgTree extends Tree>(

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc