@furystack/utils 3.1.8 → 4.0.1

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.
Files changed (107) hide show
  1. package/{dist → esm}/debounce.js +1 -5
  2. package/esm/debounce.js.map +1 -0
  3. package/{dist → esm}/deep-merge.js +2 -7
  4. package/esm/deep-merge.js.map +1 -0
  5. package/{dist → esm}/disposable.js +2 -9
  6. package/esm/disposable.js.map +1 -0
  7. package/esm/index.js +11 -0
  8. package/esm/index.js.map +1 -0
  9. package/{dist → esm}/observable-value.js +5 -16
  10. package/esm/observable-value.js.map +1 -0
  11. package/{dist → esm}/path-helper.js +1 -10
  12. package/esm/path-helper.js.map +1 -0
  13. package/esm/sleep-async.js +8 -0
  14. package/esm/sleep-async.js.map +1 -0
  15. package/esm/sort-by.js +15 -0
  16. package/esm/sort-by.js.map +1 -0
  17. package/{dist → esm}/trace.js +5 -9
  18. package/esm/trace.js.map +1 -0
  19. package/esm/tuple.js +7 -0
  20. package/esm/tuple.js.map +1 -0
  21. package/{dist → esm}/value-observer.js +2 -7
  22. package/esm/value-observer.js.map +1 -0
  23. package/package.json +22 -9
  24. package/src/debounce.spec.ts +20 -17
  25. package/src/deep-merge.spec.ts +1 -0
  26. package/src/deep-merge.ts +0 -1
  27. package/src/disposable.spec.ts +23 -15
  28. package/src/disposable.ts +0 -2
  29. package/src/observable-value.spec.ts +36 -19
  30. package/src/observable-value.ts +1 -7
  31. package/src/path-helper.spec.ts +1 -0
  32. package/src/path-helper.ts +0 -5
  33. package/src/sleep-async.spec.ts +1 -0
  34. package/src/sleep-async.ts +0 -1
  35. package/src/sort-by.spec.ts +1 -0
  36. package/src/trace.spec.ts +48 -26
  37. package/src/trace.ts +0 -1
  38. package/src/tuple.spec.ts +1 -0
  39. package/src/tuple.ts +0 -1
  40. package/src/value-observer.ts +1 -2
  41. package/types/deep-merge.d.ts +0 -1
  42. package/types/deep-merge.d.ts.map +1 -1
  43. package/types/disposable.d.ts +0 -2
  44. package/types/disposable.d.ts.map +1 -1
  45. package/types/observable-value.d.ts +1 -7
  46. package/types/observable-value.d.ts.map +1 -1
  47. package/types/path-helper.d.ts +0 -5
  48. package/types/path-helper.d.ts.map +1 -1
  49. package/types/sleep-async.d.ts +0 -1
  50. package/types/sleep-async.d.ts.map +1 -1
  51. package/types/trace.d.ts +0 -1
  52. package/types/trace.d.ts.map +1 -1
  53. package/types/tuple.d.ts +0 -1
  54. package/types/tuple.d.ts.map +1 -1
  55. package/types/value-observer.d.ts +1 -2
  56. package/types/value-observer.d.ts.map +1 -1
  57. package/dist/debounce.js.map +0 -1
  58. package/dist/debounce.spec.js +0 -40
  59. package/dist/debounce.spec.js.map +0 -1
  60. package/dist/deep-merge.js.map +0 -1
  61. package/dist/deep-merge.spec.js +0 -31
  62. package/dist/deep-merge.spec.js.map +0 -1
  63. package/dist/disposable.js.map +0 -1
  64. package/dist/disposable.spec.js +0 -112
  65. package/dist/disposable.spec.js.map +0 -1
  66. package/dist/index.js +0 -27
  67. package/dist/index.js.map +0 -1
  68. package/dist/observable-value.js.map +0 -1
  69. package/dist/observable-value.spec.js +0 -116
  70. package/dist/observable-value.spec.js.map +0 -1
  71. package/dist/path-helper.js.map +0 -1
  72. package/dist/path-helper.spec.js +0 -62
  73. package/dist/path-helper.spec.js.map +0 -1
  74. package/dist/sleep-async.js +0 -13
  75. package/dist/sleep-async.js.map +0 -1
  76. package/dist/sleep-async.spec.js +0 -16
  77. package/dist/sleep-async.spec.js.map +0 -1
  78. package/dist/sort-by.js +0 -19
  79. package/dist/sort-by.js.map +0 -1
  80. package/dist/sort-by.spec.js +0 -22
  81. package/dist/sort-by.spec.js.map +0 -1
  82. package/dist/trace.js.map +0 -1
  83. package/dist/trace.spec.js +0 -169
  84. package/dist/trace.spec.js.map +0 -1
  85. package/dist/tuple.js +0 -12
  86. package/dist/tuple.js.map +0 -1
  87. package/dist/tuple.spec.js +0 -9
  88. package/dist/tuple.spec.js.map +0 -1
  89. package/dist/value-observer.js.map +0 -1
  90. package/types/debounce.spec.d.ts +0 -5
  91. package/types/debounce.spec.d.ts.map +0 -1
  92. package/types/deep-merge.spec.d.ts +0 -2
  93. package/types/deep-merge.spec.d.ts.map +0 -1
  94. package/types/disposable.spec.d.ts +0 -22
  95. package/types/disposable.spec.d.ts.map +0 -1
  96. package/types/observable-value.spec.d.ts +0 -5
  97. package/types/observable-value.spec.d.ts.map +0 -1
  98. package/types/path-helper.spec.d.ts +0 -5
  99. package/types/path-helper.spec.d.ts.map +0 -1
  100. package/types/sleep-async.spec.d.ts +0 -5
  101. package/types/sleep-async.spec.d.ts.map +0 -1
  102. package/types/sort-by.spec.d.ts +0 -2
  103. package/types/sort-by.spec.d.ts.map +0 -1
  104. package/types/trace.spec.d.ts +0 -2
  105. package/types/trace.spec.d.ts.map +0 -1
  106. package/types/tuple.spec.d.ts +0 -2
  107. package/types/tuple.spec.d.ts.map +0 -1
