@augment-vir/common 14.4.0 → 15.1.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.
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.removePx = exports.addPx = void 0;
4
+ function addPx(input) {
5
+ if (String(input).endsWith('px')) {
6
+ return String(input);
7
+ }
8
+ else {
9
+ return `${input}px`;
10
+ }
11
+ }
12
+ exports.addPx = addPx;
13
+ function removePx(input) {
14
+ return Number(input.replace(/px$/, ''));
15
+ }
16
+ exports.removePx = removePx;
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.measureCallbackDuration = exports.timeCallback = void 0;
4
+ /**
5
+ * Measures how long (in milliseconds) the given callback takes to run to completion. Automatically
6
+ * switches to async mode and awaits callbacks if they return a promise (otherwise this function is
7
+ * purely synchronous).
8
+ */
9
+ function timeCallback(callback) {
10
+ const startTime = Date.now();
11
+ const result = callback();
12
+ if (result instanceof Promise) {
13
+ return new Promise(async (resolve, reject) => {
14
+ try {
15
+ await result;
16
+ const endTime = Date.now();
17
+ resolve(endTime - startTime);
18
+ }
19
+ catch (caught) {
20
+ reject(caught);
21
+ }
22
+ });
23
+ }
24
+ const endTime = Date.now();
25
+ return (endTime - startTime);
26
+ }
27
+ exports.timeCallback = timeCallback;
28
+ /**
29
+ * Measures how long (in milliseconds) the given callback takes to run to completion. Automatically
30
+ * switches to async mode and awaits callbacks if they return a promise (otherwise this function is
31
+ * purely synchronous).
32
+ *
33
+ * Alias of timeCallback.
34
+ */
35
+ exports.measureCallbackDuration = timeCallback;
package/dist/cjs/index.js CHANGED
@@ -19,8 +19,6 @@ __exportStar(require("./augments/array"), exports);
19
19
  __exportStar(require("./augments/async"), exports);
20
20
  __exportStar(require("./augments/common-number"), exports);
21
21
  __exportStar(require("./augments/common-string"), exports);
22
- __exportStar(require("./augments/date/date"), exports);
23
- __exportStar(require("./augments/date/relative-date"), exports);
24
22
  __exportStar(require("./augments/environment"), exports);
25
23
  __exportStar(require("./augments/error"), exports);
26
24
  __exportStar(require("./augments/function"), exports);
@@ -38,11 +36,13 @@ __exportStar(require("./augments/object/object"), exports);
38
36
  __exportStar(require("./augments/object/object-entries"), exports);
39
37
  __exportStar(require("./augments/object/pick-deep"), exports);
40
38
  __exportStar(require("./augments/object/typed-has-property"), exports);
39
+ __exportStar(require("./augments/pixel"), exports);
41
40
  __exportStar(require("./augments/promise"), exports);
42
41
  __exportStar(require("./augments/regexp"), exports);
43
42
  __exportStar(require("./augments/runtime-type-of"), exports);
44
43
  __exportStar(require("./augments/string/url"), exports);
45
44
  __exportStar(require("./augments/string/uuid"), exports);
45
+ __exportStar(require("./augments/time"), exports);
46
46
  __exportStar(require("./augments/truncate-number"), exports);
47
47
  __exportStar(require("./augments/tuple"), exports);
48
48
  __exportStar(require("./augments/type"), exports);
@@ -0,0 +1,11 @@
1
+ export function addPx(input) {
2
+ if (String(input).endsWith('px')) {
3
+ return String(input);
4
+ }
5
+ else {
6
+ return `${input}px`;
7
+ }
8
+ }
9
+ export function removePx(input) {
10
+ return Number(input.replace(/px$/, ''));
11
+ }
@@ -0,0 +1,31 @@
1
+ /**
2
+ * Measures how long (in milliseconds) the given callback takes to run to completion. Automatically
3
+ * switches to async mode and awaits callbacks if they return a promise (otherwise this function is
4
+ * purely synchronous).
5
+ */
6
+ export function timeCallback(callback) {
7
+ const startTime = Date.now();
8
+ const result = callback();
9
+ if (result instanceof Promise) {
10
+ return new Promise(async (resolve, reject) => {
11
+ try {
12
+ await result;
13
+ const endTime = Date.now();
14
+ resolve(endTime - startTime);
15
+ }
16
+ catch (caught) {
17
+ reject(caught);
18
+ }
19
+ });
20
+ }
21
+ const endTime = Date.now();
22
+ return (endTime - startTime);
23
+ }
24
+ /**
25
+ * Measures how long (in milliseconds) the given callback takes to run to completion. Automatically
26
+ * switches to async mode and awaits callbacks if they return a promise (otherwise this function is
27
+ * purely synchronous).
28
+ *
29
+ * Alias of timeCallback.
30
+ */
31
+ export const measureCallbackDuration = timeCallback;
package/dist/esm/index.js CHANGED
@@ -3,8 +3,6 @@ export * from './augments/array';
3
3
  export * from './augments/async';
