@fuman/utils
Advanced tools
@@ -5,6 +5,14 @@ "use strict"; | ||
| middlewares = middlewares.slice(); | ||
| if (final == null) { | ||
| return function(context, next) { | ||
| function dispatch2(i, ctx) { | ||
| const fn = middlewares[i] ?? next; | ||
| return fn(ctx, dispatch2.bind(null, i + 1)); | ||
| } | ||
| return dispatch2(0, context); | ||
| }; | ||
| } | ||
| middlewares.push(final); | ||
| function dispatch(i, ctx) { | ||
| const fn = middlewares[i]; | ||
| if (fn === void 0) return final(ctx); | ||
| return fn(ctx, boundDispatches[i + 1]); | ||
@@ -11,0 +19,0 @@ } |
| export type Middleware<Context, Result = void> = (ctx: Context, next: (ctx: Context) => Promise<Result>) => Promise<Result>; | ||
| export type ComposedMiddleware<Context, Result = void> = (ctx: Context) => Promise<Result>; | ||
| export declare function composeMiddlewares<Context, Result = void>(middlewares: Middleware<Context, Result>[], final: ComposedMiddleware<Context, Result>): ComposedMiddleware<Context, Result>; | ||
| export declare function composeMiddlewares<Context, Result = void>(middlewares: Middleware<Context, Result>[]): Middleware<Context, Result>; |
| export type Middleware<Context, Result = void> = (ctx: Context, next: (ctx: Context) => Promise<Result>) => Promise<Result>; | ||
| export type ComposedMiddleware<Context, Result = void> = (ctx: Context) => Promise<Result>; | ||
| export declare function composeMiddlewares<Context, Result = void>(middlewares: Middleware<Context, Result>[], final: ComposedMiddleware<Context, Result>): ComposedMiddleware<Context, Result>; | ||
| export declare function composeMiddlewares<Context, Result = void>(middlewares: Middleware<Context, Result>[]): Middleware<Context, Result>; |
+9
-1
| function composeMiddlewares(middlewares, final) { | ||
| middlewares = middlewares.slice(); | ||
| if (final == null) { | ||
| return function(context, next) { | ||
| function dispatch2(i, ctx) { | ||
| const fn = middlewares[i] ?? next; | ||
| return fn(ctx, dispatch2.bind(null, i + 1)); | ||
| } | ||
| return dispatch2(0, context); | ||
| }; | ||
| } | ||
| middlewares.push(final); | ||
| function dispatch(i, ctx) { | ||
| const fn = middlewares[i]; | ||
| if (fn === void 0) return final(ctx); | ||
| return fn(ctx, boundDispatches[i + 1]); | ||
@@ -8,0 +16,0 @@ } |
+1
-1
| { | ||
| "name": "@fuman/utils", | ||
| "type": "module", | ||
| "version": "0.0.10", | ||
| "version": "0.0.11", | ||
| "description": "various utils", | ||
@@ -6,0 +6,0 @@ "license": "MIT", |
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
168960
0.41%4951
0.34%