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.41.0 to 0.42.0

86

dist/index.d.ts

@@ -95,6 +95,6 @@ import { Equals, Dict, CamelCase, MaybeArray as MaybeArray$1 } from '@clerc/utils';

type Locales = Dict<Dict<string>>;
type TranslateFn = (name: string, ...args: string[]) => string | undefined;
type TranslateFunction = (name: string, ...arguments_: string[]) => string | undefined;
interface I18N {
add: (locales: Locales) => void;
t: TranslateFn;
t: TranslateFunction;
}

@@ -152,4 +152,4 @@

}
type Handler<C extends Commands = Commands, K extends keyof C = keyof C, GF extends GlobalFlagOptions = {}> = (ctx: HandlerContext<C, K, GF>) => void;
type HandlerInCommand<C extends HandlerContext> = (ctx: {
type Handler<C extends Commands = Commands, K extends keyof C = keyof C, GF extends GlobalFlagOptions = {}> = (context: HandlerContext<C, K, GF>) => void;
type HandlerInCommand<C extends HandlerContext> = (context: {
[K in keyof C]: C[K];

@@ -161,7 +161,7 @@ }) => void;

};
type Inspector<C extends Commands = Commands> = InspectorFn<C> | InspectorObject<C>;
type InspectorFn<C extends Commands = Commands> = (ctx: InspectorContext<C>, next: () => void) => void;
type Inspector<C extends Commands = Commands> = InspectorFunction<C> | InspectorObject<C>;
type InspectorFunction<C extends Commands = Commands> = (context: InspectorContext<C>, next: () => void) => void;
interface InspectorObject<C extends Commands = Commands> {
enforce?: "pre" | "post";
fn: InspectorFn<C>;
fn: InspectorFunction<C>;
}

@@ -288,3 +288,3 @@

* Clerc.create().errorHandler((err) => {
* console.log(err);
* console.log(err);
* });

@@ -296,3 +296,3 @@ * ```

*/
errorHandler(handler: (err: any) => void): this;
errorHandler(handler: (error: any) => void): this;
/**

@@ -305,9 +305,9 @@ * Register a command

* Clerc.create().command("test", "test command", {
* alias: "t",
* flags: {
* foo: {
* alias: "f",
* description: "foo flag",
* },
* },
* alias: "t",
* flags: {
* foo: {
* alias: "f",
* description: "foo flag",
* },
* },
* });

@@ -320,8 +320,8 @@ * ```

* Clerc.create().command("", "root", {
* flags: {
* foo: {
* alias: "f",
* description: "foo flag",
* },
* },
* flags: {
* foo: {
* alias: "f",
* description: "foo flag",
* },
* },
* });

@@ -344,4 +344,4 @@ * ```

* Clerc.create().flag("help", "help", {
* alias: "h",
* type: Boolean,
* alias: "h",
* type: Boolean,
* });

@@ -363,6 +363,6 @@ * ```

* Clerc.create()
* .command("test", "test command")
* .on("test", (ctx) => {
* console.log(ctx);
* });
* .command("test", "test command")
* .on("test", (ctx) => {
* console.log(ctx);
* });
* ```

@@ -395,4 +395,4 @@ *

* Clerc.create().inspector((ctx, next) => {
* console.log(ctx);
* next();
* console.log(ctx);
* next();
* });

@@ -435,10 +435,10 @@ * ```

commandName: string;
constructor(commandName: string, t: TranslateFn);
constructor(commandName: string, t: TranslateFunction);
}
declare class NoSuchCommandError extends Error {
commandName: string;
constructor(commandName: string, t: TranslateFn);
constructor(commandName: string, t: TranslateFunction);
}
declare class NoCommandGivenError extends Error {
constructor(t: TranslateFn);
constructor(t: TranslateFunction);
}

@@ -448,19 +448,19 @@ declare class CommandNameConflictError extends Error {

n2: string;
constructor(n1: string, n2: string, t: TranslateFn);
constructor(n1: string, n2: string, t: TranslateFunction);
}
declare class ScriptNameNotSetError extends Error {
constructor(t: TranslateFn);
constructor(t: TranslateFunction);
}
declare class DescriptionNotSetError extends Error {
constructor(t: TranslateFn);
constructor(t: TranslateFunction);
}
declare class VersionNotSetError extends Error {
constructor(t: TranslateFn);
constructor(t: TranslateFunction);
}
declare class InvalidCommandNameError extends Error {
commandName: string;
constructor(commandName: string, t: TranslateFn);
constructor(commandName: string, t: TranslateFunction);
}
declare class LocaleNotCalledFirstError extends Error {
constructor(t: TranslateFn);
constructor(t: TranslateFunction);
}

@@ -475,6 +475,6 @@

