add util.ts for sharing common functions between frontend and backend

This commit is contained in:
LouisLam
2021-07-30 11:23:04 +08:00
parent 71af902a4e
commit 081abcb6a1
12 changed files with 120 additions and 49 deletions

24
src/util.js Normal file
View File

@@ -0,0 +1,24 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.debug = exports.ucfirst = exports.sleep = exports.PENDING = exports.UP = exports.DOWN = void 0;
exports.DOWN = 0;
exports.UP = 1;
exports.PENDING = 2;
function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
exports.sleep = sleep;
function ucfirst(str) {
if (!str) {
return str;
}
const firstLetter = str.substr(0, 1);
return firstLetter.toUpperCase() + str.substr(1);
}
exports.ucfirst = ucfirst;
function debug(msg) {
if (process.env.NODE_ENV === "development") {
console.log(msg);
}
}
exports.debug = debug;