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

@clerc/core

Package Overview
Dependencies
Maintainers
1
Versions
61
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@clerc/core - npm Package Compare versions

Comparing version 0.22.0 to 0.22.1

24

dist/index.d.ts

@@ -294,8 +294,8 @@ import * as _clerc_utils from '@clerc/utils';

declare class CommandExistsError extends Error {
name: string;
constructor(name: string);
commandName: string;
constructor(commandName: string);
}
declare class NoSuchCommandError extends Error {
name: string;
constructor(name: string);
commandName: string;
constructor(commandName: string);
}

@@ -320,4 +320,4 @@ declare class NoCommandGivenError extends Error {

declare class InvalidCommandNameError extends Error {
name: string;
constructor(name: string);
commandName: string;
constructor(commandName: string);
}

@@ -333,11 +333,5 @@

declare const isInvalidName: (name: CommandType) => boolean;
declare const withBrackets: (s: string, isOptional?: boolean) => string;
declare const formatCommandName: (name: string | string[] | RootType) => string;
interface ParsedParameter {
name: string;
required: boolean;
spread: boolean;
}
declare function parseParameters(parameters: string[]): ParsedParameter[];
declare function mapParametersToArguments(mapping: Record<string, string | string[]>, parameters: ParsedParameter[], cliArguments: string[]): Error | undefined;
export { Clerc, Command, CommandAlias, CommandCustomProperties, CommandExistsError, CommandNameConflictError, CommandOptions, CommandRecord, CommandType, CommandWithHandler, DescriptionNotSetError, FallbackType, Flag, FlagOptions, Handler, HandlerContext, HandlerInCommand, Inspector, InspectorContext, InspectorFn, InspectorObject, InvalidCommandNameError, MakeEventMap, NameNotSetError, NoCommandGivenError, NoSuchCommandError, Plugin, PossibleInputKind, Root, RootType, VersionNotSetError, compose, defineCommand, defineHandler, defineInspector, definePlugin, isInvalidName, mapParametersToArguments, parseParameters, resolveArgv, resolveCommand, resolveFlattenCommands, resolveParametersBeforeFlag, resolveRootCommands, resolveSubcommandsByParent };
export { Clerc, Command, CommandAlias, CommandCustomProperties, CommandExistsError, CommandNameConflictError, CommandOptions, CommandRecord, CommandType, CommandWithHandler, DescriptionNotSetError, FallbackType, Flag, FlagOptions, Handler, HandlerContext, HandlerInCommand, Inspector, InspectorContext, InspectorFn, InspectorObject, InvalidCommandNameError, MakeEventMap, NameNotSetError, NoCommandGivenError, NoSuchCommandError, Plugin, PossibleInputKind, Root, RootType, VersionNotSetError, compose, defineCommand, defineHandler, defineInspector, definePlugin, formatCommandName, isInvalidName, resolveArgv, resolveCommand, resolveFlattenCommands, resolveParametersBeforeFlag, resolveRootCommands, resolveSubcommandsByParent, withBrackets };

@@ -7,11 +7,11 @@ import { LiteEmit } from 'lite-emit';

class CommandExistsError extends Error {
constructor(name) {
super(`Command "${name}" exists.`);
this.name = name;
constructor(commandName) {
super(`Command "${commandName}" exists.`);
this.commandName = commandName;
}
}
class NoSuchCommandError extends Error {
constructor(name) {
super(`No such command: ${name}`);
this.name = name;
constructor(commandName) {
super(`No such command: ${commandName}`);
this.commandName = commandName;
}

@@ -47,5 +47,5 @@ }

class InvalidCommandNameError extends Error {
constructor(name) {
super(`Bad name format: ${name}`);
this.name = name;
constructor(commandName) {
super(`Bad name format: ${commandName}`);
this.commandName = commandName;
}

@@ -118,14 +118,20 @@ }

function compose(inspectors) {
const preInspectors = [];
const normalInspectors = [];
const postInspectors = [];
const inspectorMap = {
pre: [],
normal: [],
post: []
};
for (const inspector of inspectors) {
const objectInspector = typeof inspector === "object" ? inspector : { fn: inspector };
const { enforce } = objectInspector;
(enforce === "pre" ? preInspectors : enforce === "post" ? postInspectors : normalInspectors).push(objectInspector.fn);
const { enforce, fn } = objectInspector;
if (enforce === "post" || enforce === "pre") {
inspectorMap[enforce].push(fn);
} else {
inspectorMap.normal.push(fn);
}
}
const mergedInspectorFns = [
...preInspectors,
...normalInspectors,
...postInspectors
...inspectorMap.pre,
...inspectorMap.normal,
...inspectorMap.post
];

@@ -141,2 +147,5 @@ return (getCtx) => {

const isInvalidName = (name) => typeof name === "string" && (name.startsWith(" ") || name.endsWith(" "));
const withBrackets = (s, isOptional) => isOptional ? `[${s}]` : `<${s}>`;
const ROOT = "<Root>";
const formatCommandName = (name) => Array.isArray(name) ? name.join(" ") : typeof name === "string" ? name : ROOT;

@@ -230,3 +239,3 @@ const { stringify } = JSON;

__privateAdd(this, _commandEmitter, new LiteEmit());
__privateAdd(this, _usedNames, []);
__privateAdd(this, _usedNames, /* @__PURE__ */ new Set());
__privateSet(this, _name, name || __privateGet(this, _name));

@@ -270,5 +279,2 @@ __privateSet(this, _description, description || __privateGet(this, _description));

const name = !isCommandObject ? nameOrCommand : nameOrCommand.name;
if (__privateGet(this, _commands)[name]) {
throw new CommandExistsError(typeof name === "symbol" ? "" : name);
}
if (isInvalidName(name)) {

@@ -281,8 +287,9 @@ throw new InvalidCommandNameError(name);

for (const name2 of nameList) {
if (__privateGet(this, _usedNames).includes(name2)) {
throw new CommandExistsError(name2);
if (__privateGet(this, _usedNames).has(name2)) {
throw new CommandExistsError(formatCommandName(name2));
}
}
__privateGet(this, _commands)[name] = commandToSave;
__privateGet(this, _usedNames).push(commandToSave.name, ...toArray(commandToSave.alias) || []);
__privateGet(this, _usedNames).add(commandToSave.name);
(toArray(commandToSave.alias) || []).forEach((a) => __privateGet(this, _usedNames).add(a));
isCommandObject && handler && this.on(nameOrCommand.name, handler);

@@ -351,3 +358,3 @@ return this;

name: command == null ? void 0 : command.name,
called: name.length === 0 ? Root : stringName,
called: name.length === 0 && (command == null ? void 0 : command.name) ? Root : stringName,
resolved: isCommandResolved,

@@ -399,7 +406,7 @@ hasRootOrAlias: __privateGet(this, _hasRootOrAlias, hasRootOrAlias_get),

hasRootOrAlias_get = function() {
return __privateGet(this, _usedNames).includes(Root);
return __privateGet(this, _usedNames).has(Root);
};
_hasRoot = new WeakSet();
hasRoot_get = function() {
return !!__privateGet(this, _commands)[Root];
return Object.hasOwn(this._commands, Root);
};

@@ -412,2 +419,2 @@

export { Clerc, CommandExistsError, CommandNameConflictError, DescriptionNotSetError, InvalidCommandNameError, NameNotSetError, NoCommandGivenError, NoSuchCommandError, Root, VersionNotSetError, compose, defineCommand, defineHandler, defineInspector, definePlugin, isInvalidName, mapParametersToArguments, parseParameters, resolveArgv, resolveCommand, resolveFlattenCommands, resolveParametersBeforeFlag, resolveRootCommands, resolveSubcommandsByParent };
export { Clerc, CommandExistsError, CommandNameConflictError, DescriptionNotSetError, InvalidCommandNameError, NameNotSetError, NoCommandGivenError, NoSuchCommandError, Root, VersionNotSetError, compose, defineCommand, defineHandler, defineInspector, definePlugin, formatCommandName, isInvalidName, resolveArgv, resolveCommand, resolveFlattenCommands, resolveParametersBeforeFlag, resolveRootCommands, resolveSubcommandsByParent, withBrackets };
{
"name": "@clerc/core",
"version": "0.22.0",
"version": "0.22.1",
"author": "Ray <nn_201312@163.com> (https://github.com/so1ve)",

@@ -53,3 +53,3 @@ "description": "Clerc core",

"type-flag": "^3.0.0",
"@clerc/utils": "0.22.0"
"@clerc/utils": "0.22.1"
},

@@ -56,0 +56,0 @@ "scripts": {

Sorry, the diff of this file is not supported yet

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