@webtypen/webframez-core 0.0.22 → 0.0.23

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.
@@ -0,0 +1,6 @@
1
+ declare class NumericFunctionsFacade {
2
+ numberFormat(number: number, decimals?: number, dec_point?: string, thousands_sep?: string): string;
3
+ bytesFormat(bytes: number): string;
4
+ }
5
+ export declare const NumericFunctions: NumericFunctionsFacade;
6
+ export {};
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.NumericFunctions = void 0;
4
+ class NumericFunctionsFacade {
5
+ numberFormat(number, decimals, dec_point, thousands_sep) {
6
+ if (decimals === undefined) {
7
+ decimals = 2;
8
+ }
9
+ if (dec_point === undefined) {
10
+ dec_point = ",";
11
+ }
12
+ if (thousands_sep === undefined) {
13
+ thousands_sep = ".";
14
+ }
15
+ number = parseFloat((number + "").replace(/[^0-9+\-Ee.]/g, ""));
16
+ let n = !isFinite(+number) ? 0 : +number, prec = !isFinite(+decimals) ? 0 : Math.abs(decimals), sep = typeof thousands_sep === "undefined" ? "," : thousands_sep, dec = typeof dec_point === "undefined" ? "." : dec_point, s = "", toFixedFix = function (n, prec) {
17
+ var k = Math.pow(10, prec);
18
+ return "" + Math.round(n * k) / k;
19
+ };
20
+ const sArr = (prec ? toFixedFix(n, prec) : "" + Math.round(n)).split(".");
21
+ if (sArr[0].length > 3) {
22
+ sArr[0] = sArr[0].replace(/\B(?=(?:\d{3})+(?!\d))/g, sep);
23
+ }
24
+ if ((s[1] || "").length < prec) {
25
+ sArr[1] = sArr[1] || "";
26
+ sArr[1] += new Array(prec - sArr[1].length + 1).join("0");
27
+ }
28
+ return sArr.join(dec);
29
+ }
30
+ bytesFormat(bytes) {
31
+ const sizes = ["Bytes", "KB", "MB", "GB", "TB"];
32
+ if (bytes == 0) {
33
+ return "n/a";
34
+ }
35
+ const i = parseInt(Math.floor(Math.log(bytes) / Math.log(1024)).toString());
36
+ if (i == 0) {
37
+ return bytes + " " + sizes[i];
38
+ }
39
+ return (bytes / Math.pow(1024, i)).toFixed(1) + " " + sizes[i];
40
+ }
41
+ }
42
+ exports.NumericFunctions = new NumericFunctionsFacade();
@@ -0,0 +1,7 @@
1
+ declare class StringFunctionsFacade {
2
+ slug(string: string): string;
3
+ random(length: number): string;
4
+ nl2br(str: string, replaceMode?: boolean, isXhtml?: boolean): string;
5
+ }
6
+ export declare const StringFunctions: StringFunctionsFacade;
7
+ export {};
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.StringFunctions = void 0;
4
+ class StringFunctionsFacade {
5
+ slug(string) {
6
+ string = (string + "").toLowerCase();
7
+ string = string.replace(new RegExp(" ", "g"), " ");
8
+ string = string.replace(new RegExp(" ", "g"), " ");
9
+ string = string.replace(new RegExp(" ", "g"), "-");
10
+ string = string.replace(new RegExp("_", "g"), "-");
11
+ const replacements = {
12
+ Ä: "AE",
13
+ ä: "ae",
14
+ Ö: "OE",
15
+ ö: "oe",
16
+ Ü: "UE",
17
+ ü: "ue",
18
+ Đ: "D",
19
+ đ: "d",
20
+ "&": "and",
21
+ "€": "euro",
22
+ "<": "less",
23
+ ">": "greater",
24
+ };
25
+ for (let i in replacements) {
26
+ string = string.replace(new RegExp(i, "g"), replacements[i]);
27
+ }
28
+ return string.replace(/[^a-zA-Z\- ]/g, "").trim();
29
+ }
30
+ random(length) {
31
+ const result = [];
32
+ const chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
33
+ for (let i = 0; i < length; i++) {
34
+ result.push(chars.charAt(Math.floor(Math.random() * chars.length)));
35
+ }
36
+ return result.join("");
37
+ }
38
+ nl2br(str, replaceMode, isXhtml) {
39
+ const breakTag = isXhtml ? "<br />" : "<br>";
40
+ const replaceStr = replaceMode ? "$1" + breakTag : "$1" + breakTag + "$2";
41
+ return (str + "").replace(/([^>\r\n]?)(\r\n|\n\r|\r|\n)/g, replaceStr);
42
+ }
43
+ }
44
+ exports.StringFunctions = new StringFunctionsFacade();
package/lib/index.d.ts CHANGED
@@ -1,4 +1,6 @@
1
1
  export * from "./Config";
2
+ export * from "./Functions/StringFunctions";
3
+ export * from "./Functions/NumericFunctions";
2
4
  export * from "./BaseKernelWeb";
3
5
  export * from "./BaseKernelConsole";
4
6
  export * from "./Controller/Controller";
package/lib/index.js CHANGED
@@ -15,6 +15,8 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./Config"), exports);
18
+ __exportStar(require("./Functions/StringFunctions"), exports);
19
+ __exportStar(require("./Functions/NumericFunctions"), exports);
18
20
  __exportStar(require("./BaseKernelWeb"), exports);
