-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmcodeServer.js
More file actions
129 lines (120 loc) · 3.5 KB
/
mcodeServer.js
File metadata and controls
129 lines (120 loc) · 3.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
// <copyright file="mcodeServer.js" company="MicroCODE Incorporated">Copyright © 2021 MicroCODE Incorporated Troy, MI</copyright><author>Timothy J. McGuire</author>
/*
* Title: MicroCODE Common Server Function Library
* Module: modules (MicroCODE:mcodeServer.js)
* Project: MicroCODE Common Library
* Customer: Internal
* Creator: MicroCODE Incorporated
* Date: January 2022
* Author: Timothy J McGuire
*
* Designed and Coded: 2022 MicroCODE Incorporated
*
* This software and related materials are the property of
* MicroCODE Incorporated and contain confidential and proprietary
* information. This software and related materials shall not be
* duplicated, disclosed to others, or used in any way without the
* written of MicroCODE Incorported.
*
*
* DESCRIPTION:
* ------------
*
* This module implements the MicroCODE's Common JavaScript Server/Back-End functions.
*
*
* REFERENCES:
* -----------
*
* 1. MIT xPRO Course: Professional Certificate in Coding: Full Stack Development with MERN
*
*
* VIDEOS:
* -------
*
* 1. ...
*
*
*
* MODIFICATIONS:
* --------------
*
* Date: By-Group: Rev: Description:
*
* 27-Jan-2022 TJM-MCODE {0001} New module for common reusable Javascript UI/Client functions.
* 05-Mar-2022 TJM-MCODE {0002} Documentation updates.
* 04-May-0222 TJM-MCODE {0003} Corrected 'month' in timeStamp.
*
*
*/
"use strict";
// Create an object to hold our exported methods
var methods = {};
/**
* timestamp() -- function to generate timestamp string: YYYY-MM-DD HH:MM:SS.mmm.
* @returns {String} "YYYY-MM-DD HH:MM:SS.mmm".
* @api public
*/
methods.timeStamp = function ()
{
let now = new Date();
let month = Number(now.getMonth()) + 1; // {0003}
return (
now.getFullYear() +
"-" +
month +
"-" +
now.getDate() +
" " +
now.getHours() +
":" +
now.getMinutes() +
":" +
now.getSeconds() +
"." +
now.getMilliseconds()
);
};
/**
* Strips a string of BRACES, BRACKETS, QUOTES, etc.
*
* @param {string} textToSimplify the string to be simplified to data
* @returns {string} the simplified text
* @api public
*/
methods.simplifyText = function (textToSimplify)
{
let simplifiedText = "";
for (let i = 0; i < textToSimplify.length; i++)
{
switch (textToSimplify[i])
{
case '{':
case '}':
case '[':
case ']':
case '"':
break;
case ',':
simplifiedText += textToSimplify[i];
simplifiedText += ' ';
break;
default:
simplifiedText += textToSimplify[i];
break;
}
}
return simplifiedText;
};
/**
* Rounds a floating point number that represents dollars and cents to 2 decimals digits (pennies).
*
* @param {float} numberToRound as a floating point value
* @returns number rounded to dollars and cents (2 decimals place)
*/
methods.roundToCents = function (numberToRound)
{
return +(Math.round(numberToRound + "e+2") + "e-2");
};
// NOTE: Build as CommonJS Module for NodeJS Version v16.7.0
module.exports = methods; // Common JS (CJS) form: module.exports = methods;