0.0.4 • Published 5 years ago
@originforest/common v0.0.4
Common library in originforest
Setup
npm i @originforest/common
set config in tsconfig.json
"experimentalDecorators": true,
"emitDecoratorMetadata": true,Distributed identity
use api
import {identity} from '@originforest/common'
// a unique id.
let id = identity.nextId();
// test id.
if (!identity.isValidId(id)) {
}
// id length.
identity.idLength == 32use decorator
import {Identity} from '@originforest/common'
class Demo {
  @Identity
  id: string;
}
// a unique id.
new Demo().idErrorCode
import {errorCode, getErrorCodeMsg} from '@originforest/common';
// get the errCode
errorCode.OK                // 200
errorCode.NOT_FOUND         // 404
errorCode.OPERATOR_EXPIRED  // 408
getErrorCodeMsg(errorCode.OPERATOR_EXPIRED) // 'OPERATOR_EXPIRED'Msg
Network message package.
import {Msg, errorCode} from '@originforest/common';
let msg:Msg = {
  err_code: errorCode.OK
}