nmce-func 0.0.6 → 0.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -707,10 +707,20 @@
707
707
  var m = moment__default['default'].utc(dtUtc);
708
708
  return moment__default['default'].utc().diff(m, 'days');
709
709
  };
710
+ /**
711
+ * How many years from now.
712
+ * @param d
713
+ * @returns
714
+ */
710
715
  DateFunc.getAge = function (d) {
711
716
  var m = moment__default['default'](d);
712
717
  return moment__default['default']().diff(m, 'years');
713
718
  };
719
+ /**
720
+ * Year of date.
721
+ * @param d
722
+ * @returns
723
+ */
714
724
  DateFunc.getYear = function (d) {
715
725
  var m = moment__default['default'](d);
716
726
  return m.year();
@@ -809,44 +819,17 @@
809
819
  return DateFunc;
810
820
  }());
811
821
 
812
- // import { v5 as uuid } from 'uuid/v5 causes ERROR in src / app / _func / helperFunc.ts(1, 10): error TS2305: Module '"C:/VSProjects/ApsCloudTrunk/APS.WebPos.NGCli/NGSource/node_modules/@types/uuid/v5"' has no exported member 'v5'
813
- // https://github.com/DefinitelyTyped/DefinitelyTyped/pull/28439
814
- var HelperFunc = /** @class */ (function () {
815
- function HelperFunc() {
822
+ var HtmlPrintFunc = /** @class */ (function () {
823
+ function HtmlPrintFunc() {
816
824
  }
817
- HelperFunc.loadExternalScript = function (scriptUrl) {
818
- return new Promise(function (resolve, reject) {
819
- var scriptElement = document.createElement('script');
820
- scriptElement.src = scriptUrl;
821
- scriptElement.onload = resolve;
822
- document.body.appendChild(scriptElement);
823
- });
824
- };
825
825
  /**
826
- * 36 UUID string including 4 hyphens. MySql stores GUID as 36 bytes anyway rather than 16bytes.
827
- */
828
- HelperFunc.newUUID = function () {
829
- // return uuid('medilink.com.au', 'apscloud');
830
- return uuid.v4();
831
- };
832
- HelperFunc.newUUIDStartWith0 = function () {
833
- var s = uuid.v4();
834
- return '0000' + s.slice(4);
835
- };
836
- return HelperFunc;
837
- }());
838
-
839
- var HtmlFunc = /** @class */ (function () {
840
- function HtmlFunc() {
841
- }
842
- /**
843
- * Print with buillt-in CSS for internal reports
826
+ * Print with CSS for internal reports
844
827
  * @param htmlTags
845
- * @param baseRef
828
+ * @param cssUrl
846
829
  */
847
- HtmlFunc.printWithCSS = function (htmlTags, baseRef) {
830
+ HtmlPrintFunc.printWithCSS = function (htmlTags, cssUrl) {
848
831
  if (window) {
849
- var htmlToPrint = "<html><head>\n<meta name=\"viewport\" content=\"width=device-width, initial-scale=1, shrink-to-fit=no\"/>\n<link rel=\"stylesheet\" type=\"text/css\" href=\"" + baseRef + "scripts/print190826.css\" media=\"screen,print\"/>\n</head><body onload=\"window.print()\">" + htmlTags + "</body></html>";
832
+ var htmlToPrint = "<html><head>\n<meta name=\"viewport\" content=\"width=device-width, initial-scale=1, shrink-to-fit=no\"/>\n<link rel=\"stylesheet\" type=\"text/css\" href=\"" + cssUrl + "\" media=\"screen,print\"/>\n</head><body onload=\"window.print()\">" + htmlTags + "</body></html>";
850
833
  var popup = window.open('', '_blank', 'width=1024,height=768');
851
834
  popup === null || popup === void 0 ? void 0 : popup.document.open();
852
835
  popup === null || popup === void 0 ? void 0 : popup.document.write(htmlToPrint);
@@ -858,7 +841,7 @@
858
841
  * Print for external documents.
859
842
  * @param htmlTags
860
843
  */
861
- HtmlFunc.print = function (htmlTags) {
844
+ HtmlPrintFunc.print = function (htmlTags) {
862
845
  if (window) {
863
846
  var htmlToPrint = "<html><head>\n<meta name=\"viewport\" content=\"width=device-width, initial-scale=1, shrink-to-fit=no\"/>\n</head><body onload=\"window.print()\">" + htmlTags + "</body></html>";
864
847
  var popup = window.open('', '_blank', 'width=1024,height=768');
@@ -868,17 +851,50 @@
868
851
  }
869
852
  return true;
870
853
  };
871
- HtmlFunc.printImage = function (url) {
854
+ /**
855
+ * Print image url through html img.
856
+ * @param url
857
+ */
858
+ HtmlPrintFunc.printImage = function (url) {
872
859
  var imageTags = "<img src=\"" + url + "\" alt=\"Image from URL\"/>";
873
- HtmlFunc.print(imageTags);
860
+ HtmlPrintFunc.print(imageTags);
861
+ };
862
+ return HtmlPrintFunc;
863
+ }());
864
+
865
+ var JavaScriptFunc = /** @class */ (function () {
866
+ function JavaScriptFunc() {
867
+ }
868
+ /**
869
+ * Some business functions depend on external JavaScript libraries. Lazy loading of respective business modules is good,
870
+ * and this function supports lazy loading of JS libraries.
871
+ * @param scriptUrl
872
+ * @returns Promise for subsequent JS function calls.
873
+ */
874
+ JavaScriptFunc.loadExternalScript = function (scriptUrl) {
875
+ return new Promise(function (resolve, reject) {
876
+ var scriptElement = document.createElement('script');
877
+ scriptElement.src = scriptUrl;
878
+ scriptElement.onload = resolve;
879
+ document.body.appendChild(scriptElement);
880
+ });
874
881
  };
875
- return HtmlFunc;
882
+ return JavaScriptFunc;
876
883
  }());
877
884
 
878
- var JSFunc = /** @class */ (function () {
879
- function JSFunc() {
885
+ /**
886
+ * Basic JSON functions
887
+ */
888
+ var JsonFunc = /** @class */ (function () {
889
+ function JsonFunc() {
880
890
  }
881
- JSFunc.groupBy = function (array, propertyName) {
891
+ /**
892
+ *
893
+ * @param array Group by a property of array element.
894
+ * @param propertyName
895
+ * @returns
896
+ */
897
+ JsonFunc.groupBy = function (array, propertyName) {
882
898
  return array.reduce(function (acc, obj) {
883
899
  var key = obj[propertyName];
884
900
  if (!acc[key]) {
@@ -889,12 +905,13 @@
889
905
  }, {});
890
906
  };
891
907
  /**
892
- * Group by a date property. The key is always of string type and representing milliseconds. The client should convert the string to number.
908
+ * Group by a date property. The key is always of string type and representing milliseconds.
909
+ * The client should convert the string to number.
893
910
  * Angular date pipe could actually consume such string without explicitly converting to number.
894
911
  * @param array
895
912
  * @param propertyName
896
913
  */
897
- JSFunc.groupByDate = function (array, propertyName) {
914
+ JsonFunc.groupByDate = function (array, propertyName) {
898
915
  return array.reduce(function (acc, obj) {
899
916
  var key = DateFunc.dateTimeUtcToLocalDateNumber(obj[propertyName]);
900
917
  if (!acc[key]) {
@@ -906,9 +923,10 @@
906
923
  };
907
924
  /**
908
925
  * Remove null or empty fields including those in nested objects.
926
+ * This is useful for reducing payload of AJAX serialization.
909
927
  * @param obj
910
928
  */
911
- JSFunc.removeNullOrEmptyFields = function (obj) {
929
+ JsonFunc.removeNullOrEmptyFields = function (obj) {
912
930
  for (var f in obj) {
913
931
  var p = obj[f];
914
932
  if (p === null || p === '') {
@@ -919,104 +937,32 @@
919
937
  }
920
938
  }
921
939
  };
922
- JSFunc.removeNullFields = function (obj) {
940
+ /**
941
+ *
942
+ * @param obj Remove null fields of object at only the 1st level.
943
+ */
944
+ JsonFunc.removeNullFields = function (obj) {
923
945
  for (var f in obj) {
924
946
  if (obj[f] === null) {
925
947
  delete obj[f];
926
948
  }
927
949
  }
928
950
  };
929
- return JSFunc;
951
+ return JsonFunc;
930
952
  }());
931
953
 
932
- var StringFunc = /** @class */ (function () {
933
- function StringFunc() {
954
+ /**
955
+ * String functions specific to Australia
956
+ */
957
+ var StringAusFunc = /** @class */ (function () {
958
+ function StringAusFunc() {
934
959
  }
935
- ;
936
- ;
937
- /**
938
- * Up to 2 letters. For John Smith, returns JS, for Huang, Zijian, returns ZH
939
- * @param s
940
- */
941
- StringFunc.getAbbr = function (s) {
942
- if (!s) {
943
- return '';
944
- }
945
- var sArray = s.split(/[\s,]+/);
946
- var comma = s.indexOf(',') >= 0;
947
- if (sArray.length === 1) {
948
- return sArray[0][0];
949
- }
950
- return comma ? sArray[1][0] + sArray[0][0] : sArray[0][0] + sArray[1][0];
951
- };
952
- /**
953
- * A substring with line breaks replaced by space.
954
- * @param s
955
- * @param length
956
- * @returns result, or empty string if the input is empty, null or undefined
957
- */
958
- StringFunc.getOneLineDigest = function (s, length) {
959
- if (!s) {
960
- return '';
961
- }
962
- var ss = s.substring(0, length);
963
- var st = ss.replace(new RegExp('\n', 'g'), ' ') + ((s.length > length) ? '...' : '');
964
- return st.trim();
965
- };
966
- /**
967
- * Remove line breaks and econde with encodeURI() so the data could be saved in Azure as meta. If the string is truncated, the return will have ... suffix.
968
- * @param s
969
- * @param length
970
- * @returns result, or empty string if the input is empty, null or undefined
971
- */
972
- StringFunc.getOneLineDigestOfHtml = function (s, length) {
973
- if (!s) {
974
- return '';
975
- }
976
- var ss = s.substring(0, length);
977
- var st = ss.replace(new RegExp('\n', 'g'), ' ') + ((s.length > length) ? '...' : '');
978
- return encodeURI(st.trim()); //need to encode in order to save as meta in Azure.
979
- };
980
- StringFunc.pad = function (num, size) {
981
- if (num == null) {
982
- return '';
983
- }
984
- var s = num + '';
985
- while (s.length < size) {
986
- s = '0' + s;
987
- }
988
- return s;
989
- };
990
- /**
991
- * get plain text of HTML content
992
- * @param s
993
- * @returns result. If input is empty, null, or undefined, return the same.
994
- */
995
- StringFunc.getHtmlPlainText = function (s) {
996
- if (!s) {
997
- return null;
998
- }
999
- var parser = new DOMParser();
1000
- var html = parser.parseFromString(s, 'text/html');
1001
- return html.body.textContent;
1002
- };
1003
- /**
1004
- *
1005
- * @param s
1006
- * @returns result. If input is empty, null, or undefined, return the same.
1007
- */
1008
- StringFunc.capitalizeWords = function (s) {
1009
- if (!s) {
1010
- return s;
1011
- }
1012
- return s.replace(/(?:^|\s)\S/g, function (a) { return a.toUpperCase(); });
1013
- };
1014
960
  /**
1015
961
  * Validate medicare number
1016
962
  * @param n
1017
963
  * @returns validation error message
1018
964
  */
1019
- StringFunc.validateMedicare = function (n) {
965
+ StringAusFunc.validateMedicare = function (n) {
1020
966
  if (!n) {
1021
967
  return null;
1022
968
  }
@@ -1047,7 +993,7 @@
1047
993
  }
1048
994
  return null;
1049
995
  };
1050
- StringFunc.validateMedicareProviderNumber = function (providerNumber) {
996
+ StringAusFunc.validateMedicareProviderNumber = function (providerNumber) {
1051
997
  if (!providerNumber) {
1052
998
  return null;
1053
999
  }
@@ -1070,7 +1016,7 @@
1070
1016
  }
1071
1017
  return null;
1072
1018
  };
1073
- StringFunc.validateDVAFileNumber = function (dva) {
1019
+ StringAusFunc.validateDVAFileNumber = function (dva) {
1074
1020
  if (!dva) {
1075
1021
  return null;
1076
1022
  }
@@ -1100,7 +1046,7 @@
1100
1046
  }
1101
1047
  return null;
1102
1048
  };
1103
- StringFunc.validateTFN = function (n) {
1049
+ StringAusFunc.validateTFN = function (n) {
1104
1050
  if (!n) {
1105
1051
  return null;
1106
1052
  }
@@ -1132,20 +1078,20 @@
1132
1078
  }
1133
1079
  return null;
1134
1080
  };
1135
- StringFunc.addWeighted = function (p, v, i) {
1136
- return p + v * StringFunc.weights[i];
1081
+ StringAusFunc.addWeighted = function (p, v, i) {
1082
+ return p + v * StringAusFunc.weights[i];
1137
1083
  };
1138
- StringFunc.addAcnWeighted = function (p, v, i) {
1139
- return p + v * StringFunc.acnWeights[i];
1084
+ StringAusFunc.addAcnWeighted = function (p, v, i) {
1085
+ return p + v * StringAusFunc.acnWeights[i];
1140
1086
  };
1141
- StringFunc.generateLookup = function () {
1087
+ StringAusFunc.generateLookup = function () {
1142
1088
  var ns = [];
1143
1089
  for (var i = 0; i < 10; ++i) {
1144
1090
  ns[i * 19 % 89] = i;
1145
1091
  }
1146
1092
  return ns;
1147
1093
  };
1148
- StringFunc.validateABN = function (abn) {
1094
+ StringAusFunc.validateABN = function (abn) {
1149
1095
  if (!abn) {
1150
1096
  return null;
1151
1097
  }
@@ -1154,13 +1100,13 @@
1154
1100
  return { code: 1, message: 'Expect 11-digit.' };
1155
1101
  }
1156
1102
  digits[0] -= 1;
1157
- var sum = digits.reduce(this.addWeighted, 0);
1103
+ var sum = digits.reduce(StringAusFunc.addWeighted, 0);
1158
1104
  if (sum % 89 === 0) {
1159
1105
  return null;
1160
1106
  }
1161
1107
  digits[0] += 1;
1162
- var sum1 = sum - digits[10] * StringFunc.weights[10];
1163
- var digit = StringFunc.suggestLookup[89 - sum1 % 89];
1108
+ var sum1 = sum - digits[10] * StringAusFunc.weights[10];
1109
+ var digit = StringAusFunc.suggestLookup[89 - sum1 % 89];
1164
1110
  if (digit !== undefined) {
1165
1111
  return {
1166
1112
  code: 2,
@@ -1168,10 +1114,10 @@
1168
1114
  };
1169
1115
  }
1170
1116
  else {
1171
- var sum2 = sum1 - digits[9] * StringFunc.weights[9];
1117
+ var sum2 = sum1 - digits[9] * StringAusFunc.weights[9];
1172
1118
  for (var i = 0; i < 10; ++i) {
1173
- sum1 = sum2 + i * StringFunc.weights[9];
1174
- digit = StringFunc.suggestLookup[89 - sum1 % 89];
1119
+ sum1 = sum2 + i * StringAusFunc.weights[9];
1120
+ digit = StringAusFunc.suggestLookup[89 - sum1 % 89];
1175
1121
  if (digit !== undefined) {
1176
1122
  return {
1177
1123
  code: 3,
@@ -1182,7 +1128,7 @@
1182
1128
  }
1183
1129
  return null;
1184
1130
  };
1185
- StringFunc.validateACN = function (acn) {
1131
+ StringAusFunc.validateACN = function (acn) {
1186
1132
  if (!acn) {
1187
1133
  return null;
1188
1134
  }
@@ -1191,7 +1137,7 @@
1191
1137
  if (digits.length !== 9) {
1192
1138
  return { code: 1, message: 'Expect 9-digit.' };
1193
1139
  }
1194
- var sum = digits.slice(0, 8).reduce(StringFunc.addAcnWeighted, 0);
1140
+ var sum = digits.slice(0, 8).reduce(StringAusFunc.addAcnWeighted, 0);
1195
1141
  var lastDigit = 10 - sum % 10;
1196
1142
  if (lastDigit === digits[8]) {
1197
1143
  return null;
@@ -1201,7 +1147,100 @@
1201
1147
  message: 'Checksum is incorrect.'
1202
1148
  };
1203
1149
  };
1204
- StringFunc.prototype.validateEmail = function (email) {
1150
+ return StringAusFunc;
1151
+ }());
1152
+ //thanks to https://github.com/sidorares/australian-business-number/blob/0591475f5978fd122b472edcdc7efe6d96d56f26/index.js
1153
+ StringAusFunc.acnWeights = [8, 7, 6, 5, 4, 3, 2, 1];
1154
+ StringAusFunc.weights = [10, 1, 3, 5, 7, 9, 11, 13, 15, 17, 19];
1155
+ StringAusFunc.suggestLookup = StringAusFunc.generateLookup();
1156
+
1157
+ var StringFunc = /** @class */ (function () {
1158
+ function StringFunc() {
1159
+ }
1160
+ /**
1161
+ * Up to 2 letters. For John Smith, returns JS, for Huang, Zijian, returns ZH
1162
+ * @param s
1163
+ */
1164
+ StringFunc.getAbbr = function (s) {
1165
+ if (!s) {
1166
+ return '';
1167
+ }
1168
+ var sArray = s.split(/[\s,]+/);
1169
+ var comma = s.indexOf(',') >= 0;
1170
+ if (sArray.length === 1) {
1171
+ return sArray[0][0];
1172
+ }
1173
+ return comma ? sArray[1][0] + sArray[0][0] : sArray[0][0] + sArray[1][0];
1174
+ };
1175
+ /**
1176
+ * A substring with line breaks replaced by space.
1177
+ * @param s
1178
+ * @param length
1179
+ * @returns result, or empty string if the input is empty, null or undefined
1180
+ */
1181
+ StringFunc.getOneLineDigest = function (s, length) {
1182
+ if (!s) {
1183
+ return '';
1184
+ }
1185
+ var ss = s.substring(0, length);
1186
+ var st = ss.replace(new RegExp('\n', 'g'), ' ') + ((s.length > length) ? '...' : '');
1187
+ return st.trim();
1188
+ };
1189
+ /**
1190
+ * Remove line breaks and econde with encodeURI() so the data could be saved in Azure as meta. If the string is truncated, the return will have ... suffix.
1191
+ * @param s
1192
+ * @param length
1193
+ * @returns result, or empty string if the input is empty, null or undefined
1194
+ */
1195
+ StringFunc.getOneLineDigestOfHtml = function (s, length) {
1196
+ if (!s) {
1197
+ return '';
1198
+ }
1199
+ var ss = s.substring(0, length);
1200
+ var st = ss.replace(new RegExp('\n', 'g'), ' ') + ((s.length > length) ? '...' : '');
1201
+ return encodeURI(st.trim()); //need to encode in order to save as meta in Azure.
1202
+ };
1203
+ /**
1204
+ * Pad number with zero
1205
+ * @param num
1206
+ * @param size
1207
+ * @returns
1208
+ */
1209
+ StringFunc.pad = function (num, size) {
1210
+ if (num == null) {
1211
+ return '';
1212
+ }
1213
+ var s = num + '';
1214
+ while (s.length < size) {
1215
+ s = '0' + s;
1216
+ }
1217
+ return s;
1218
+ };
1219
+ /**
1220
+ * get plain text of HTML content
1221
+ * @param s
1222
+ * @returns result. If input is empty, null, or undefined, return the same.
1223
+ */
1224
+ StringFunc.getHtmlPlainText = function (s) {
1225
+ if (!s) {
1226
+ return null;
1227
+ }
1228
+ var parser = new DOMParser();
1229
+ var html = parser.parseFromString(s, 'text/html');
1230
+ return html.body.textContent;
1231
+ };
1232
+ /**
1233
+ *
1234
+ * @param s
1235
+ * @returns result. If input is empty, null, or undefined, return the same.
1236
+ */
1237
+ StringFunc.capitalizeWords = function (s) {
1238
+ if (!s) {
1239
+ return s;
1240
+ }
1241
+ return s.replace(/(?:^|\s)\S/g, function (a) { return a.toUpperCase(); });
1242
+ };
1243
+ StringFunc.validateEmail = function (email) {
1205
1244
  if (!email) {
1206
1245
  return true;
1207
1246
  }
@@ -1209,11 +1248,26 @@
1209
1248
  return re.test(email.toLowerCase());
1210
1249
  };
1211
1250
  return StringFunc;
1212
- }());
1213
- //thanks to https://github.com/sidorares/australian-business-number/blob/0591475f5978fd122b472edcdc7efe6d96d56f26/index.js
1214
- StringFunc.acnWeights = [8, 7, 6, 5, 4, 3, 2, 1];
1215
- StringFunc.weights = [10, 1, 3, 5, 7, 9, 11, 13, 15, 17, 19];
1216
- StringFunc.suggestLookup = StringFunc.generateLookup();
1251
+ }());
1252
+
1253
+ // import { v5 as uuid } from 'uuid/v5 causes ERROR in src / app / _func / helperFunc.ts(1, 10): error TS2305: Module '"C:/VSProjects/ApsCloudTrunk/APS.WebPos.NGCli/NGSource/node_modules/@types/uuid/v5"' has no exported member 'v5'
1254
+ // https://github.com/DefinitelyTyped/DefinitelyTyped/pull/28439
1255
+ var UuidFunc = /** @class */ (function () {
1256
+ function UuidFunc() {
1257
+ }
1258
+ /**
1259
+ * 36 UUID string including 4 hyphens. MySql stores GUID as 36 bytes anyway rather than 16bytes.
1260
+ */
1261
+ UuidFunc.newUUID = function () {
1262
+ // return uuid('medilink.com.au', 'apscloud');
1263
+ return uuid.v4();
1264
+ };
1265
+ UuidFunc.newUUIDStartWith0 = function () {
1266
+ var s = uuid.v4();
1267
+ return '0000' + s.slice(4);
1268
+ };
1269
+ return UuidFunc;
1270
+ }());
1217
1271
 
1218
1272
  /*
1219
1273
  * Public API Surface of nmce-func
@@ -1227,10 +1281,12 @@
1227
1281
  exports.AuthenticationService = AuthenticationService;
1228
1282
  exports.CurrencyFunc = CurrencyFunc;
1229
1283
  exports.DateFunc = DateFunc;
1230
- exports.HelperFunc = HelperFunc;
1231
- exports.HtmlFunc = HtmlFunc;
1232
- exports.JSFunc = JSFunc;
1284
+ exports.HtmlPrintFunc = HtmlPrintFunc;
1285
+ exports.JavaScriptFunc = JavaScriptFunc;
1286
+ exports.JsonFunc = JsonFunc;
1287
+ exports.StringAusFunc = StringAusFunc;
1233
1288
  exports.StringFunc = StringFunc;
1289
+ exports.UuidFunc = UuidFunc;
1234
1290
 
1235
1291
  Object.defineProperty(exports, '__esModule', { value: true });
1236
1292