@verisoft/core 17.3.0 → 18.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/package.json CHANGED
@@ -1,12 +1,11 @@
1
- {
2
- "name": "@verisoft/core",
3
- "version": "17.3.0",
4
- "peerDependencies": {
5
- "@angular/common": "^17.3.0",
6
- "@angular/core": "^17.3.0",
7
- "rxjs": "~7.8.0",
8
- "moment": "^2.30.1"
9
- },
10
- "dependencies": {},
11
- "sideEffects": false
12
- }
1
+ {
2
+ "name": "@verisoft/core",
3
+ "version": "18.0.0",
4
+ "peerDependencies": {
5
+ "@angular/common": "^18.2.8",
6
+ "@angular/core": "^18.2.8",
7
+ "moment": "^2.30.1",
8
+ "rxjs": "~7.8.0"
9
+ },
10
+ "sideEffects": false
11
+ }
package/src/index.ts CHANGED
@@ -4,7 +4,4 @@ export * from './lib/models/lazy-load.model';
4
4
 
5
5
  export * from './lib/services/base-http.service';
6
6
 
7
- export * from './lib/utils/clear.utils';
8
- export * from './lib/utils/keyOrFn.utils';
9
- export * from './lib/utils/array.utils';
10
- export * from './lib/utils/data.utils';
7
+ export * from './lib/utils';
@@ -101,8 +101,4 @@ export abstract class BaseHttpService<T, TKey = number> {
101
101
  }
102
102
  return null;
103
103
  }
104
-
105
- private printNevim() {
106
- console.log("Hello world!")
107
- }
108
104
  }
@@ -0,0 +1,5 @@
1
+ export * from './clear.utils';
2
+ export * from './keyOrFn.utils';
3
+ export * from './array.utils';
4
+ export * from './data.utils';
5
+ export * from './object.utils';
@@ -0,0 +1,34 @@
1
+ import { sortBy } from './object.utils';
2
+
3
+ describe('object.utils', () => {
4
+ describe('sortBy', () => {
5
+ const items = [
6
+ { name: undefined, age: 60 },
7
+ { name: 'Martin', age: 40 },
8
+ { name: 'Alena', age: 28 },
9
+ { name: 'Karel', age: 15 },
10
+ ];
11
+
12
+ test('Should sort items by name ascending.', () => {
13
+ const sortedItems = sortBy(items, (x) => x.name);
14
+
15
+ expect(items).not.toBe(sortedItems);
16
+ expect(sortedItems).toBeDefined();
17
+ expect(sortedItems?.[0].name).toBeUndefined();
18
+ expect(sortedItems?.[1].name).toBe('Alena');
19
+ expect(sortedItems?.[2].name).toBe('Karel');
20
+ expect(sortedItems?.[3].name).toBe('Martin');
21
+ });
22
+
23
+ test('Should sort items by name descending.', () => {
24
+ const sortedItems = sortBy(items, (x) => x.name, false);
25
+
26
+ expect(items).not.toBe(sortedItems);
27
+ expect(sortedItems).toBeDefined();
28
+ expect(sortedItems?.[0].name).toBe('Martin');
29
+ expect(sortedItems?.[1].name).toBe('Karel');
30
+ expect(sortedItems?.[2].name).toBe('Alena');
31
+ expect(sortedItems?.[3].name).toBeUndefined();
32
+ });
33
+ });
34
+ });
@@ -0,0 +1,31 @@
1
+ export function sortBy<TEntity, TProperty>(
2
+ items: TEntity[],
3
+ selector: (item: TEntity) => TProperty,
4
+ ascending = true
5
+ ): TEntity[] {
6
+ return [...items].sort((item, other) => {
7
+ const value = selector(item);
8
+ const otherValue = selector(other);
9
+ const direction = ascending ? 1 : -1;
10
+ if (value == undefined && other == undefined) {
11
+ return 0;
12
+ }
13
+
14
+ if (value == undefined) {
15
+ return -1 * direction;
16
+ }
17
+ if (otherValue == undefined) {
18
+ return 1 * direction;
19
+ }
20
+
21
+ if (value < otherValue) {
22
+ return -1 * direction;
23
+ }
24
+
25
+ if (value > otherValue) {
26
+ return 1 * direction;
27
+ }
28
+
29
+ return 0;
30
+ });
31
+ }