| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- let matchNumberStr = ['0',]
- // 部分关键字转换为boolean值
- let falseField = ['false','False','FALSE','null','Null','NULL','undefined','Undefined'];
- let trueField = ['true','True','TRUE'];
- // 类型转换
- function toString(){
- // 情况1 非对象,直接调用内部值
- }
- // 转换为number类型,先用toBoolean转换为布尔类型
- function toNumber(v){
- if(isString(v)){
- if(falseField.includes(v)){
- v = toBoolean(v)
- }else if (trueField.includes(v)){
- v = toBoolean(v)
- }
- }
- return Number(v)
- }
- // 考虑字段类型
- function toBoolean(v){
- // 字符串类型
- if (isString(v)){
- if(falseField.includes(v)){
- return false
- }else if (trueField.includes(v)){
- return true
- }else{
- Boolean(v)
- }
- }
- }
- function isArray(v){
- return v instanceof Array
- }
- function isString(v){
- return v instanceof String || typeof v === 'string'
- }
- function isNumber(v){
- return v instanceof Number
- }
- function isObject(v){
- return v instanceof Object
- }
- module.exports = {
- toNumber,
- toString,
- toBoolean
- }
|