declare function resolveFlattenCommands(commands: Commands, t: TranslateFn): Map<string[] | typeof Root, CommandAlias>;
declare function resolveCommand(commands: Commands, argv: string[], t: TranslateFn): [Command<string | RootType> | undefined, string[] | RootType | undefined];
declare function resolveFlattenCommands(commands: Commands, t: TranslateFunction): Map<string[] | typeof Root, CommandAlias>;
declare function resolveCommand(commands: Commands, argv: string[], t: TranslateFunction): [Command<string | RootType> | undefined, string[] | RootType | undefined];
declare const resolveArgv: () => string[];
declare function compose(inspectors: Inspector[]): (ctx: InspectorContext) => void;
declare function compose(inspectors: Inspector[]): (context: InspectorContext) => void;
declare const isValidName: (name: CommandType) => boolean;

@@ -486,2 +486,2 @@ declare const withBrackets: (s: string, isOptional?: boolean) => string;

export { Clerc, Command, CommandAlias, CommandCustomProperties, CommandExistsError, CommandNameConflictError, CommandOptions, CommandType, CommandWithHandler, Commands, DescriptionNotSetError, FallbackType, Flag, FlagOptions, Flags, GlobalFlagOption, GlobalFlagOptions, Handler, HandlerContext, HandlerInCommand, I18N, Inspector, InspectorContext, InspectorFn, InspectorObject, InvalidCommandNameError, LocaleNotCalledFirstError, Locales, MakeEventMap, NoCommandGivenError, NoSuchCommandError, ParseOptions, Plugin, Root, RootType, ScriptNameNotSetError, TranslateFn, VersionNotSetError, compose, defineCommand, defineHandler, defineInspector, definePlugin, detectLocale, formatCommandName, isValidName, resolveArgv, resolveCommand, resolveFlattenCommands, stripFlags, withBrackets };
export { Clerc, Command, CommandAlias, CommandCustomProperties, CommandExistsError, CommandNameConflictError, CommandOptions, CommandType, CommandWithHandler, Commands, DescriptionNotSetError, FallbackType, Flag, FlagOptions, Flags, GlobalFlagOption, GlobalFlagOptions, Handler, HandlerContext, HandlerInCommand, I18N, Inspector, InspectorContext, InspectorFunction, InspectorObject, InvalidCommandNameError, LocaleNotCalledFirstError, Locales, MakeEventMap, NoCommandGivenError, NoSuchCommandError, ParseOptions, Plugin, Root, RootType, ScriptNameNotSetError, TranslateFunction, VersionNotSetError, compose, defineCommand, defineHandler, defineInspector, definePlugin, detectLocale, formatCommandName, isValidName, resolveArgv, resolveCommand, resolveFlattenCommands, stripFlags, withBrackets };

@@ -147,4 +147,4 @@ import { format } from 'node:util';

