@naturalcycles/js-lib 14.178.0 → 14.180.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/dist/index.d.ts CHANGED
@@ -80,6 +80,7 @@ export * from './env/buildInfo';
80
80
  export * from './form.util';
81
81
  export * from './semver';
82
82
  export * from './web';
83
+ export * from './polyfill';
83
84
  export * from './zod/zod.util';
84
85
  export * from './zod/zod.shared.schemas';
85
86
  import { z, ZodSchema, ZodError, ZodIssue } from 'zod';
package/dist/index.js CHANGED
@@ -84,6 +84,7 @@ tslib_1.__exportStar(require("./env/buildInfo"), exports);
84
84
  tslib_1.__exportStar(require("./form.util"), exports);
85
85
  tslib_1.__exportStar(require("./semver"), exports);
86
86
  tslib_1.__exportStar(require("./web"), exports);
87
+ tslib_1.__exportStar(require("./polyfill"), exports);
87
88
  tslib_1.__exportStar(require("./zod/zod.util"), exports);
88
89
  tslib_1.__exportStar(require("./zod/zod.shared.schemas"), exports);
89
90
  const zod_1 = require("zod");
package/dist/is.util.d.ts CHANGED
@@ -23,9 +23,9 @@ export declare const _isFalsy: <T>(v: T) => v is Falsy<T>;
23
23
  /**
24
24
  * Returns true if item is Object, not null and not Array.
25
25
  */
26
- export declare function _isObject(item: any): item is AnyObject;
26
+ export declare function _isObject(obj: any): obj is AnyObject;
27
27
  export declare function _isPrimitive(v: any): v is Primitive;
28
- export declare function _isEmptyObject(obj: any): boolean;
28
+ export declare function _isEmptyObject(obj: AnyObject): boolean;
29
29
  /**
30
30
  * Object is considered empty if it's one of:
31
31
  * undefined
package/dist/is.util.js CHANGED
@@ -27,8 +27,8 @@ exports._isFalsy = _isFalsy;
27
27
  /**
28
28
  * Returns true if item is Object, not null and not Array.
29
29
  */
