coer-elements 1.0.0

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.
package/README.md ADDED
@@ -0,0 +1 @@
1
+ # COER Elements
@@ -0,0 +1,150 @@
1
+ var __assign = (this && this.__assign) || function () {
2
+ __assign = Object.assign || function(t) {
3
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
4
+ s = arguments[i];
5
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
6
+ t[p] = s[p];
7
+ }
8
+ return t;
9
+ };
10
+ return __assign.apply(this, arguments);
11
+ };
12
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
13
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
14
+ if (ar || !(i in from)) {
15
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
16
+ ar[i] = from[i];
17
+ }
18
+ }
19
+ return to.concat(ar || Array.prototype.slice.call(from));
20
+ };
21
+ export var Tools = {
22
+ /** Returns true if the value is null or undefined, false otherwise */
23
+ IsNull: function (value) {
24
+ if (value === undefined)
25
+ return true;
26
+ if (value === null)
27
+ return true;
28
+ return false;
29
+ },
30
+ /** Returns true if the value is not null or undefined, false otherwise */
31
+ IsNotNull: function (value) {
32
+ if (value === undefined)
33
+ return false;
34
+ if (value === null)
35
+ return false;
36
+ return true;
37
+ },
38
+ /** Break reference of a object or array */
39
+ BreakReference: function (object) {
40
+ if (object === undefined)
41
+ return undefined;
42
+ if (object === null)
43
+ return null;
44
+ var OBJECT = JSON.parse(JSON.stringify(object));
45
+ return (Array.isArray(OBJECT)) ? __spreadArray([], OBJECT, true) : __assign({}, OBJECT);
46
+ },
47
+ /** Clean extra whitespaces */
48
+ CleanUpBlanks: function (text) {
49
+ if (Tools.IsNull(text))
50
+ return '';
51
+ var worlds = String(text).split(' ');
52
+ worlds = worlds.filter(function (x) { return x.length > 0; });
53
+ return worlds.join(' ');
54
+ },
55
+ /** Get properties of an object */
56
+ GetObjectProperties: function (obj) {
57
+ var properties = [];
58
+ if (Tools.IsNull(obj))
59
+ return properties;
60
+ for (var property in obj)
61
+ properties.push(String(property));
62
+ return properties;
63
+ },
64
+ /**
65
+ * Set an index and merge more arrays of the same type
66
+ * @returns A new array
67
+ * */
68
+ SetIndex: function (array) {
69
+ var args = [];
70
+ for (var _i = 1; _i < arguments.length; _i++) {
71
+ args[_i - 1] = arguments[_i];
72
+ }
73
+ var index = 0;
74
+ for (var _a = 0, args_1 = args; _a < args_1.length; _a++) {
75
+ var arg = args_1[_a];
76
+ array = Tools.BreakReference(array).concat(Tools.BreakReference(arg));
77
+ }
78
+ return Tools.BreakReference(array).map(function (item) { return Object.assign({ index: index++ }, item); });
79
+ },
80
+ /** Set First Char To Lower */
81
+ FirstCharToLower: function (text) {
82
+ if (Tools.IsNull(text))
83
+ return '';
84
+ var textArray = [];
85
+ for (var i = 0; i < text.length; i++) {
86
+ if (i === 0)
87
+ textArray.push(text[i].toLowerCase());
88
+ else
89
+ textArray.push(text[i]);
90
+ }
91
+ return textArray.join('');
92
+ },
93
+ /** Set First Char To Upper */
94
+ FirstCharToUpper: function (text) {
95
+ if (Tools.IsNull(text))
96
+ return '';
97
+ var textArray = [];
98
+ for (var i = 0; i < text.length; i++) {
99
+ if (i === 0)
100
+ textArray.push(text[i].toUpperCase());
101
+ else
102
+ textArray.push(text[i]);
103
+ }
104
+ return textArray.join('');
105
+ },
106
+ /**
107
+ * Sort an array in ascending order by property
108
+ * @returns A new array
109
+ * */
110
+ SortBy: function (array, property, propertyType) {
111
+ if (propertyType === void 0) { propertyType = 'string'; }
112
+ switch (propertyType) {
113
+ case 'string': {
114
+ return __spreadArray([], array, true).sort(function (x, y) {
115
+ if (String(x[property]).toUpperCase().trim() < String(y[property]).toUpperCase().trim())
116
+ return -1;
117
+ else if (String(x[property]).toUpperCase().trim() > String(y[property]).toUpperCase().trim())
118
+ return 1;
119
+ else
120
+ return 0;
121
+ });
122
+ }
123
+ case 'number': {
124
+ return array.sort(function (x, y) { return Number(x[property] - Number(y[property])); });
125
+ }
126
+ }
127
+ },
128
+ /**
129
+ * Sort an array in descending order by property
130
+ * @returns A new array
131
+ * */
132
+ SortByDesc: function (array, property, propertyType) {
133
+ if (propertyType === void 0) { propertyType = 'string'; }
134
+ switch (propertyType) {
135
+ case 'string': {
136
+ return array.sort(function (x, y) {
137
+ if (String(x[property]).toUpperCase().trim() < String(y[property]).toUpperCase().trim())
138
+ return 1;
139
+ else if (String(x[property]).toUpperCase().trim() > String(y[property]).toUpperCase().trim())
140
+ return -1;
141
+ else
142
+ return 0;
143
+ });
144
+ }
145
+ case 'number': {
146
+ return array.sort(function (x, y) { return Number(Number(y[property])) - x[property]; });
147
+ }
148
+ }
149
+ }
150
+ };
@@ -0,0 +1,153 @@
1
+ "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
13
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
14
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
15
+ if (ar || !(i in from)) {
16
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
17
+ ar[i] = from[i];
18
+ }
19
+ }
20
+ return to.concat(ar || Array.prototype.slice.call(from));
21
+ };
22
+ Object.defineProperty(exports, "__esModule", { value: true });
23
+ exports.Tools = void 0;
24
+ exports.Tools = {
25
+ /** Returns true if the value is null or undefined, false otherwise */
26
+ IsNull: function (value) {
27
+ if (value === undefined)
28
+ return true;
29
+ if (value === null)
30
+ return true;
31
+ return false;
32
+ },
33
+ /** Returns true if the value is not null or undefined, false otherwise */
34
+ IsNotNull: function (value) {
35
+ if (value === undefined)
36
+ return false;
37
+ if (value === null)
38
+ return false;
39
+ return true;
40
+ },
41
+ /** Break reference of a object or array */
42
+ BreakReference: function (object) {
43
+ if (object === undefined)
44
+ return undefined;
45
+ if (object === null)
46
+ return null;
47
+ var OBJECT = JSON.parse(JSON.stringify(object));
48
+ return (Array.isArray(OBJECT)) ? __spreadArray([], OBJECT, true) : __assign({}, OBJECT);
49
+ },
50
+ /** Clean extra whitespaces */
51
+ CleanUpBlanks: function (text) {
52
+ if (exports.Tools.IsNull(text))
53
+ return '';
54
+ var worlds = String(text).split(' ');
55
+ worlds = worlds.filter(function (x) { return x.length > 0; });
56
+ return worlds.join(' ');
57
+ },
58
+ /** Get properties of an object */
59
+ GetObjectProperties: function (obj) {
60
+ var properties = [];
61
+ if (exports.Tools.IsNull(obj))
62
+ return properties;
63
+ for (var property in obj)
64
+ properties.push(String(property));
65
+ return properties;
66
+ },
67
+ /**
68
+ * Set an index and merge more arrays of the same type
69
+ * @returns A new array
70
+ * */
71
+ SetIndex: function (array) {
72
+ var args = [];
73
+ for (var _i = 1; _i < arguments.length; _i++) {
74
+ args[_i - 1] = arguments[_i];
75
+ }
76
+ var index = 0;
77
+ for (var _a = 0, args_1 = args; _a < args_1.length; _a++) {
78
+ var arg = args_1[_a];
79
+ array = exports.Tools.BreakReference(array).concat(exports.Tools.BreakReference(arg));
80
+ }
81
+ return exports.Tools.BreakReference(array).map(function (item) { return Object.assign({ index: index++ }, item); });
82
+ },
83
+ /** Set First Char To Lower */
84
+ FirstCharToLower: function (text) {
85
+ if (exports.Tools.IsNull(text))
86
+ return '';
87
+ var textArray = [];
88
+ for (var i = 0; i < text.length; i++) {
89
+ if (i === 0)
90
+ textArray.push(text[i].toLowerCase());
91
+ else
92
+ textArray.push(text[i]);
93
+ }
94
+ return textArray.join('');
95
+ },
96
+ /** Set First Char To Upper */
97
+ FirstCharToUpper: function (text) {
98
+ if (exports.Tools.IsNull(text))
99
+ return '';
100
+ var textArray = [];
101
+ for (var i = 0; i < text.length; i++) {
102
+ if (i === 0)
103
+ textArray.push(text[i].toUpperCase());
104
+ else
105
+ textArray.push(text[i]);
106
+ }
107
+ return textArray.join('');
108
+ },
109
+ /**
110
+ * Sort an array in ascending order by property
111
+ * @returns A new array
112
+ * */
113
+ SortBy: function (array, property, propertyType) {
114
+ if (propertyType === void 0) { propertyType = 'string'; }
115
+ switch (propertyType) {
116
+ case 'string': {
117
+ return __spreadArray([], array, true).sort(function (x, y) {
118
+ if (String(x[property]).toUpperCase().trim() < String(y[property]).toUpperCase().trim())
119
+ return -1;
120
+ else if (String(x[property]).toUpperCase().trim() > String(y[property]).toUpperCase().trim())
121
+ return 1;
122
+ else
123
+ return 0;
124
+ });
125
+ }
126
+ case 'number': {
127
+ return array.sort(function (x, y) { return Number(x[property] - Number(y[property])); });
128
+ }
129
+ }
130
+ },
131
+ /**
132
+ * Sort an array in descending order by property
133
+ * @returns A new array
134
+ * */
135
+ SortByDesc: function (array, property, propertyType) {
136
+ if (propertyType === void 0) { propertyType = 'string'; }
137
+ switch (propertyType) {
138
+ case 'string': {
139
+ return array.sort(function (x, y) {
140
+ if (String(x[property]).toUpperCase().trim() < String(y[property]).toUpperCase().trim())
141
+ return 1;
142
+ else if (String(x[property]).toUpperCase().trim() > String(y[property]).toUpperCase().trim())
143
+ return -1;
144
+ else
145
+ return 0;
146
+ });
147
+ }
148
+ case 'number': {
149
+ return array.sort(function (x, y) { return Number(Number(y[property])) - x[property]; });
150
+ }
151
+ }
152
+ }
153
+ };
package/package.json ADDED
@@ -0,0 +1,24 @@
1
+ {
2
+ "name": "coer-elements",
3
+ "version": "1.0.0",
4
+ "author": "Christian Omar Escamilla Rodríguez",
5
+ "keywords": ["coer", "coer-system", "coer system"],
6
+ "description": "",
7
+ "license": "MIT",
8
+ "main": "dist_node/index.js",
9
+ "browser": "dist_browser/index.js",
10
+ "homepage": "https://github.com/Chris19910804/coer-elements",
11
+ "repository": {
12
+ "type": "git",
13
+ "url": "https://github.com/Chris19910804/coer-elements"
14
+ },
15
+ "scripts": {
16
+ "build-browser": "tsc src/index.ts --outDir dist-browser --module ES6",
17
+ "build-node": "tsc src/index.ts --outDir dist_node",
18
+ "build": "npm run build-browser & npm run build_node",
19
+ "publish": "npm publish --access public"
20
+ },
21
+ "devDependencies": {
22
+ "typescript": "^5.5.4"
23
+ }
24
+ }
package/src/index.ts ADDED
@@ -0,0 +1,127 @@
1
+ export const Tools = {
2
+ /** Returns true if the value is null or undefined, false otherwise */
3
+ IsNull: (value: any): boolean => {
4
+ if (value === undefined) return true;
5
+ if (value === null) return true;
6
+ return false;
7
+ },
8
+
9
+
10
+ /** Returns true if the value is not null or undefined, false otherwise */
11
+ IsNotNull: (value: any): boolean => {
12
+ if (value === undefined) return false;
13
+ if (value === null) return false;
14
+ return true;
15
+ },
16
+
17
+
18
+ /** Break reference of a object or array */
19
+ BreakReference: <T>(object: T): T => {
20
+ if (object === undefined) return undefined as T;
21
+ if (object === null) return null as T;
22
+ const OBJECT = JSON.parse(JSON.stringify(object))
23
+ return (Array.isArray(OBJECT)) ? [...OBJECT] : { ...OBJECT }
24
+ },
25
+
26
+
27
+ /** Clean extra whitespaces */
28
+ CleanUpBlanks: (text: string | number): string => {
29
+ if(Tools.IsNull(text)) return '';
30
+ let worlds: string[] = String(text).split(' ');
31
+ worlds = worlds.filter(x => x.length > 0);
32
+ return worlds.join(' ');
33
+ },
34
+
35
+
36
+ /** Get properties of an object */
37
+ GetObjectProperties: <T>(obj: T | null | undefined): string[] => {
38
+ const properties: string[] = [];
39
+ if(Tools.IsNull(obj)) return properties;
40
+ for(const property in obj) properties.push(String(property));
41
+ return properties;
42
+ },
43
+
44
+
45
+ /**
46
+ * Set an index and merge more arrays of the same type
47
+ * @returns A new array
48
+ * */
49
+ SetIndex: <T>(array: T[], ...args: T[][]): T[] => {
50
+ let index = 0;
51
+ for (const arg of args) {
52
+ array = Tools.BreakReference(array).concat(Tools.BreakReference(arg));
53
+ }
54
+
55
+ return Tools.BreakReference(array).map(item => Object.assign({ index: index++ }, item));
56
+ },
57
+
58
+
59
+ /** Set First Char To Lower */
60
+ FirstCharToLower: (text: string | null | undefined): string => {
61
+ if (Tools.IsNull(text)) return '';
62
+
63
+ const textArray: string[] = [];
64
+ for(let i = 0; i < text!.length; i++) {
65
+ if(i === 0) textArray.push(text![i].toLowerCase());
66
+ else textArray.push(text![i]);
67
+ }
68
+
69
+ return textArray.join('');
70
+ },
71
+
72
+
73
+ /** Set First Char To Upper */
74
+ FirstCharToUpper: (text: string | null | undefined): string => {
75
+ if (Tools.IsNull(text)) return '';
76
+
77
+ const textArray: string[] = [];
78
+ for(let i = 0; i < text!.length; i++) {
79
+ if(i === 0) textArray.push(text![i].toUpperCase());
80
+ else textArray.push(text![i]);
81
+ }
82
+
83
+ return textArray.join('');
84
+ },
85
+
86
+
87
+ /**
88
+ * Sort an array in ascending order by property
89
+ * @returns A new array
90
+ * */
91
+ SortBy: <T>(array: T[], property: string, propertyType: 'string' | 'number' = 'string'): T[] => {
92
+ switch (propertyType) {
93
+ case 'string': {
94
+ return [...array].sort((x: any, y: any) => {
95
+ if (String(x[property]).toUpperCase().trim() < String(y[property]).toUpperCase().trim()) return -1;
96
+ else if (String(x[property]).toUpperCase().trim() > String(y[property]).toUpperCase().trim()) return 1;
97
+ else return 0;
98
+ });
99
+ }
100
+
101
+ case 'number': {
102
+ return array.sort((x: any, y: any) => Number(x[property] - Number(y[property])));
103
+ }
104
+ }
105
+ },
106
+
107
+
108
+ /**
109
+ * Sort an array in descending order by property
110
+ * @returns A new array
111
+ * */
112
+ SortByDesc: <T>(array: T[], property: string, propertyType: 'string' | 'number' = 'string'): T[] => {
113
+ switch (propertyType) {
114
+ case 'string': {
115
+ return array.sort((x: any, y: any) => {
116
+ if (String(x[property]).toUpperCase().trim() < String(y[property]).toUpperCase().trim()) return 1;
117
+ else if (String(x[property]).toUpperCase().trim() > String(y[property]).toUpperCase().trim()) return -1;
118
+ else return 0;
119
+ });
120
+ }
121
+
122
+ case 'number': {
123
+ return array.sort((x: any, y: any) => Number(Number(y[property])) - x[property]);
124
+ }
125
+ }
126
+ }
127
+ };