UNPKG

kitten-cloud-function

Version:

用于编程猫源码云功能(云变量、云列表等)的客户端工具

34 lines (33 loc) 941 B
/** 用户性别。*/ export class CodemaoUserSex { static from(argument) { if (argument instanceof CodemaoUserSex) { return argument; } return CodemaoUserSex.parse(argument); } static parse(type) { if (typeof type == "number") { type = type.toString(); } type = type.toUpperCase(); if (!(type in sexMap)) { throw new Error(`无法识别的用户性别:${type}`); } return sexMap[type]; } constructor(name) { this.name = name; this.symbol = Symbol(name); } toString() { return this.name; } } /** 男性。*/ CodemaoUserSex.MALE = new CodemaoUserSex("男"); /** 女性。*/ CodemaoUserSex.FEMALE = new CodemaoUserSex("女"); const sexMap = { "1": CodemaoUserSex.MALE, "MALE": CodemaoUserSex.MALE, "0": CodemaoUserSex.FEMALE, "FEMALE": CodemaoUserSex.FEMALE };