4
4
  export * from './augments/common-number';
5
5
  export * from './augments/common-string';
6
- export * from './augments/date/date';
7
- export * from './augments/date/relative-date';
8
6
  export * from './augments/environment';
9
7
  export * from './augments/error';
10
8
  export * from './augments/function';
@@ -22,11 +20,13 @@ export * from './augments/object/object';
22
20
  export * from './augments/object/object-entries';
23
21
  export * from './augments/object/pick-deep';
24
22
  export * from './augments/object/typed-has-property';
23
+ export * from './augments/pixel';
25
24
  export * from './augments/promise';
26
25
  export * from './augments/regexp';
27
26
  export * from './augments/runtime-type-of';
28
27
  export * from './augments/string/url';
29
28
  export * from './augments/string/uuid';
29
+ export * from './augments/time';
30
30
  export * from './augments/truncate-number';
31
31
  export * from './augments/tuple';
32
32
  export * from './augments/type';
@@ -0,0 +1,3 @@
1
+ export type WithPx = `${string | number}px`;
2
+ export declare function addPx(input: number | string): WithPx;
3
+ export declare function removePx(input: WithPx | string): number;
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Measures how long (in milliseconds) the given callback takes to run to completion. Automatically
3
+ * switches to async mode and awaits callbacks if they return a promise (otherwise this function is
4
+ * purely synchronous).
5
+ */
6
+ export declare function timeCallback<T>(callback: () => T): T extends Promise<any> ? Promise<number> : number;
7
+ /**
8
+ * Measures how long (in milliseconds) the given callback takes to run to completion. Automatically
9
+ * switches to async mode and awaits callbacks if they return a promise (otherwise this function is
10
+ * purely synchronous).
11
+ *
12
+ * Alias of timeCallback.
13
+ */
14
+ export declare const measureCallbackDuration: typeof timeCallback;
@@ -3,8 +3,6 @@ export * from './augments/array';
3
3
  export * from './augments/async';
4
4
  export * from './augments/common-number';
5
5
  export * from './augments/common-string';
6
- export * from './augments/date/date';
7
- export * from './augments/date/relative-date';
8
6
  export * from './augments/environment';
9
7
  export * from './augments/error';
10
8
  export * from './augments/function';
@@ -22,11 +20,13 @@ export * from './augments/object/object';
22
20
  export * from './augments/object/object-entries';
23
21
  export * from './augments/object/pick-deep';
24
22
  export * from './augments/object/typed-has-property';
23
+ export * from './augments/pixel';
25
24
  export * from './augments/promise';
26
25
  export * from './augments/regexp';
27
26
  export * from './augments/runtime-type-of';
28
27
  export * from './augments/string/url';
29
28
  export * from './augments/string/uuid';
29
+ export * from './augments/time';
30
30
  export * from './augments/truncate-number';
31
31
  export * from './augments/tuple';
32
32
  export * from './augments/type';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@augment-vir/common",
3
- "version": "14.4.0",
3
+ "version": "15.1.0",
4
4
  "homepage": "https://github.com/electrovir/augment-vir/tree/main/packages/common",
5
5
  "bugs": {
6
6
  "url": "https://github.com/electrovir/augment-vir/issues"
@@ -24,7 +24,7 @@
24
24
  "test:types": "tsc --noEmit"
25
25
  },
26
26
  "dependencies": {
27
- "type-fest": "^3.11.1"
27
+ "type-fest": "^3.12.0"
28
28
  },
29
29
  "devDependencies": {
30
30
  "typescript": "^5.1.3"