30
- function _isObject(item) {
31
- return (typeof item === 'object' && item !== null && !Array.isArray(item)) || false;
30
+ function _isObject(obj) {
31
+ return obj?.constructor === Object;
32
32
  }
33
33
  exports._isObject = _isObject;
34
34
  function _isPrimitive(v) {
@@ -42,7 +42,7 @@ function _isPrimitive(v) {
42
42
  }
43
43
  exports._isPrimitive = _isPrimitive;
44
44
  function _isEmptyObject(obj) {
45
- return obj && obj.constructor === Object && Object.keys(obj).length === 0;
45
+ return Object.keys(obj).length === 0;
46
46
  }
47
47
  exports._isEmptyObject = _isEmptyObject;
48
48
  /**
@@ -0,0 +1 @@
1
+ export declare function polyfillDispose(): void;
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.polyfillDispose = void 0;
4
+ function polyfillDispose() {
5
+ // @ts-expect-error polyfill
6
+ Symbol.dispose ??= Symbol('Symbol.dispose');
7
+ // @ts-expect-error polyfill
8
+ Symbol.asyncDispose ??= Symbol('Symbol.asyncDispose');
9
+ }
10
+ exports.polyfillDispose = polyfillDispose;
@@ -1,3 +1,13 @@
1
+ /**
2
+ * using _ = blockTimer()
3
+ * // will log "took 1.234 sec" on dispose
4
+ *
5
+ * using _ = blockTimer('named')
6
+ * // will log "named took 1.234 sec" on dispose
7
+ *
8
+ * @experimental
9
+ */
10
+ export declare function _blockTimer(name?: string): Disposable;
1
11
  /**
2
12
  * Returns time passed since `from` until `until` (default to Date.now())
3
13
  */
@@ -1,6 +1,24 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports._ms = exports._since = void 0;
3
+ exports._ms = exports._since = exports._blockTimer = void 0;
4
+ /**
5
+ * using _ = blockTimer()
6
+ * // will log "took 1.234 sec" on dispose
7
+ *
8
+ * using _ = blockTimer('named')
9
+ * // will log "named took 1.234 sec" on dispose
10
+ *
11
+ * @experimental
12
+ */
13
+ function _blockTimer(name) {
14
+ const started = Date.now();
15
+ return {
16
+ [Symbol.dispose]() {
17
+ console.log(`${name ? name + ' ' : ''}took ${_since(started)}`);
18
+ },
19
+ };
20
+ }
21
+ exports._blockTimer = _blockTimer;
4
22
  /**
5
23
  * Returns time passed since `from` until `until` (default to Date.now())
6
24
  */
package/dist-esm/index.js CHANGED
@@ -80,6 +80,7 @@ export * from './env/buildInfo';
80
80
  export * from './form.util';
81
81
  export * from './semver';
82
82
  export * from './web';
83
+ export * from './polyfill';
83
84
  export * from './zod/zod.util';
84
85
  export * from './zod/zod.shared.schemas';
85
86
  import { z, ZodSchema, ZodError } from 'zod';
@@ -18,8 +18,8 @@ export const _isFalsy = (v) => !v;
18
18
  /**
19
19
  * Returns true if item is Object, not null and not Array.
20
20
  */
21
- export function _isObject(item) {
22
- return (typeof item === 'object' && item !== null && !Array.isArray(item)) || false;
21
+ export function _isObject(obj) {
22
+ return (obj === null || obj === void 0 ? void 0 : obj.constructor) === Object;
23
23
  }
24
24
  export function _isPrimitive(v) {
25
25
  return (v === null ||
@@ -31,7 +31,7 @@ export function _isPrimitive(v) {
31
31
  typeof v === 'symbol');
32
32
  }
33
33
  export function _isEmptyObject(obj) {
34
- return obj && obj.constructor === Object && Object.keys(obj).length === 0;
34
+ return Object.keys(obj).length === 0;
35
35
  }
36
36
  /**
37
37
  * Object is considered empty if it's one of:
@@ -0,0 +1,7 @@
1
+ export function polyfillDispose() {
2
+ var _a, _b;
3
+ // @ts-expect-error polyfill
4
+ (_a = Symbol.dispose) !== null && _a !== void 0 ? _a : (Symbol.dispose = Symbol('Symbol.dispose'));
5
+ // @ts-expect-error polyfill
6
+ (_b = Symbol.asyncDispose) !== null && _b !== void 0 ? _b : (Symbol.asyncDispose = Symbol('Symbol.asyncDispose'));
7
+ }
@@ -1,3 +1,20 @@
1
+ /**
2
+ * using _ = blockTimer()
3
+ * // will log "took 1.234 sec" on dispose
4
+ *
5
+ * using _ = blockTimer('named')
6
+ * // will log "named took 1.234 sec" on dispose
7
+ *
8
+ * @experimental
9
+ */
10
+ export function _blockTimer(name) {
11
+ const started = Date.now();
12
+ return {
13
+ [Symbol.dispose]() {
14
+ console.log(`${name ? name + ' ' : ''}took ${_since(started)}`);
15
+ },
16
+ };
17
+ }
1
18
  /**
2
19
  * Returns time passed since `from` until `until` (default to Date.now())
3
20
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@naturalcycles/js-lib",
3
- "version": "14.178.0",
3
+ "version": "14.180.0",
4
4
  "scripts": {
5
5
  "prepare": "husky install",
6
6
  "build-prod": "build-prod-esm-cjs",
package/src/index.ts CHANGED
@@ -80,6 +80,7 @@ export * from './env/buildInfo'
80
80
  export * from './form.util'
81
81
  export * from './semver'
82
82
  export * from './web'
83
+ export * from './polyfill'
83
84
  export * from './zod/zod.util'
84
85
  export * from './zod/zod.shared.schemas'
85
86
  import { z, ZodSchema, ZodError, ZodIssue } from 'zod'
package/src/is.util.ts CHANGED
@@ -27,8 +27,8 @@ export const _isFalsy = <T>(v: T): v is Falsy<T> => !v
27
27
  /**
28
28
  * Returns true if item is Object, not null and not Array.
29
29
  */
30
- export function _isObject(item: any): item is AnyObject {
31
- return (typeof item === 'object' && item !== null && !Array.isArray(item)) || false
30
+ export function _isObject(obj: any): obj is AnyObject {
31
+ return obj?.constructor === Object
32
32
  }
33
33
 
34
34
  export function _isPrimitive(v: any): v is Primitive {
@@ -43,8 +43,8 @@ export function _isPrimitive(v: any): v is Primitive {
43
43
  )
44
44
  }
45
45
 
46
- export function _isEmptyObject(obj: any): boolean {
47
- return obj && obj.constructor === Object && Object.keys(obj).length === 0
46
+ export function _isEmptyObject(obj: AnyObject): boolean {
47
+ return Object.keys(obj).length === 0
48
48
  }
49
49
 
50
50
  /**
@@ -0,0 +1,6 @@
1
+ export function polyfillDispose(): void {
2
+ // @ts-expect-error polyfill
3
+ Symbol.dispose ??= Symbol('Symbol.dispose')
4
+ // @ts-expect-error polyfill
5
+ Symbol.asyncDispose ??= Symbol('Symbol.asyncDispose')
6
+ }
@@ -1,3 +1,21 @@
1
+ /**
2
+ * using _ = blockTimer()
3
+ * // will log "took 1.234 sec" on dispose
4
+ *
5
+ * using _ = blockTimer('named')
6
+ * // will log "named took 1.234 sec" on dispose
7
+ *
8
+ * @experimental
9
+ */
10
+ export function _blockTimer(name?: string): Disposable {
11
+ const started = Date.now()
12
+ return {
13
+ [Symbol.dispose](): void {
14
+ console.log(`${name ? name + ' ' : ''}took ${_since(started)}`)
15
+ },
16
+ } as any
17
+ }
18
+
1
19
  /**
2
20
  * Returns time passed since `from` until `until` (default to Date.now())
3
21
  */