@iot9x.com/nestjs-tdengine-restful
Version:
NestJS TDengine 驱动——基于Restful
63 lines (62 loc) • 2.23 kB
JavaScript
;
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.FormatUtil = void 0;
const common_1 = require("@nestjs/common");
let FormatUtil = class FormatUtil {
/**
* 下划线转小驼峰
* @param raw 下划线格式
*/
underlineToSmallHump(raw) {
return raw.replace(/\_(\w)/g, (all, letter) => letter.toUpperCase());
}
/**
* 小驼峰转下划线
* @param raw 小驼峰格式
*/
smallHumpToUnderline(raw) {
return raw.replace(/([A-Z])/g, '_$1').toLowerCase();
}
/**
* 获取数据值(按照类型转换为Typescript/Javascript的数据类型)
* @param value 原始值
* @param type 数据类型
* @returns 转换后的数据值
*/
getValue(value, type) {
switch (type) {
case 1 /* Bool */:
return !!value;
case 2 /* TinyInt */:
return value;
case 3 /* SmallInt */:
return value;
case 4 /* Int */:
return value;
case 5 /* BigInt */:
return value;
case 6 /* Float */:
return value;
case 7 /* Double */:
return value;
case 8 /* Binary */:
return value;
case 9 /* Timestamp */:
return new Date(value);
case 10 /* NChar */:
return value;
default:
throw new Error('未知数据类型:' + type);
}
}
};
FormatUtil = __decorate([
common_1.Injectable()
], FormatUtil);
exports.FormatUtil = FormatUtil;