19
21
  __exportStar(require("./BaseKernelConsole"), exports);
20
22
  __exportStar(require("./Controller/Controller"), exports);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webtypen/webframez-core",
3
- "version": "0.0.22",
3
+ "version": "0.0.23",
4
4
  "description": "The core package of the typescript based webframez (web-framework) by webtypen.de",
5
5
  "homepage": "https://webtypen.de/",
6
6
  "license": "MIT",
@@ -0,0 +1,57 @@
1
+ class NumericFunctionsFacade {
2
+ numberFormat(
3
+ number: number,
4
+ decimals?: number,
5
+ dec_point?: string,
6
+ thousands_sep?: string
7
+ ) {
8
+ if (decimals === undefined) {
9
+ decimals = 2;
10
+ }
11
+
12
+ if (dec_point === undefined) {
13
+ dec_point = ",";
14
+ }
15
+
16
+ if (thousands_sep === undefined) {
17
+ thousands_sep = ".";
18
+ }
19
+
20
+ number = parseFloat((number + "").replace(/[^0-9+\-Ee.]/g, ""));
21
+ let n = !isFinite(+number) ? 0 : +number,
22
+ prec = !isFinite(+decimals) ? 0 : Math.abs(decimals),
23
+ sep = typeof thousands_sep === "undefined" ? "," : thousands_sep,
24
+ dec = typeof dec_point === "undefined" ? "." : dec_point,
25
+ s = "",
26
+ toFixedFix = function (n: number, prec: number) {
27
+ var k = Math.pow(10, prec);
28
+ return "" + Math.round(n * k) / k;
29
+ };
30
+
31
+ const sArr = (prec ? toFixedFix(n, prec) : "" + Math.round(n)).split(".");
32
+ if (sArr[0].length > 3) {
33
+ sArr[0] = sArr[0].replace(/\B(?=(?:\d{3})+(?!\d))/g, sep);
34
+ }
35
+ if ((s[1] || "").length < prec) {
36
+ sArr[1] = sArr[1] || "";
37
+ sArr[1] += new Array(prec - sArr[1].length + 1).join("0");
38
+ }
39
+ return sArr.join(dec);
40
+ }
41
+
42
+ bytesFormat(bytes: number) {
43
+ const sizes = ["Bytes", "KB", "MB", "GB", "TB"];
44
+
45
+ if (bytes == 0) {
46
+ return "n/a";
47
+ }
48
+
49
+ const i = parseInt(Math.floor(Math.log(bytes) / Math.log(1024)).toString());
50
+ if (i == 0) {
51
+ return bytes + " " + sizes[i];
52
+ }
53
+ return (bytes / Math.pow(1024, i)).toFixed(1) + " " + sizes[i];
54
+ }
55
+ }
56
+
57
+ export const NumericFunctions = new NumericFunctionsFacade();
@@ -0,0 +1,47 @@
1
+ class StringFunctionsFacade {
2
+ slug(string: string) {
3
+ string = (string + "").toLowerCase();
4
+ string = string.replace(new RegExp(" ", "g"), " ");
5
+ string = string.replace(new RegExp(" ", "g"), " ");
6
+ string = string.replace(new RegExp(" ", "g"), "-");
7
+ string = string.replace(new RegExp("_", "g"), "-");
8
+
9
+ const replacements: { [key: string]: string } = {
10
+ Ä: "AE",
11
+ ä: "ae",
12
+ Ö: "OE",
13
+ ö: "oe",
14
+ Ü: "UE",
15
+ ü: "ue",
16
+ Đ: "D",
17
+ đ: "d",
18
+ "&": "and",
19
+ "€": "euro",
20
+ "<": "less",
21
+ ">": "greater",
22
+ };
23
+ for (let i in replacements) {
24
+ string = string.replace(new RegExp(i, "g"), replacements[i]);
25
+ }
26
+
27
+ return string.replace(/[^a-zA-Z\- ]/g, "").trim();
28
+ }
29
+
30
+ random(length: number) {
31
+ const result = [];
32
+ const chars =
33
+ "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
34
+ for (let i = 0; i < length; i++) {
35
+ result.push(chars.charAt(Math.floor(Math.random() * chars.length)));
36
+ }
37
+ return result.join("");
38
+ }
39
+
40
+ nl2br(str: string, replaceMode?: boolean, isXhtml?: boolean) {
41
+ const breakTag = isXhtml ? "<br />" : "<br>";
42
+ const replaceStr = replaceMode ? "$1" + breakTag : "$1" + breakTag + "$2";
43
+ return (str + "").replace(/([^>\r\n]?)(\r\n|\n\r|\r|\n)/g, replaceStr);
44
+ }
45
+ }
46
+
47
+ export const StringFunctions = new StringFunctionsFacade();
package/src/index.ts CHANGED
@@ -1,4 +1,6 @@
1
1
  export * from "./Config";
2
+ export * from "./Functions/StringFunctions";
3
+ export * from "./Functions/NumericFunctions";
2
4
  export * from "./BaseKernelWeb";
3
5
  export * from "./BaseKernelConsole";
4
6
  export * from "./Controller/Controller";