@@ -1,12 +1,9 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.debounce = void 0;
4
1
  /**
5
2
  * @param method The method that should be debounced
6
3
  * @param debounceMs The timeout in millisecs
7
4
  * @returns a method that wraps the original one with an async debounce
8
5
  */
9
- const debounce = (method, debounceMs = 250) => {
6
+ export const debounce = (method, debounceMs = 250) => {
10
7
  let timeout;
11
8
  return ((...args) => {
12
9
  if (timeout) {
@@ -19,5 +16,4 @@ const debounce = (method, debounceMs = 250) => {
19
16
  }, debounceMs);
20
17
  });
21
18
  };
22
- exports.debounce = debounce;
23
19
  //# sourceMappingURL=debounce.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"debounce.js","sourceRoot":"","sources":["../src/debounce.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAG,CAAoC,MAAoC,EAAE,UAAU,GAAG,GAAG,EAAE,EAAE;IACpH,IAAI,OAAkD,CAAA;IACtD,OAAO,CAAC,CAAC,GAAG,IAAW,EAAE,EAAE;QACzB,IAAI,OAAO,EAAE;YACX,YAAY,CAAC,OAAO,CAAC,CAAA;SACtB;QACD,OAAO,GAAG,UAAU,CAAC,GAAG,EAAE;YACxB,MAAM,CAAC,GAAG,IAAI,CAAC,CAAA;YACf,OAAO,IAAI,YAAY,CAAC,OAAO,CAAC,CAAA;YAChC,OAAO,GAAG,SAAS,CAAA;QACrB,CAAC,EAAE,UAAU,CAAC,CAAA;IAChB,CAAC,CAAiC,CAAA;AACpC,CAAC,CAAA"}
@@ -1,14 +1,10 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.deepMerge = void 0;
4
1
  /**
5
2
  * Deep merge two objects.
6
- *
7
3
  * @param target The source object to be merged
8
4
  * @param sources The source objects
9
5
  * @returns A new instance with the merged values
10
6
  */
11
- const deepMerge = (target, ...sources) => {
7
+ export const deepMerge = (target, ...sources) => {
12
8
  if (!sources.length) {
13
9
  return target;
14
10
  }
@@ -20,7 +16,7 @@ const deepMerge = (target, ...sources) => {
20
16
  const keys = Object.keys(source);
21
17
  for (const key of keys) {
22
18
  if (!(source[key] instanceof Array) && typeof source[key] === 'object' && typeof target[key] === 'object') {
23
- merged[key] = (0, exports.deepMerge)(target[key], source[key]);
19
+ merged[key] = deepMerge(target[key], source[key]);
24
20
  }
25
21
  else if (source[key] !== undefined) {
26
22
  ;
@@ -30,5 +26,4 @@ const deepMerge = (target, ...sources) => {
30
26
  }
31
27
  return merged;
32
28
  };
33
- exports.deepMerge = deepMerge;
34
29
  //# sourceMappingURL=deep-merge.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"deep-merge.js","sourceRoot":"","sources":["../src/deep-merge.ts"],"names":[],"mappings":"AAKA;;;;;GAKG;AACH,MAAM,CAAC,MAAM,SAAS,GAAG,CAAI,MAAS,EAAE,GAAG,OAA0C,EAAE,EAAE;IACvF,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE;QACnB,OAAO,MAAM,CAAA;KACd;IACD,MAAM,MAAM,GAAG,EAAE,GAAG,MAAM,EAAE,CAAA;IAC5B,KAAK,MAAM,MAAM,IAAI,OAAO,EAAE;QAC5B,IAAI,CAAC,MAAM,EAAE;YACX,SAAQ;SACT;QACD,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,MAAM,CAAmB,CAAA;QAClD,KAAK,MAAM,GAAG,IAAI,IAAI,EAAE;YACtB,IAAI,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,YAAY,KAAK,CAAC,IAAI,OAAO,MAAM,CAAC,GAAG,CAAC,KAAK,QAAQ,IAAI,OAAO,MAAM,CAAC,GAAG,CAAC,KAAK,QAAQ,EAAE;gBACzG,MAAM,CAAC,GAAG,CAAC,GAAG,SAAS,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC,GAAG,CAAC,CAAC,CAAA;aAClD;iBAAM,IAAI,MAAM,CAAC,GAAG,CAAC,KAAK,SAAS,EAAE;gBACpC,CAAC;gBAAC,MAAM,CAAC,GAAG,CAAS,GAAG,MAAM,CAAC,GAAG,CAAC,CAAA;aACpC;SACF;KACF;IACD,OAAO,MAAM,CAAA;AACf,CAAC,CAAA"}
@@ -1,4 +1,3 @@
1
- "use strict";
2
1
  /**
3
2
  *
4
3
  * You can implement *IDisposable* resources and use them with a *using()* or *usingAsync()* syntax.
@@ -23,16 +22,13 @@
23
22
  * ```
24
23
  */
25
24
  /** */
26
- Object.defineProperty(exports, "__esModule", { value: true });
27
- exports.usingAsync = exports.using = void 0;
28
25
  /**
29
26
  * Method that accepts an IDisposable resource that will be disposed after the callback
30
- *
31
27
  * @param resource The resource that is used in the callback and will be disposed afterwards
32
28
  * @param callback The callback that will be executed synchrounously before the resource will be disposed
33
29
  * @returns the value that will be returned by the callback method
34
30
  */
35
- const using = (resource, callback) => {
31
+ export const using = (resource, callback) => {
36
32
  try {
37
33
  return callback(resource);
38
34
  }
@@ -40,15 +36,13 @@ const using = (resource, callback) => {
40
36
  resource.dispose();
41
37
  }
42
38
  };
43
- exports.using = using;
44
39
  /**
45
40
  * Method that accepts an IDisposable resource that will be disposed after the callback
46
- *
47
41
  * @param resource The resource that is used in the callback and will be disposed afterwards
48
42
  * @param callback The callback that will be executed asynchrounously before the resource will be disposed
49
43
  * @returns A promise that will be resolved with a return value after the resource is disposed
50
44
  */
51
- const usingAsync = async (resource, callback) => {
45
+ export const usingAsync = async (resource, callback) => {
52
46
  try {
53
47
  return await callback(resource);
54
48
  }
@@ -59,5 +53,4 @@ const usingAsync = async (resource, callback) => {
59
53
  }
60
54
  }
61
55
  };
62
- exports.usingAsync = usingAsync;
63
56
  //# sourceMappingURL=disposable.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"disposable.js","sourceRoot":"","sources":["../src/disposable.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,MAAM;AAaN;;;;;GAKG;AACH,MAAM,CAAC,MAAM,KAAK,GAAG,CAAiC,QAAW,EAAE,QAA4B,EAAE,EAAE;IACjG,IAAI;QACF,OAAO,QAAQ,CAAC,QAAQ,CAAC,CAAA;KAC1B;YAAS;QACR,QAAQ,CAAC,OAAO,EAAE,CAAA;KACnB;AACH,CAAC,CAAA;AAED;;;;;GAKG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,KAAK,EAC7B,QAAW,EACX,QAAqC,EACrC,EAAE;IACF,IAAI;QACF,OAAO,MAAM,QAAQ,CAAC,QAAQ,CAAC,CAAA;KAChC;YAAS;QACR,MAAM,aAAa,GAAG,QAAQ,CAAC,OAAO,EAAE,CAAA;QACxC,IAAI,aAAa,YAAY,OAAO,EAAE;YACpC,MAAM,aAAa,CAAA;SACpB;KACF;AACH,CAAC,CAAA"}
package/esm/index.js ADDED
@@ -0,0 +1,11 @@
1
+ export * from './disposable';
2
+ export * from './deep-merge';
3
+ export * from './debounce';
4
+ export * from './observable-value';
5
+ export * from './value-observer';
6
+ export * from './path-helper';
7
+ export * from './sleep-async';
8
+ export * from './sort-by';
9
+ export * from './trace';
10
+ export * from './tuple';
11
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAA;AAC5B,cAAc,cAAc,CAAA;AAC5B,cAAc,YAAY,CAAA;AAC1B,cAAc,oBAAoB,CAAA;AAClC,cAAc,kBAAkB,CAAA;AAChC,cAAc,eAAe,CAAA;AAC7B,cAAc,eAAe,CAAA;AAC7B,cAAc,WAAW,CAAA;AACzB,cAAc,SAAS,CAAA;AACvB,cAAc,SAAS,CAAA"}
@@ -1,16 +1,12 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ObservableValue = exports.ObservableAlreadyDisposedError = void 0;
4
- const value_observer_1 = require("./value-observer");
1
+ import { ValueObserver } from './value-observer';
5
2
  /**
6
3
  * Error thrown when you try to retrieve or set an observable value that is already disposed.
7
4
  */
8
- class ObservableAlreadyDisposedError extends Error {
5
+ export class ObservableAlreadyDisposedError extends Error {
9
6
  constructor() {
10
7
  super('Observable already disposed');
11
8
  }
12
9
  }
13
- exports.ObservableAlreadyDisposedError = ObservableAlreadyDisposedError;
14
10
  /**
15
11
  * Defines an ObservableValue value object.
16
12
  *
@@ -20,7 +16,7 @@ exports.ObservableAlreadyDisposedError = ObservableAlreadyDisposedError;
20
16
  * ```ts
21
17
  * const observableValue = new ObservableValue<number>(0);
22
18
  * const observer = observableValue.subscribe((newValue) => {
23
- * console.log("Value changed:", newValue);
19
+ * console.log("Value changed:", newValue);
24
20
  * });
25
21
  * // To update the value
26
22
  * observableValue.setValue(Math.random());
@@ -29,10 +25,9 @@ exports.ObservableAlreadyDisposedError = ObservableAlreadyDisposedError;
29
25
  * // if you want to dispose the whole observableValue with all of its observers:
30
26
  * observableValue.dispose();
31
27
  * ```
32
- *
33
28
  * @param T Generic argument to indicate the value type
34
29
  */
35
- class ObservableValue {
30
+ export class ObservableValue {
36
31
  get isDisposed() {
37
32
  return this._isDisposed;
38
33
  }
@@ -45,7 +40,6 @@ class ObservableValue {
45
40
  }
46
41
  /**
47
42
  * Subscribes to a value changes
48
- *
49
43
  * @param callback The callback method that will be called on each change
50
44
  * @param getLast Will call the callback with the last known value right after subscription
51
45
  * @returns The ValueObserver instance
@@ -54,7 +48,7 @@ class ObservableValue {
54
48
  if (this._isDisposed) {
55
49
  throw new ObservableAlreadyDisposedError();
56
50
  }
57
- const observer = new value_observer_1.ValueObserver(this, callback);
51
+ const observer = new ValueObserver(this, callback);
58
52
  this.observers.add(observer);
59
53
  if (getLast) {
60
54
  callback(this.currentValue);
@@ -63,7 +57,6 @@ class ObservableValue {
63
57
  }
64
58
  /**
65
59
  * The observer will unsubscribe from the Observable
66
- *
67
60
  * @param observer The ValueObserver instance
68
61
  * @returns if unsubscribing was successfull
69
62
  */
@@ -72,7 +65,6 @@ class ObservableValue {
72
65
  }
73
66
  /**
74
67
  * Gets the current Value
75
- *
76
68
  * @returns The current value
77
69
  */
78
70
  getValue() {
@@ -83,7 +75,6 @@ class ObservableValue {
83
75
  }
84
76
  /**
85
77
  * Sets a new value and notifies the observers.
86
- *
87
78
  * @param newValue The new value to be set
88
79
  */
89
80
  setValue(newValue) {
@@ -99,7 +90,6 @@ class ObservableValue {
99
90
  }
100
91
  /**
101
92
  * Gets the observers
102
- *
103
93
  * @returns The subscribed observers
104
94
  */
105
95
  getObservers() {
@@ -116,5 +106,4 @@ class ObservableValue {
116
106
  }
117
107
  }
118
108
  }
119
- exports.ObservableValue = ObservableValue;
120
109
  //# sourceMappingURL=observable-value.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"observable-value.js","sourceRoot":"","sources":["../src/observable-value.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAA;AAEhD;;GAEG;AACH,MAAM,OAAO,8BAA+B,SAAQ,KAAK;IACvD;QACE,KAAK,CAAC,6BAA6B,CAAC,CAAA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AAC,QAAQ,CAAC,CAAA;aAChC;SACF;IACH,CAAC;IAED;;;OAGG;IACI,YAAY;QACjB,OAAO,CAAC,GAAG,IAAI,CAAC,SAAS,CAAoC,CAAA;IAC/D,CAAC;IAED;;OAEG;IACH,YAAY,YAAgB;QA7EpB,gBAAW,GAAG,KAAK,CAAA;QASnB,cAAS,GAA0B,IAAI,GAAG,EAAE,CAAA;QAqElD,IAAI,YAAY,KAAK,SAAS,EAAE;YAC9B,IAAI,CAAC,YAAY,GAAG,YAAY,CAAA;SACjC;IACH,CAAC;CACF"}
@@ -1,15 +1,11 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.PathHelper = void 0;
4
1
  /**
5
2
  * Helper class for path-related functions and methods
6
3
  *
7
4
  * The class contains general helper methods for joining, splitting, modifying and validating paths.
8
5
  */
9
- class PathHelper {
6
+ export class PathHelper {
10
7
  /**
11
8
  * Trims the slash characters from the beginning and from the end of the path to avoid duplicated slashes
12
- *
13
9
  * @param {string} path The source path that should be trimmed
14
10
  * @returns the trimmed path
15
11
  */
@@ -25,7 +21,6 @@ class PathHelper {
25
21
  /**
26
22
  * Splits a full path into path segments,
27
23
  * e.g.: /Root/Example/stuff
28
- *
29
24
  * @param path The path to be splitted
30
25
  * @returns {string[]} the segments for the path
31
26
  */
@@ -34,7 +29,6 @@ class PathHelper {
34
29
  }
35
30
  /**
36
31
  * Method that allows to join paths without multiple or missing slashes
37
- *
38
32
  * @param args The list of the paths to join
39
33
  * @returns the joined path string
40
34
  */
@@ -43,7 +37,6 @@ class PathHelper {
43
37
  }
44
38
  /**
45
39
  * Checks if the ancestorPath is really the ancestor of the descendantPath
46
- *
47
40
  * @param {string} ancestorPath the ancestor path
48
41
  * @param {string} descendantPath the descendant path
49
42
  * @returns {boolean} if the provided path is the ancestor of the descendant
@@ -56,7 +49,6 @@ class PathHelper {
56
49
  * e.g. "/Root/Example/Content" will return "/Root/Example"
57
50
  *
58
51
  * "Root" will always return "Root"
59
- *
60
52
  * @param path The content path
61
53
  * @returns the parent path
62
54
  */
@@ -71,5 +63,4 @@ class PathHelper {
71
63
  return this.getSegments(path).join('/');
72
64
  }
73
65
  }
74
- exports.PathHelper = PathHelper;
75
66
  //# sourceMappingURL=path-helper.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"path-helper.js","sourceRoot":"","sources":["../src/path-helper.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,OAAO,UAAU;IACrB;;;;OAIG;IACI,MAAM,CAAC,WAAW,CAAC,IAAY;QACpC,OAAO,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE;YACzB,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC,CAAC,EAAE,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,CAAA;SAC1C;QACD,OAAO,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE;YAC3B,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC,CAAC,EAAE,IAAI,CAAC,MAAM,CAAC,CAAA;SACtC;QACD,OAAO,IAAI,CAAA;IACb,CAAC;IAED;;;;;OAKG;IACI,MAAM,CAAC,WAAW,CAAC,IAAY;QACpC,OAAO,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,IAAI,OAAO,CAAC,MAAM,CAAC,CAAA;IACvE,CAAC;IAED;;;;OAIG;IACI,MAAM,CAAC,SAAS,CAAC,GAAG,IAAc;QACvC,OAAO,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;IAC7C,CAAC;IAED;;;;;OAKG;IACI,MAAM,CAAC,YAAY,CAAC,YAAoB,EAAE,cAAsB;QACrE,OAAO,cAAc,CAAC,OAAO,CAAC,GAAG,IAAI,CAAC,SAAS,CAAC,YAAY,CAAC,GAAG,CAAC,KAAK,CAAC,CAAA;IACzE,CAAC;IAED;;;;;;;OAOG;IACI,MAAM,CAAC,aAAa,CAAC,IAAY;QACtC,MAAM,QAAQ,GAAG,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,CAAA;QACvC,IAAI,QAAQ,CAAC,MAAM,GAAG,CAAC,EAAE;YACvB,QAAQ,CAAC,GAAG,EAAE,CAAA;SACf;QACD,OAAO,QAAQ,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;IAC3B,CAAC;IAEM,MAAM,CAAC,SAAS,CAAC,IAAY;QAClC,OAAO,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;IACzC,CAAC;CACF"}
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Returns a simple promise that will be resolved within a discrete timeout
3
+ * @param timeout The timeout in millisecs
4
+ */
5
+ export const sleepAsync = (timeout = 250) => new Promise((resolve) => setTimeout(() => {
6
+ resolve();
7
+ }, timeout));
8
+ //# sourceMappingURL=sleep-async.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sleep-async.js","sourceRoot":"","sources":["../src/sleep-async.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,OAAO,GAAG,GAAG,EAAE,EAAE,CAC1C,IAAI,OAAO,CAAO,CAAC,OAAO,EAAE,EAAE,CAC5B,UAAU,CAAC,GAAG,EAAE;IACd,OAAO,EAAE,CAAA;AACX,CAAC,EAAE,OAAO,CAAC,CACZ,CAAA"}
package/esm/sort-by.js ADDED
@@ -0,0 +1,15 @@
1
+ export const compareBy = (entity1, entity2, field, direction) => {
2
+ const a = direction === 'asc' ? entity1 : entity2;
3
+ const b = direction === 'asc' ? entity2 : entity1;
4
+ if (a[field] < b[field]) {
5
+ return -1;
6
+ }
7
+ if (a[field] > b[field]) {
8
+ return 1;
9
+ }
10
+ return 0;
11
+ };
12
+ Array.prototype.sortBy = function (key, direction = 'asc') {
13
+ return this.sort((a, b) => compareBy(a, b, key, direction));
14
+ };
15
+ //# sourceMappingURL=sort-by.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sort-by.js","sourceRoot":"","sources":["../src/sort-by.ts"],"names":[],"mappings":"AAYA,MAAM,CAAC,MAAM,SAAS,GAAG,CAAuB,OAAU,EAAE,OAAU,EAAE,KAAQ,EAAE,SAAyB,EAAE,EAAE;IAC7G,MAAM,CAAC,GAAG,SAAS,KAAK,KAAK,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,OAAO,CAAA;IACjD,MAAM,CAAC,GAAG,SAAS,KAAK,KAAK,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,OAAO,CAAA;IACjD,IAAI,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,EAAE;QACvB,OAAO,CAAC,CAAC,CAAA;KACV;IACD,IAAI,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,EAAE;QACvB,OAAO,CAAC,CAAA;KACT;IACD,OAAO,CAAC,CAAA;AACV,CAAC,CAAA;AAED,KAAK,CAAC,SAAS,CAAC,MAAM,GAAG,UAAU,GAAG,EAAE,SAAS,GAAG,KAAK;IACvD,OAAO,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,SAAS,CAAC,CAAC,EAAE,CAAC,EAAE,GAAG,EAAE,SAAS,CAAC,CAAC,CAAA;AAC7D,CAAC,CAAA"}
@@ -1,7 +1,4 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Trace = void 0;
4
- const observable_value_1 = require("./observable-value");
1
+ import { ObservableValue } from './observable-value';
5
2
  /**
6
3
  * Helper class that can be used to trace method calls programmatically
7
4
  *
@@ -84,7 +81,6 @@ class Trace {
84
81
  }
85
82
  /**
86
83
  * Creates an observer that will be observe method calls, finishes and errors
87
- *
88
84
  * @param options The options object for the trace
89
85
  * @returns the trace object that can be disposed after usage
90
86
  */
@@ -109,9 +105,9 @@ class Trace {
109
105
  if (!objectTrace.methodMappings.has(options.method.name)) {
110
106
  objectTrace.methodMappings.set(options.method.name, {
111
107
  originalMethod: options.method,
112
- callObservable: new observable_value_1.ObservableValue(),
113
- finishedObservable: new observable_value_1.ObservableValue(),
114
- errorObservable: new observable_value_1.ObservableValue(),
108
+ callObservable: new ObservableValue(),
109
+ finishedObservable: new ObservableValue(),
110
+ errorObservable: new ObservableValue(),
115
111
  });
116
112
  }
117
113
  const methodTrace = objectTrace.methodMappings.get(options.method.name);
@@ -127,5 +123,5 @@ class Trace {
127
123
  }
128
124
  }
129
125
  Trace.objectTraces = new Map();
130
- exports.Trace = Trace;
126
+ export { Trace };
131
127
  //# sourceMappingURL=trace.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"trace.js","sourceRoot":"","sources":["../src/trace.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAA;AA2FpD;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAa,KAAK;IAGR,MAAM,CAAC,cAAc,CAC3B,MAAc,EACd,MAAoC;QAEpC,MAAM,WAAW,GAAG,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,MAAM,CAAuB,CAAA;QACvE,OAAO,WAAW,CAAC,cAAc,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,CAA0C,CAAA;IAC7F,CAAC;IAEO,MAAM,CAAC,UAAU,CACvB,WAA6C,EAC7C,IAAa;QAEb,MAAM,aAAa,GAAG,IAAI,IAAI,EAAE,CAAA;QAChC,MAAM,UAAU,GAAG;YACjB,eAAe,EAAE,IAAI;YACrB,aAAa;SACd,CAAA;QACD,WAAW,CAAC,cAAc,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAA;QAC/C,OAAO,UAAU,CAAA;IACnB,CAAC;IAEO,MAAM,CAAC,aAAa,CAC1B,WAA2C,EAC3C,IAAW,EACX,SAAiC,EACjC,QAAa;QAEb,MAA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,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,OAAO,EAAE,CAAC;SAC1D,CAAA;IACH,CAAC;;AAxIc,kBAAY,GAA6B,IAAI,GAAG,EAAE,CAAA;SADtD,KAAK"}
package/esm/tuple.js ADDED
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Factory method for creating a Tuple instance.
3
+ * @param args The argument list to create
4
+ * @returns alma asd
5
+ */
6
+ export const tuple = (...args) => args;
7
+ //# sourceMappingURL=tuple.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tuple.js","sourceRoot":"","sources":["../src/tuple.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,CAAC,MAAM,KAAK,GAAG,CAAqB,GAAG,IAAO,EAAE,EAAE,CAAC,IAAI,CAAA"}
@@ -1,6 +1,3 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ValueObserver = void 0;
4
1
  /**
5
2
  * Defines a generic ValueObserver instance
6
3
  *
@@ -11,7 +8,7 @@ exports.ValueObserver = void 0;
11
8
  *
12
9
  * const observableValue = new ObservableValue<number>(0);
13
10
  * const observer = observableValue.subscribe((newValue) => {
14
- * console.log("Value changed:", newValue);
11
+ * console.log("Value changed:", newValue);
15
12
  * });
16
13
  *
17
14
  * // To update the value
@@ -21,10 +18,9 @@ exports.ValueObserver = void 0;
21
18
  * // if you want to dispose the whole observableValue with all of its observers:
22
19
  * observableValue.dispose();
23
20
  * ```
24
- *
25
21
  * @param T This type parameter is the value type to observe
26
22
  */
27
- class ValueObserver {
23
+ export class ValueObserver {
28
24
  /**
29
25
  * Disposes the ValueObserver instance. Unsubscribes from the observable
30
26
  */
@@ -41,5 +37,4 @@ class ValueObserver {
41
37
  this.callback = callback;
42
38
  }
43
39
  }
44
- exports.ValueObserver = ValueObserver;
45
40
  //# sourceMappingURL=value-observer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"value-observer.js","sourceRoot":"","sources":["../src/value-observer.ts"],"names":[],"mappings":"AAGA;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAM,OAAO,aAAa;IACxB;;OAEG;IACI,OAAO;QACZ,IAAI,CAAC,UAAU,CAAC,WAAW,CAAC,IAAI,CAAC,CAAA;IACnC,CAAC;IAED;;;;OAIG;IACH,YAA4B,UAA8B,EAAS,QAAgC;QAAvE,eAAU,GAAV,UAAU,CAAoB;QAAS,aAAQ,GAAR,QAAQ,CAAwB;IAAG,CAAC;CACxG"}
package/package.json CHANGED
@@ -1,18 +1,30 @@
1
1
  {
2
2
  "name": "@furystack/utils",
3
- "version": "3.1.8",
3
+ "version": "4.0.1",
4
4
  "description": "General utilities",
5
- "main": "dist/index.js",
6
- "typings": "./types/index.d.ts",
5
+ "type": "module",
6
+ "scripts": {
7
+ "build:es6": "tsc --outDir ./esm"
8
+ },
9
+ "exports": {
10
+ ".": {
11
+ "import": "./esm/index.js",
12
+ "types": "./types/index.d.ts"
13
+ },
14
+ "./package.json": "./package.json"
15
+ },
16
+ "typesVersions": {
17
+ "*": {
18
+ "*": [
19
+ "types/*"
20
+ ]
21
+ }
22
+ },
7
23
  "files": [
8
- "dist",
24
+ "esm",
9
25
  "types",
10
26
  "src"
11
27
  ],
12
- "scripts": {
13
- "fix:prettier": "prettier \"{,!(dist|temp)/**/}*.{ts,tsx}\" --write",
14
- "build": "tsc -b"
15
- },
16
28
  "repository": {
17
29
  "type": "git",
18
30
  "url": "https://github.com/furystack/furystack.git"
@@ -31,6 +43,7 @@
31
43
  },
32
44
  "homepage": "https://github.com/furystack/furystack",
33
45
  "devDependencies": {
34
- "@types/jest": "^29.5.0"
46
+ "typescript": "^5.0.4",
47
+ "vitest": "^0.30.1"
35
48
  }
36
49
  }
@@ -1,3 +1,4 @@
1
+ import { describe, it, expect, vi } from 'vitest'
1
2
  import { debounce } from './debounce'
2
3
  import { sleepAsync } from './sleep-async'
3
4
 
@@ -5,35 +6,37 @@ import { sleepAsync } from './sleep-async'
5
6
  * Tests for debounce
6
7
  */
7
8
  export const debounceTests = describe('debounce', () => {
8
- it('Simple method execution', (done) => {
9
- const method = debounce(() => {
10
- done()
9
+ it('Simple method execution', async () => {
10
+ const method = vi.fn()
11
+ await new Promise<void>((resolve) => {
12
+ const debouncedMethod = debounce(() => {
13
+ resolve()
14
+ method()
15
+ })
16
+ debouncedMethod()
11
17
  })
12
- method()
18
+ expect(method).toBeCalledTimes(1)
13
19
  })
14
20
 
15
21
  it('Should be executed once when triggered multiple time in a given range', async () => {
16
- let counter = 0
17
- const method = debounce(() => {
18
- counter++
19
- }, 10)
22
+ const method = vi.fn()
23
+
24
+ const debouncedMethod = debounce(method, 10)
20
25
  for (let index = 0; index < 10; index++) {
21
- method()
26
+ debouncedMethod()
22
27
  }
23
28
  await sleepAsync(300)
24
- expect(counter).toBe(1)
29
+ expect(method).toBeCalledTimes(1)
25
30
  })
26
31
 
27
32
  it('Should be executed multiple times when triggered multiple times out of a a given range', async () => {
28
- let counter = 0
29
- const method = debounce(() => {
30
- counter++
31
- }, 10)
33
+ const method = vi.fn()
34
+
35
+ const debouncedMethod = debounce(method, 10)
32
36
  for (let index = 0; index < 10; index++) {
33
- method()
37
+ debouncedMethod()
34
38
  await sleepAsync(15)
35
39
  }
36
- await sleepAsync(300)
37
- expect(counter).toBe(10)
40
+ expect(method).toBeCalledTimes(10)
38
41
  })
39
42
  })
@@ -1,3 +1,4 @@
1
+ import { describe, it, expect } from 'vitest'
1
2
  import { deepMerge } from './deep-merge'
2
3
 
3
4
  describe('DeepMerge tests', () => {
package/src/deep-merge.ts CHANGED
@@ -5,7 +5,6 @@ export type DeepPartial<T> = { [K in keyof T]?: DeepPartial<T[K]> }
5
5
 
6
6
  /**
7
7
  * Deep merge two objects.
8
- *
9
8
  * @param target The source object to be merged
10
9
  * @param sources The source objects
11
10
  * @returns A new instance with the merged values
@@ -1,3 +1,4 @@
1
+ import { describe, it, expect, vi } from 'vitest'
1
2
  import type { Disposable } from './disposable'
2
3
  import { using, usingAsync } from './disposable'
3
4
 
@@ -59,42 +60,49 @@ export const disposableTests = describe('Disposable', () => {
59
60
  })
60
61
 
61
62
  describe('dispose()', () => {
62
- it('should be called on error', (done) => {
63
+ it('should be called on error', () => {
64
+ const callbackMethod = vi.fn()
63
65
  try {
64
66
  using(new MockDisposable(), (d) => {
65
67
  d.disposeCallback = () => {
66
- done()
68
+ callbackMethod()
67
69
  }
68
-
69
70
  d.whooops()
70
71
  })
71
72
  } catch {
72
73
  /** ignore */
73
74
  }
75
+ expect(callbackMethod).toBeCalled()
74
76
  })
75
77
 
76
- it('should be called with usingAsync()', (done) => {
77
- usingAsync(new MockDisposable(), async (d) => {
78
+ it('should be called with usingAsync()', async () => {
79
+ const callbackMethod = vi.fn()
80
+ await usingAsync(new MockDisposable(), async (d) => {
78
81
  d.disposeCallback = () => {
79
- done()
82
+ callbackMethod()
80
83
  }
81
84
  return new Promise((resolve) => {
82
85
  setTimeout(resolve, 1)
83
86
  })
84
87
  })
88
+ expect(callbackMethod).toBeCalled()
85
89
  })
86
90
 
87
- it('should be called when async fails', (done) => {
88
- usingAsync(new MockDisposable(), async (d) => {
89
- d.disposeCallback = () => {
90
- done()
91
- }
92
- return new Promise((_resolve, reject) => {
93
- setTimeout(reject, 1)
91
+ it('should be called when async fails', async () => {
92
+ const callbackMethod = vi.fn()
93
+ try {
94
+ await usingAsync(new MockDisposable(), async (d) => {
95
+ d.disposeCallback = () => {
96
+ callbackMethod()
97
+ }
98
+ return new Promise((_resolve, reject) => {
99
+ setTimeout(reject, 1)
100
+ })
94
101
  })
95
- }).catch(() => {
102
+ } catch (error) {
96
103
  /** ignore */
97
- })
104
+ }
105
+ expect(callbackMethod).toBeCalled()
98
106
  })
99
107
 
100
108
  it('should await dispose for asyncs with usingAsync()', async () => {
package/src/disposable.ts CHANGED
@@ -36,7 +36,6 @@ export interface Disposable {
36
36
 
37
37
  /**
38
38
  * Method that accepts an IDisposable resource that will be disposed after the callback
39
- *
40
39
  * @param resource The resource that is used in the callback and will be disposed afterwards
41
40
  * @param callback The callback that will be executed synchrounously before the resource will be disposed
42
41
  * @returns the value that will be returned by the callback method
@@ -51,7 +50,6 @@ export const using = <T extends Disposable, TReturns>(resource: T, callback: (r:
51
50
 
52
51
  /**
53
52
  * Method that accepts an IDisposable resource that will be disposed after the callback
54
- *
55
53
  * @param resource The resource that is used in the callback and will be disposed afterwards
56
54
  * @param callback The callback that will be executed asynchrounously before the resource will be disposed
57
55
  * @returns A promise that will be resolved with a return value after the resource is disposed