1.0.9 • Published 22 days ago
siutils v1.0.9
import { BaseEnum, is } from 'siutils'
class CompanyStatusEnum extends BaseEnum<CompanyStatusEnum> {
TEST = this.created({ code: 0, label: '测试', oth: '1' } as const)
DEBUG = this.created({ code: 1, label: '灰度', oth: '1' } as const)
PROD = this.created({ code: 2, label: '生产', oth: '1' } as const)
custom() {
console.log(this.TEST.code)
console.log(this.TEST.label)
console.log(this.custom)
console.log(this.toArray())
this.toArray().map((item) => {
console.log(item)
})
console.log(this.toOriginArray())
this.toOriginArray().map(([key, value]) => {
console.log(key, value)
})
console.log(this.getByCode(1))
for (const [key, value] of this) {
console.log(key, value)
}
}
}
const companyStatusEnum2 = new CompanyStatusEnum()
console.dir(companyStatusEnum2)
console.log(companyStatusEnum2.TEST.code)
console.log(companyStatusEnum2.TEST.label)
console.log(companyStatusEnum2.custom)
console.log(companyStatusEnum2.toArray())
companyStatusEnum2.toArray().map((item) => {
console.log(item)
})
console.log(companyStatusEnum2.toOriginArray())
companyStatusEnum2.toOriginArray().map(([key, value]) => {
console.log(key, value)
})
console.log(companyStatusEnum2.getByCode(2))
console.log(companyStatusEnum2.getEnums().TEST.code)
for (const [key, item] of companyStatusEnum2) {
console.log(key, item)
}
is.getValueType(new Map()) // Map
is.getValueType(1) // Number
is.getValueType('1') // String
is.notEmpty(null) // false
is.notEmpty(undefined) // false
is.notEmpty('') // false
is.notEmpty(0) // true
is.def(null) // false
is.def(undefined) // false
is.def('') // true
is.def(0) // true
is.empty(null) // true
is.empty(undefined) // true
is.empty('') // true
is.empty(0) // false
is.plainObject(new function (){})) // false
is.plainObject(new Map()) // false
is.plainObject({}) // true
is.frames() // true || false