function mapParametersToArguments(mapping, parameters, cliArguments, t) {
for (let i = 0; i < parameters.length; i += 1) {
const { name, required, spread } = parameters[i];
for (let index = 0; index < parameters.length; index += 1) {
const { name, required, spread } = parameters[index];
const camelCaseName = camelCase(name);

@@ -154,5 +154,5 @@ if (camelCaseName in mapping) {

}
const value = spread ? cliArguments.slice(i) : cliArguments[i];
const value = spread ? cliArguments.slice(index) : cliArguments[index];
if (spread) {
i = parameters.length;
index = parameters.length;
}

@@ -201,7 +201,7 @@ if (required && (!value || spread && value.length === 0)) {

const parsed = typeFlag((_a = command == null ? void 0 : command.flags) != null ? _a : /* @__PURE__ */ Object.create(null), [...argv]);
const { _: args } = parsed;
const { _: arguments_ } = parsed;
if (name === Root) {
continue;
}
if (arrayStartsWith(args, name)) {
if (arrayStartsWith(arguments_, name)) {
return [command, name];

@@ -234,3 +234,3 @@ }

}
const mergedInspectorFns = [
const mergedInspectorFunctions = [
...inspectorMap.pre,

@@ -240,7 +240,7 @@ ...inspectorMap.normal,

];
return (ctx) => {
return (context) => {
return dispatch(0);
function dispatch(i) {
const inspector = mergedInspectorFns[i];
return inspector(ctx, dispatch.bind(null, i + 1));
function dispatch(index) {
const inspector = mergedInspectorFunctions[index];
return inspector(context, dispatch.bind(null, index + 1));
}

@@ -255,3 +255,3 @@ };

const detectLocale = () => process.env.CLERC_LOCALE ? process.env.CLERC_LOCALE : Intl.DateTimeFormat().resolvedOptions().locale;
const stripFlags = (argv) => argv.filter((arg) => !arg.startsWith("-"));
const stripFlags = (argv) => argv.filter((argument) => !argument.startsWith("-"));

@@ -312,6 +312,6 @@ var __accessCheck = (obj, member, msg) => {

},
t: (name, ...args) => {
t: (name, ...arguments_) => {
const localeObject = __privateGet(this, _locales)[__privateGet(this, _locale)] || __privateGet(this, _locales)[__privateGet(this, _defaultLocale)];
const defaultLocaleObject = __privateGet(this, _locales)[__privateGet(this, _defaultLocale)];
return localeObject[name] ? format(localeObject[name], ...args) : defaultLocaleObject[name] ? format(defaultLocaleObject[name], ...args) : void 0;
return localeObject[name] ? format(localeObject[name], ...arguments_) : defaultLocaleObject[name] ? format(defaultLocaleObject[name], ...arguments_) : void 0;
}

@@ -482,3 +482,3 @@ };

* Clerc.create().errorHandler((err) => {
* console.log(err);
* console.log(err);
* });

@@ -505,4 +505,4 @@ * ```

* Clerc.create().flag("help", "help", {
* alias: "h",
* type: Boolean,
* alias: "h",
* type: Boolean,
* });

@@ -530,6 +530,6 @@ * ```

* Clerc.create()
* .command("test", "test command")
* .on("test", (ctx) => {
* console.log(ctx);
* });
* .command("test", "test command")
* .on("test", (ctx) => {
* console.log(ctx);
* });
* ```

@@ -568,4 +568,4 @@ *

* Clerc.create().inspector((ctx, next) => {
* console.log(ctx);
* next();
* console.log(ctx);
* next();
* });

@@ -712,4 +712,4 @@ * ```

const parsed = typeFlag(flagsMerged, [...argv]);
const { _: args, flags, unknownFlags } = parsed;
let parameters = !isCommandResolved || command.name === Root ? args : args.slice(command.name.split(" ").length);
const { _: arguments_, flags, unknownFlags } = parsed;
let parameters = !isCommandResolved || command.name === Root ? arguments_ : arguments_.slice(command.name.split(" ").length);
let commandParameters = (_a = command == null ? void 0 : command.parameters) != null ? _a : [];

@@ -721,3 +721,3 @@ const hasEof = commandParameters.indexOf("--");

commandParameters = commandParameters.slice(0, hasEof);
const eofArguments = args["--"];
const eofArguments = arguments_["--"];
parameters = parameters.slice(0, -eofArguments.length || void 0);

@@ -760,12 +760,12 @@ mapParametersToArguments(

_callWithErrorHandling = new WeakSet();
callWithErrorHandling_fn = function(fn) {
callWithErrorHandling_fn = function(function_) {
try {
fn();
} catch (e) {
function_();
} catch (error) {
if (__privateGet(this, _errorHandlers).length > 0) {
for (const cb of __privateGet(this, _errorHandlers)) {
cb(e);
for (const callback of __privateGet(this, _errorHandlers)) {
callback(error);
}
} else {
throw e;
throw error;
}

@@ -786,3 +786,3 @@ }

enforce: "post",
fn: (ctx) => {
fn: (context) => {
const [command] = getCommand();

@@ -794,3 +794,3 @@ const stringName = stripFlags(argv).join(" ");

}
__privateGet(this, _commandEmitter).emit(command.name, ctx);
__privateGet(this, _commandEmitter).emit(command.name, context);
}

@@ -797,0 +797,0 @@ };

{
"name": "@clerc/core",
"version": "0.41.0",
"version": "0.42.0",
"author": "Ray <i@mk1.io> (https://github.com/so1ve)",

@@ -15,10 +15,10 @@ "type": "module",

],
"homepage": "https://github.com/so1ve/clerc/tree/main/packages/core#readme",
"homepage": "https://github.com/clercjs/clerc/tree/main/packages/core#readme",
"repository": {
"type": "git",
"url": "git+https://github.com/so1ve/clerc.git",
"url": "git+https://github.com/clercjs/clerc.git",
"directory": "/"
},
"bugs": {
"url": "https://github.com/so1ve/clerc/issues"
"url": "https://github.com/clercjs/clerc/issues"
},

@@ -54,5 +54,5 @@ "license": "MIT",

"lite-emit": "^2.2.0",
"type-fest": "^3.12.0",
"type-fest": "^4.0.0",
"type-flag": "^3.0.0",
"@clerc/utils": "0.41.0"
"@clerc/utils": "0.42.0"
},

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

@@ -5,3 +5,3 @@ # @clerc/core

See [Clerc](https://github.com/so1ve/clerc) for documentation.
See [Clerc](https://github.com/clercjs/clerc) for documentation.

@@ -8,0 +8,0 @@ ## 📝 License

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