12 changed files with 120 additions and 49 deletions
			
			
		@ -1,25 +0,0 @@ | 
				
			|||
// Common JS cannot be used in frontend sadly
 | 
				
			|||
// sleep, ucfirst is duplicated in ../src/util-frontend.js
 | 
				
			|||
 | 
				
			|||
exports.DOWN = 0; | 
				
			|||
exports.UP = 1; | 
				
			|||
exports.PENDING = 2; | 
				
			|||
 | 
				
			|||
exports.sleep = function (ms) { | 
				
			|||
    return new Promise(resolve => setTimeout(resolve, ms)); | 
				
			|||
} | 
				
			|||
 | 
				
			|||
exports.ucfirst = function (str) { | 
				
			|||
    if (! str) { | 
				
			|||
        return str; | 
				
			|||
    } | 
				
			|||
 | 
				
			|||
    const firstLetter = str.substr(0, 1); | 
				
			|||
    return firstLetter.toUpperCase() + str.substr(1); | 
				
			|||
} | 
				
			|||
 | 
				
			|||
exports.debug = (msg) => { | 
				
			|||
    if (process.env.NODE_ENV === "development") { | 
				
			|||
        console.log(msg) | 
				
			|||
    } | 
				
			|||
} | 
				
			|||
@ -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; | 
				
			|||
@ -0,0 +1,31 @@ | 
				
			|||
// Common Util for frontend and backend
 | 
				
			|||
// Backend uses the compiled file util.js
 | 
				
			|||
// Frontend uses util.ts
 | 
				
			|||
// Need to run "tsc" to compile if there are any changes.
 | 
				
			|||
 | 
				
			|||
export const DOWN = 0; | 
				
			|||
export const UP = 1; | 
				
			|||
export const PENDING = 2; | 
				
			|||
 | 
				
			|||
export function sleep(ms) { | 
				
			|||
    return new Promise(resolve => setTimeout(resolve, ms)); | 
				
			|||
} | 
				
			|||
 | 
				
			|||
/** | 
				
			|||
 * PHP's ucfirst | 
				
			|||
 * @param str | 
				
			|||
 */ | 
				
			|||
export function ucfirst(str) { | 
				
			|||
    if (! str) { | 
				
			|||
        return str; | 
				
			|||
    } | 
				
			|||
 | 
				
			|||
    const firstLetter = str.substr(0, 1); | 
				
			|||
    return firstLetter.toUpperCase() + str.substr(1); | 
				
			|||
} | 
				
			|||
 | 
				
			|||
export function debug(msg) { | 
				
			|||
    if (process.env.NODE_ENV === "development") { | 
				
			|||
        console.log(msg) | 
				
			|||
    } | 
				
			|||
} | 
				
			|||
@ -0,0 +1,14 @@ | 
				
			|||
{ | 
				
			|||
    "compileOnSave": true, | 
				
			|||
    "compilerOptions": { | 
				
			|||
        "target": "ES2018", | 
				
			|||
        "module": "commonjs", | 
				
			|||
        "removeComments": true, | 
				
			|||
        "preserveConstEnums": true, | 
				
			|||
        "sourceMap": false, | 
				
			|||
        "files.insertFinalNewline": true | 
				
			|||
    }, | 
				
			|||
    "files": [ | 
				
			|||
        "./server/util.ts" | 
				
			|||
    ] | 
				
			|||
} | 
				
			|||
					Loading…
					
					
				
		Reference in new issue