kenote-config-helper
TypeScript icon, indicating that this package has built-in type declarations

1.0.11 • Public • Published

config-helper

Configuration helper

NPM Version NPM Downloads Build Status Gratipay

Installation

$ npm install kenote-config-helper
# Or 
$ yarn add kenote-config-helper

Usages

Create Channel

/data/channels/account.yml

---
# 频道 我的帐户 配置 #################################################################### 
###################################################################################### 
 
# 频道 ID 
id            : 1
# 频道名称 
name          : 我的帐户
# 频道标识 
label         : account
# 频道描述 
description   : 查看和管理自己的信息、活动、安全选项和隐私偏好设置
# 默认打开页面 
default       : /account/baseinfo
# 自定义参数 
options:
  # 用户方案类型 
  plan_type:
    key           : ditch
      name          : 渠道
    key           : sendmail
      name          : 系统邮件
# 频道导航 
navs:
  # 导航分栏 -- 帐户管理 
  index         : 1-1
    name          : 帐户管理
    icon          : iconfont icon-passport
    children:
      index         : /account/baseinfo
        name          : 基本资料
      index         : /account/security
        name          : 安全设置
      index         : /account/plan
        name          : 方案管理

app.ts

import { KenoteConfig, Channel, getChannelId } from 'kenote-config-helper'
import { loadData } from 'kenote-config-helper/dist/utils.server'
 
const channels: KenoteConfig.Channel[] = <KenoteConfig.Channel[]> loadData('data/channels', 'array')
 
const channelId: number = getChannelId('/account/baseinfo')
const channel: KenoteConfig.Channel | undefined = channels.find( _channel => _channel.id === channelId )
 
if (channel) {
  let nav: Navigation = new Channel(channel).find('/account/baseinfo')
  /** value for nav
   * {
   *   index  : '/account/baseinfo',
   *   name   : '基本资料'
   * }
   **/
}

Use Error Set

import { useError, Maps } from 'kenote-config-helper'
 
const code: Maps<number> = {
  ERROR_STATUS_NULL                : 0,
  ERROR_AUTH_FLAG_ACCESS           : 1001
}
const message: Maps<string> = {
  ERROR_STATUS_NULL                : 'Request Success!',
  ERROR_AUTH_FLAG_ACCESS           : '没有访问该页面的权限'
}
const start: number = 1000
 
const { __ErrorCode, __ErrorMessage, ErrorInfo } = useError(code, message, start)
 
// thrown custom error
throw ErrorInfo(__ErrorCode.ERROR_AUTH_FLAG_ACCESS)
 
// handing errors
try {
  // ...
} catch (error) {
  if (CustomError(error)) {
    // custom error
  }
  else {
    // system error
  }
}

License

this repo is released under the MIT License.

Package Sidebar

Install

npm i kenote-config-helper

Weekly Downloads

0

Version

1.0.11

License

MIT

Unpacked Size

94 kB

Total Files

47

Last publish

Collaborators

  • thondery