@glacierjs/core
TypeScript icon, indicating that this package has built-in type declarations

0.1.7 • Public • Published

@glacierjs/core

作为 GlacierJS 的核心模块,它提供:

  1. MiddlewareQueue:支撑函数的插件化。
  2. Logger:统一管理 GlacierJS 的日志。
  3. Const:统一管理静态变量

MiddlewareQueue

一个基于洋葱模型的中间件队列。

Quick Usage:

const queue = new MiddlewareQueue();

queue.push(async (context, next) => {
  console.log('A');
  await next();
  console.log('B');
  context.name = 'abc';
});

queue.push(async (context, next) => {
  console.log('C');
  await next();
  console.log('D');
});

const context = {};
await queue.runAll(context);  // print: A C D B
consle.log(context); // { name: 'abc' }

Logger

Quick Usage:

const logger = new Logger({ prefix: 'glacierjs' });
logger.info('hello');  // print: glacierjs [info] hello
logger.debug('hello');  // print: glacierjs [debug] hello
logger.warn('hello');  // print: glacierjs [warn] hello
logger.error('hello');  // print: glacierjs [error] hello

Nest Logger:

const myPluginLogger = logger.extends({ prefix: 'my-plugin' }); 
const myPluginModuleALogger = myPluginLogger.extends({ prefix: 'module-a' });

myPluginLogger.info('hello'); // print: glacierjs-my-plugin [info] hello
myPluginModuleALogger.info('hello'); // print: glacierjs-my-plugin-module-a [info] hello

Level Controller:

Logger.level = Level.ERROR;
logger.info('hello');  // print nothing
logger.debug('hello');  // print nothing
logger.warn('hello');  // print nothing
logger.error('hello');  // print: glacierjs [error] hello

Readme

Keywords

none

Package Sidebar

Install

npm i @glacierjs/core

Weekly Downloads

8

Version

0.1.7

License

MIT

Unpacked Size

146 kB

Total Files

44

Last publish

Collaborators

  • jerryc