@naturalcycles/js-lib 14.170.0 → 14.171.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.
@@ -8,6 +8,14 @@ import type { FetcherAfterResponseHook, FetcherBeforeRequestHook, FetcherBeforeR
8
8
  * Works in both Browser and Node, using `globalThis.fetch`.
9
9
  */
10
10
  export declare class Fetcher {
11
+ /**
12
+ * Included in UserAgent when run in Node.
13
+ * In the browser it's not included, as we want "browser own" UserAgent to be included instead.
14
+ *
15
+ * Version is to be incremented every time a difference in behaviour (or a bugfix) is done.
16
+ */
17
+ static readonly VERSION = 1;
18
+ static readonly userAgent: string | undefined;
11
19
  private constructor();
12
20
  /**
13
21
  * Add BeforeRequest hook at the end of the hooks list.
@@ -34,6 +34,14 @@ const defRetryOptions = {
34
34
  * Works in both Browser and Node, using `globalThis.fetch`.
35
35
  */
36
36
  class Fetcher {
37
+ /**
38
+ * Included in UserAgent when run in Node.
39
+ * In the browser it's not included, as we want "browser own" UserAgent to be included instead.
40
+ *
41
+ * Version is to be incremented every time a difference in behaviour (or a bugfix) is done.
42
+ */
43
+ static { this.VERSION = 1; }
44
+ static { this.userAgent = (0, env_1.isServerSide)() ? `fetcher${this.VERSION}` : undefined; }
37
45
  constructor(cfg = {}) {
38
46
  if (typeof globalThis.fetch !== 'function') {
39
47
  throw new TypeError(`globalThis.fetch is not available`);
@@ -487,10 +495,10 @@ class Fetcher {
487
495
  retry: { ...defRetryOptions },
488
496
  init: {
489
497
  method: cfg.method || 'GET',
490
- headers: {
491
- 'user-agent': 'fetcher',
498
+ headers: (0, object_util_1._filterNullishValues)({
499
+ 'user-agent': Fetcher.userAgent,
492
500
  ...cfg.headers,
493
- },
501
+ }),
494
502
  credentials: cfg.credentials,
495
503
  redirect: cfg.redirect,
496
504
  },
@@ -532,6 +540,8 @@ class Fetcher {
532
540
  headers: (0, object_util_1._mapKeys)(opt.headers || {}, k => k.toLowerCase()),
533
541
  }),
534
542
  };
543
+ // Because all header values are stringified, so `a: undefined` becomes `undefined` as a string
544
+ (0, object_util_1._filterNullishValues)(req.init.headers, true);
535
545
  // setup url
536
546
  const baseUrl = opt.baseUrl || this.cfg.baseUrl;
537
547
  if (baseUrl) {
package/dist/index.d.ts CHANGED
@@ -86,6 +86,5 @@ export * from './web';
86
86
  export * from './zod/zod.util';
87
87
  export * from './zod/zod.shared.schemas';
88
88
  import { z, ZodSchema, ZodError, ZodIssue } from 'zod';
89
- import { is } from './vendor/is';
90
- export { is, z, ZodSchema, ZodError };
89
+ export { z, ZodSchema, ZodError };
91
90
  export type { ZodIssue };
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ZodError = exports.ZodSchema = exports.z = exports.is = void 0;
3
+ exports.ZodError = exports.ZodSchema = exports.z = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  tslib_1.__exportStar(require("./array/array.util"), exports);
6
6
  tslib_1.__exportStar(require("./define"), exports);
@@ -93,5 +93,3 @@ const zod_1 = require("zod");
93
93
  Object.defineProperty(exports, "z", { enumerable: true, get: function () { return zod_1.z; } });
94
94
  Object.defineProperty(exports, "ZodSchema", { enumerable: true, get: function () { return zod_1.ZodSchema; } });
95
95
  Object.defineProperty(exports, "ZodError", { enumerable: true, get: function () { return zod_1.ZodError; } });
96
- const is_1 = require("./vendor/is");
97
- Object.defineProperty(exports, "is", { enumerable: true, get: function () { return is_1.is; } });
@@ -1,5 +1,6 @@
1
1
  /// <reference lib="dom"/>
2
2
  /// <reference lib="dom.iterable"/>
3
+ var _a;
3
4
  import { isServerSide } from '../env';
4
5
  import { _assertErrorClassOrRethrow } from '../error/assert';
5
6
  import { _anyToError, _anyToErrorObject, _errorLikeToErrorObject } from '../error/error.util';
@@ -60,21 +61,21 @@ export class Fetcher {
60
61
  * Add BeforeRequest hook at the end of the hooks list.
61
62
  */
62
63
  onBeforeRequest(hook) {
63
- var _a;
64
+ var _b;
64
65
  ;
65
- ((_a = this.cfg.hooks).beforeRequest || (_a.beforeRequest = [])).push(hook);
66
+ ((_b = this.cfg.hooks).beforeRequest || (_b.beforeRequest = [])).push(hook);
66
67
  return this;
67
68
  }
68
69
  onAfterResponse(hook) {
69
- var _a;
70
+ var _b;
70
71
  ;
71
- ((_a = this.cfg.hooks).afterResponse || (_a.afterResponse = [])).push(hook);
72
+ ((_b = this.cfg.hooks).afterResponse || (_b.afterResponse = [])).push(hook);
72
73
  return this;
73
74
  }
74
75
  onBeforeRetry(hook) {
75
- var _a;
76
+ var _b;
76
77
  ;
77
- ((_a = this.cfg.hooks).beforeRetry || (_a.beforeRetry = [])).push(hook);
78
+ ((_b = this.cfg.hooks).beforeRetry || (_b.beforeRetry = [])).push(hook);
78
79
  return this;
79
80
  }
80
81
  static create(cfg = {}) {
@@ -120,7 +121,7 @@ export class Fetcher {
120
121
  * Note: responseType defaults to `void`, so, override it if you expect different.
121
122
  */
122
123
  async doFetch(opt) {
123
- var _a, _b;
124
+ var _b, _c;
124
125
  const req = this.normalizeOptions(opt);
125
126
  const { logger } = this.cfg;
126
127
  const { timeoutSeconds, init: { method }, } = req;
@@ -182,8 +183,8 @@ export class Fetcher {
182
183
  // Separate Timeout will be introduced to "download and parse the body"
183
184
  }
184
185
  res.statusFamily = this.getStatusFamily(res);
185
- res.statusCode = (_a = res.fetchResponse) === null || _a === void 0 ? void 0 : _a.status;
186
- if ((_b = res.fetchResponse) === null || _b === void 0 ? void 0 : _b.ok) {
186
+ res.statusCode = (_b = res.fetchResponse) === null || _b === void 0 ? void 0 : _b.status;
187
+ if ((_c = res.fetchResponse) === null || _c === void 0 ? void 0 : _c.ok) {
187
188
  try {
188
189
  // We are applying a separate Timeout (as long as original Timeout for now) to "download and parse the body"
189
190
  await pTimeout(async () => await this.onOkResponse(res), {
@@ -274,7 +275,7 @@ export class Fetcher {
274
275
  return await globalThis.fetch(url, init);
275
276
  }
276
277
  async onNotOkResponse(res) {
277
- var _a, _b;
278
+ var _b, _c;
278
279
  let cause;
279
280
  if (res.err) {
280
281
  // This is only possible on JSON.parse error, or CORS error,
@@ -293,10 +294,10 @@ export class Fetcher {
293
294
  message: 'Fetch failed',
294
295
  data: {},
295
296
  });
296
- const message = [(_a = res.fetchResponse) === null || _a === void 0 ? void 0 : _a.status, res.signature].filter(Boolean).join(' ');
297
+ const message = [(_b = res.fetchResponse) === null || _b === void 0 ? void 0 : _b.status, res.signature].filter(Boolean).join(' ');
297
298
  res.err = new HttpRequestError(message, _filterNullishValues({
298
299
  response: res.fetchResponse,
299
- responseStatusCode: ((_b = res.fetchResponse) === null || _b === void 0 ? void 0 : _b.status) || 0,
300
+ responseStatusCode: ((_c = res.fetchResponse) === null || _c === void 0 ? void 0 : _c.status) || 0,
300
301
  // These properties are provided to be used in e.g custom Sentry error grouping
301
302
  // Actually, disabled now, to avoid unnecessary error printing when both msg and data are printed
302
303
  // Enabled, cause `data` is not printed by default when error is HttpError
@@ -313,7 +314,7 @@ export class Fetcher {
313
314
  await this.processRetry(res);
314
315
  }
315
316
  async processRetry(res) {
316
- var _a;
317
+ var _b;
317
318
  const { retryStatus } = res;
318
319
  if (!this.shouldRetry(res)) {
319
320
  retryStatus.retryStopped = true;
@@ -333,7 +334,7 @@ export class Fetcher {
333
334
  if (res.err && (!retryStatus.retryStopped || res.req.logResponse)) {
334
335
  this.cfg.logger.error([
335
336
  ' <<',
336
- ((_a = res.fetchResponse) === null || _a === void 0 ? void 0 : _a.status) || 0,
337
+ ((_b = res.fetchResponse) === null || _b === void 0 ? void 0 : _b.status) || 0,
337
338
  res.signature,
338
339
  count &&
339
340
  (retryStatus.retryAttempt || !retryStatus.retryStopped) &&
@@ -356,12 +357,12 @@ export class Fetcher {
356
357
  await pDelay(timeout);
357
358
  }
358
359
  getRetryTimeout(res) {
359
- var _a;
360
+ var _b;
360
361
  let timeout = 0;
361
362
  // Handling http 429 with specific retry headers
362
363
  // https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Retry-After
363
364
  if (res.fetchResponse && [429, 503].includes(res.fetchResponse.status)) {
364
- const retryAfterStr = (_a = res.fetchResponse.headers.get('retry-after')) !== null && _a !== void 0 ? _a : res.fetchResponse.headers.get('x-ratelimit-reset');
365
+ const retryAfterStr = (_b = res.fetchResponse.headers.get('retry-after')) !== null && _b !== void 0 ? _b : res.fetchResponse.headers.get('x-ratelimit-reset');
365
366
  if (retryAfterStr) {
366
367
  if (Number(retryAfterStr)) {
367
368
  timeout = Number(retryAfterStr) * 1000;
@@ -391,13 +392,13 @@ export class Fetcher {
391
392
  * statusCode of 0 (or absense of it) will BE retried.
392
393
  */
393
394
  shouldRetry(res) {
394
- var _a, _b, _c, _d, _e;
395
+ var _b, _c, _d, _e, _f;
395
396
  const { retryPost, retry3xx, retry4xx, retry5xx } = res.req;
396
397
  const { method } = res.req.init;
397
398
  if (method === 'POST' && !retryPost)
398
399
  return false;
399
400
  const { statusFamily } = res;
400
- const statusCode = ((_a = res.fetchResponse) === null || _a === void 0 ? void 0 : _a.status) || 0;
401
+ const statusCode = ((_b = res.fetchResponse) === null || _b === void 0 ? void 0 : _b.status) || 0;
401
402
  if (statusFamily === 5 && !retry5xx)
402
403
  return false;
403
404
  if ([408, 429].includes(statusCode)) {
@@ -409,14 +410,14 @@ export class Fetcher {
409
410
  if (statusFamily === 3 && !retry3xx)
410
411
  return false;
411
412
  // should not retry on `unexpected redirect` in error.cause.cause
412
- if ((_e = (_d = (_c = (_b = res.err) === null || _b === void 0 ? void 0 : _b.cause) === null || _c === void 0 ? void 0 : _c.cause) === null || _d === void 0 ? void 0 : _d.message) === null || _e === void 0 ? void 0 : _e.includes('unexpected redirect')) {
413
+ if ((_f = (_e = (_d = (_c = res.err) === null || _c === void 0 ? void 0 : _c.cause) === null || _d === void 0 ? void 0 : _d.cause) === null || _e === void 0 ? void 0 : _e.message) === null || _f === void 0 ? void 0 : _f.includes('unexpected redirect')) {
413
414
  return false;
414
415
  }
415
416
  return true; // default is true
416
417
  }
417
418
  getStatusFamily(res) {
418
- var _a;
419
- const status = (_a = res.fetchResponse) === null || _a === void 0 ? void 0 : _a.status;
419
+ var _b;
420
+ const status = (_b = res.fetchResponse) === null || _b === void 0 ? void 0 : _b.status;
420
421
  if (!status)
421
422
  return;
422
423
  if (status >= 500)
@@ -449,8 +450,8 @@ export class Fetcher {
449
450
  return shortUrl;
450
451
  }
451
452
  normalizeCfg(cfg) {
452
- var _a;
453
- if ((_a = cfg.baseUrl) === null || _a === void 0 ? void 0 : _a.endsWith('/')) {
453
+ var _b;
454
+ if ((_b = cfg.baseUrl) === null || _b === void 0 ? void 0 : _b.endsWith('/')) {
454
455
  console.warn(`Fetcher: baseUrl should not end with slash: ${cfg.baseUrl}`);
455
456
  cfg.baseUrl = cfg.baseUrl.slice(0, cfg.baseUrl.length - 1);
456
457
  }
@@ -477,7 +478,7 @@ export class Fetcher {
477
478
  retry: Object.assign({}, defRetryOptions),
478
479
  init: {
479
480
  method: cfg.method || 'GET',
480
- headers: Object.assign({ 'user-agent': 'fetcher' }, cfg.headers),
481
+ headers: _filterNullishValues(Object.assign({ 'user-agent': Fetcher.userAgent }, cfg.headers)),
481
482
  credentials: cfg.credentials,
482
483
  redirect: cfg.redirect,
483
484
  },
@@ -487,7 +488,7 @@ export class Fetcher {
487
488
  return norm;
488
489
  }
489
490
  normalizeOptions(opt) {
490
- var _a;
491
+ var _b;
491
492
  const req = Object.assign(Object.assign(Object.assign(Object.assign({}, _pick(this.cfg, [
492
493
  'timeoutSeconds',
493
494
  'retryPost',
@@ -503,6 +504,8 @@ export class Fetcher {
503
504
  ])), { started: Date.now() }), _omit(opt, ['method', 'headers', 'credentials'])), { inputUrl: opt.url || '', fullUrl: opt.url || '', retry: Object.assign(Object.assign({}, this.cfg.retry), _filterUndefinedValues(opt.retry || {})), init: _merge(Object.assign(Object.assign({}, this.cfg.init), { headers: Object.assign({}, this.cfg.init.headers), method: opt.method || this.cfg.init.method, credentials: opt.credentials || this.cfg.init.credentials, redirect: opt.redirect || this.cfg.init.redirect || 'follow' }), {
504
505
  headers: _mapKeys(opt.headers || {}, k => k.toLowerCase()),
505
506
  }) });
507
+ // Because all header values are stringified, so `a: undefined` becomes `undefined` as a string
508
+ _filterNullishValues(req.init.headers, true);
506
509
  // setup url
507
510
  const baseUrl = opt.baseUrl || this.cfg.baseUrl;
508
511
  if (baseUrl) {
@@ -540,10 +543,19 @@ export class Fetcher {
540
543
  req.init.body = opt.body;
541
544
  }
542
545
  // Unless `accept` header was already set - set it based on responseType
543
- (_a = req.init.headers)['accept'] || (_a['accept'] = acceptByResponseType[req.responseType]);
546
+ (_b = req.init.headers)['accept'] || (_b['accept'] = acceptByResponseType[req.responseType]);
544
547
  return req;
545
548
  }
546
549
  }
550
+ _a = Fetcher;
551
+ /**
552
+ * Included in UserAgent when run in Node.
553
+ * In the browser it's not included, as we want "browser own" UserAgent to be included instead.
554
+ *
555
+ * Version is to be incremented every time a difference in behaviour (or a bugfix) is done.
556
+ */
557
+ Fetcher.VERSION = 1;
558
+ Fetcher.userAgent = isServerSide() ? `fetcher${_a.VERSION}` : undefined;
547
559
  export function getFetcher(cfg = {}) {
548
560
  return Fetcher.create(cfg);
549
561
  }
package/dist-esm/index.js CHANGED
@@ -86,5 +86,4 @@ export * from './web';
86
86
  export * from './zod/zod.util';
87
87
  export * from './zod/zod.shared.schemas';
88
88
  import { z, ZodSchema, ZodError } from 'zod';
89
- import { is } from './vendor/is';
90
- export { is, z, ZodSchema, ZodError };
89
+ export { z, ZodSchema, ZodError };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@naturalcycles/js-lib",
3
- "version": "14.170.0",
3
+ "version": "14.171.0",
4
4
  "scripts": {
5
5
  "prepare": "husky install",
6
6
  "build-prod": "build-prod-esm-cjs",
@@ -58,6 +58,15 @@ const defRetryOptions: FetcherRetryOptions = {
58
58
  * Works in both Browser and Node, using `globalThis.fetch`.
59
59
  */
60
60
  export class Fetcher {
61
+ /**
62
+ * Included in UserAgent when run in Node.
63
+ * In the browser it's not included, as we want "browser own" UserAgent to be included instead.
64
+ *
65
+ * Version is to be incremented every time a difference in behaviour (or a bugfix) is done.
66
+ */
67
+ static readonly VERSION = 1
68
+ static readonly userAgent = isServerSide() ? `fetcher${this.VERSION}` : undefined
69
+
61
70
  private constructor(cfg: FetcherCfg & FetcherOptions = {}) {
62
71
  if (typeof globalThis.fetch !== 'function') {
63
72
  throw new TypeError(`globalThis.fetch is not available`)
@@ -594,10 +603,10 @@ export class Fetcher {
594
603
  retry: { ...defRetryOptions },
595
604
  init: {
596
605
  method: cfg.method || 'GET',
597
- headers: {
598
- 'user-agent': 'fetcher',
606
+ headers: _filterNullishValues({
607
+ 'user-agent': Fetcher.userAgent,
599
608
  ...cfg.headers,
600
- },
609
+ }),
601
610
  credentials: cfg.credentials,
602
611
  redirect: cfg.redirect,
603
612
  },
@@ -647,6 +656,10 @@ export class Fetcher {
647
656
  } satisfies RequestInit,
648
657
  ),
649
658
  }
659
+
660
+ // Because all header values are stringified, so `a: undefined` becomes `undefined` as a string
661
+ _filterNullishValues(req.init.headers, true)
662
+
650
663
  // setup url
651
664
  const baseUrl = opt.baseUrl || this.cfg.baseUrl
652
665
  if (baseUrl) {
package/src/index.ts CHANGED
@@ -86,7 +86,6 @@ export * from './web'
86
86
  export * from './zod/zod.util'
87
87
  export * from './zod/zod.shared.schemas'
88
88
  import { z, ZodSchema, ZodError, ZodIssue } from 'zod'
89
- import { is } from './vendor/is'
90
89
 
91
- export { is, z, ZodSchema, ZodError }
90
+ export { z, ZodSchema, ZodError }
92
91
  export type { ZodIssue }
@@ -1,226 +0,0 @@
1
- /// <reference types="node" />
2
- /// <reference types="node" />
3
- /// <reference types="node" />
4
- /// <reference lib="es2018" />
5
- /// <reference lib="dom" />
6
- import { Class, ObservableLike, Primitive, TypedArray } from '../typeFest';
7
- declare const objectTypeNames: readonly ["Function", "Generator", "AsyncGenerator", "GeneratorFunction", "AsyncGeneratorFunction", "AsyncFunction", "Observable", "Array", "Buffer", "Object", "RegExp", "Date", "Error", "Map", "Set", "WeakMap", "WeakSet", "ArrayBuffer", "SharedArrayBuffer", "DataView", "Promise", "URL", "FormData", "URLSearchParams", "HTMLElement", "Int8Array", "Uint8Array", "Uint8ClampedArray", "Int16Array", "Uint16Array", "Int32Array", "Uint32Array", "Float32Array", "Float64Array", "BigInt64Array", "BigUint64Array"];
8
- type ObjectTypeName = (typeof objectTypeNames)[number];
9
- declare const primitiveTypeNames: readonly ["null", "undefined", "string", "number", "bigint", "boolean", "symbol"];
10
- type PrimitiveTypeName = (typeof primitiveTypeNames)[number];
11
- export type TypeName = ObjectTypeName | PrimitiveTypeName;
12
- export declare function is(value: unknown): TypeName;
13
- export declare namespace is {
14
- var undefined: (value: unknown) => value is undefined;
15
- var string: (value: unknown) => value is string;
16
- var number: (value: unknown) => value is number;
17
- var bigint: (value: unknown) => value is bigint;
18
- var function_: (value: unknown) => value is Function;
19
- var null_: (value: unknown) => value is null;
20
- var class_: (value: unknown) => value is Class;
21
- var boolean: (value: unknown) => value is boolean;
22
- var symbol: (value: unknown) => value is symbol;
23
- var numericString: (value: unknown) => value is string;
24
- var array: <T = unknown>(value: unknown, assertion?: ((value: T) => value is T) | undefined) => value is T[];
25
- var buffer: (value: unknown) => value is Buffer;
26
- var nullOrUndefined: (value: unknown) => value is null | undefined;
27
- var object: (value: unknown) => value is object;
28
- var iterable: <T = unknown>(value: unknown) => value is IterableIterator<T>;
29
- var asyncIterable: <T = unknown>(value: unknown) => value is AsyncIterableIterator<T>;
30
- var generator: (value: unknown) => value is Generator<unknown, any, unknown>;
31
- var asyncGenerator: (value: unknown) => value is AsyncGenerator<unknown, any, unknown>;
32
- var nativePromise: <T = unknown>(value: unknown) => value is Promise<T>;
33
- var promise: <T = unknown>(value: unknown) => value is Promise<T>;
34
- var generatorFunction: (value: unknown) => value is GeneratorFunction;
35
- var asyncGeneratorFunction: (value: unknown) => value is (...args: any[]) => Promise<unknown>;
36
- var asyncFunction: <T = unknown>(value: unknown) => value is (...args: any[]) => Promise<T>;
37
- var boundFunction: (value: unknown) => value is Function;
38
- var regExp: (value: unknown) => value is RegExp;
39
- var date: (value: unknown) => value is Date;
40
- var error: (value: unknown) => value is Error;
41
- var map: <Key = unknown, Value = unknown>(value: unknown) => value is Map<Key, Value>;
42
- var set: <T = unknown>(value: unknown) => value is Set<T>;
43
- var weakMap: <Key extends object = object, Value = unknown>(value: unknown) => value is WeakMap<Key, Value>;
44
- var weakSet: (value: unknown) => value is WeakSet<object>;
45
- var int8Array: (value: unknown) => value is Int8Array;
46
- var uint8Array: (value: unknown) => value is Uint8Array;
47
- var uint8ClampedArray: (value: unknown) => value is Uint8ClampedArray;
48
- var int16Array: (value: unknown) => value is Int16Array;
49
- var uint16Array: (value: unknown) => value is Uint16Array;
50
- var int32Array: (value: unknown) => value is Int32Array;
51
- var uint32Array: (value: unknown) => value is Uint32Array;
52
- var float32Array: (value: unknown) => value is Float32Array;
53
- var float64Array: (value: unknown) => value is Float64Array;
54
- var bigInt64Array: (value: unknown) => value is BigInt64Array;
55
- var bigUint64Array: (value: unknown) => value is BigUint64Array;
56
- var arrayBuffer: (value: unknown) => value is ArrayBuffer;
57
- var sharedArrayBuffer: (value: unknown) => value is SharedArrayBuffer;
58
- var dataView: (value: unknown) => value is DataView;
59
- var directInstanceOf: <T>(instance: unknown, class_: Class<T>) => instance is T;
60
- var urlInstance: (value: unknown) => value is URL;
61
- var urlString: (value: unknown) => value is string;
62
- var truthy: (value: unknown) => boolean;
63
- var falsy: (value: unknown) => boolean;
64
- var nan: (value: unknown) => boolean;
65
- var primitive: (value: unknown) => value is Primitive;
66
- var integer: (value: unknown) => value is number;
67
- var safeInteger: (value: unknown) => value is number;
68
- var plainObject: <Value = unknown>(value: unknown) => value is Record<PropertyKey, Value>;
69
- var typedArray: (value: unknown) => value is TypedArray;
70
- var arrayLike: <T = unknown>(value: unknown) => value is ArrayLike<T>;
71
- var inRange: (value: number, range: number | number[]) => value is number;
72
- var domElement: (value: unknown) => value is HTMLElement;
73
- var observable: (value: unknown) => value is ObservableLike;
74
- var nodeStream: (value: unknown) => value is NodeStream;
75
- var infinite: (value: unknown) => value is number;
76
- var evenInteger: (value: number) => value is number;
77
- var oddInteger: (value: number) => value is number;
78
- var emptyArray: (value: unknown) => value is never[];
79
- var nonEmptyArray: (value: unknown) => value is unknown[];
80
- var emptyString: (value: unknown) => value is "";
81
- var nonEmptyString: (value: unknown) => value is string;
82
- var emptyStringOrWhitespace: (value: unknown) => value is string;
83
- var emptyObject: <Key extends string | number | symbol = string>(value: unknown) => value is Record<Key, never>;
84
- var nonEmptyObject: <Key extends string | number | symbol = string, Value = unknown>(value: unknown) => value is Record<Key, Value>;
85
- var emptySet: (value: unknown) => value is Set<never>;
86
- var nonEmptySet: <T = unknown>(value: unknown) => value is Set<T>;
87
- var emptyMap: (value: unknown) => value is Map<never, never>;
88
- var nonEmptyMap: <Key = unknown, Value = unknown>(value: unknown) => value is Map<Key, Value>;
89
- var propertyKey: (value: unknown) => value is PropertyKey;
90
- var formData: (value: unknown) => value is FormData;
91
- var urlSearchParams: (value: unknown) => value is URLSearchParams;
92
- var any: (predicate: Predicate | Predicate[], ...values: unknown[]) => boolean;
93
- var all: (predicate: Predicate, ...values: unknown[]) => boolean;
94
- }
95
- export interface ArrayLike<T> {
96
- readonly [index: number]: T;
97
- readonly length: number;
98
- }
99
- export interface NodeStream extends NodeJS.EventEmitter {
100
- pipe<T extends NodeJS.WritableStream>(destination: T, options?: {
101
- end?: boolean;
102
- }): T;
103
- }
104
- export type Predicate = (value: unknown) => boolean;
105
- export declare const enum AssertionTypeDescription {
106
- class_ = "Class",
107
- numericString = "string with a number",
108
- nullOrUndefined = "null or undefined",
109
- iterable = "Iterable",
110
- asyncIterable = "AsyncIterable",
111
- nativePromise = "native Promise",
112
- urlString = "string with a URL",
113
- truthy = "truthy",
114
- falsy = "falsy",
115
- nan = "NaN",
116
- primitive = "primitive",
117
- integer = "integer",
118
- safeInteger = "integer",
119
- plainObject = "plain object",
120
- arrayLike = "array-like",
121
- typedArray = "TypedArray",
122
- domElement = "HTMLElement",
123
- nodeStream = "Node.js Stream",
124
- infinite = "infinite number",
125
- emptyArray = "empty array",
126
- nonEmptyArray = "non-empty array",
127
- emptyString = "empty string",
128
- nonEmptyString = "non-empty string",
129
- emptyStringOrWhitespace = "empty string or whitespace",
130
- emptyObject = "empty object",
131
- nonEmptyObject = "non-empty object",
132
- emptySet = "empty set",
133
- nonEmptySet = "non-empty set",
134
- emptyMap = "empty map",
135
- nonEmptyMap = "non-empty map",
136
- evenInteger = "even integer",
137
- oddInteger = "odd integer",
138
- directInstanceOf = "T",
139
- inRange = "in range",
140
- any = "predicate returns truthy for any value",
141
- all = "predicate returns truthy for all values"
142
- }
143
- interface Assert {
144
- undefined: (value: unknown) => asserts value is undefined;
145
- string: (value: unknown) => asserts value is string;
146
- number: (value: unknown) => asserts value is number;
147
- bigint: (value: unknown) => asserts value is bigint;
148
- function_: (value: unknown) => asserts value is Function;
149
- null_: (value: unknown) => asserts value is null;
150
- class_: (value: unknown) => asserts value is Class;
151
- boolean: (value: unknown) => asserts value is boolean;
152
- symbol: (value: unknown) => asserts value is symbol;
153
- numericString: (value: unknown) => asserts value is string;
154
- array: <T = unknown>(value: unknown, assertion?: (element: unknown) => asserts element is T) => asserts value is T[];
155
- buffer: (value: unknown) => asserts value is Buffer;
156
- nullOrUndefined: (value: unknown) => asserts value is null | undefined;
157
- object: <Key extends keyof any = string, Value = unknown>(value: unknown) => asserts value is Record<Key, Value>;
158
- iterable: <T = unknown>(value: unknown) => asserts value is Iterable<T>;
159
- asyncIterable: <T = unknown>(value: unknown) => asserts value is AsyncIterable<T>;
160
- generator: (value: unknown) => asserts value is Generator;
161
- asyncGenerator: (value: unknown) => asserts value is AsyncGenerator;
162
- nativePromise: <T = unknown>(value: unknown) => asserts value is Promise<T>;
163
- promise: <T = unknown>(value: unknown) => asserts value is Promise<T>;
164
- generatorFunction: (value: unknown) => asserts value is GeneratorFunction;
165
- asyncGeneratorFunction: (value: unknown) => asserts value is AsyncGeneratorFunction;
166
- asyncFunction: (value: unknown) => asserts value is Function;
167
- boundFunction: (value: unknown) => asserts value is Function;
168
- regExp: (value: unknown) => asserts value is RegExp;
169
- date: (value: unknown) => asserts value is Date;
170
- error: (value: unknown) => asserts value is Error;
171
- map: <Key = unknown, Value = unknown>(value: unknown) => asserts value is Map<Key, Value>;
172
- set: <T = unknown>(value: unknown) => asserts value is Set<T>;
173
- weakMap: <Key extends object = object, Value = unknown>(value: unknown) => asserts value is WeakMap<Key, Value>;
174
- weakSet: <T extends object = object>(value: unknown) => asserts value is WeakSet<T>;
175
- int8Array: (value: unknown) => asserts value is Int8Array;
176
- uint8Array: (value: unknown) => asserts value is Uint8Array;
177
- uint8ClampedArray: (value: unknown) => asserts value is Uint8ClampedArray;
178
- int16Array: (value: unknown) => asserts value is Int16Array;
179
- uint16Array: (value: unknown) => asserts value is Uint16Array;
180
- int32Array: (value: unknown) => asserts value is Int32Array;
181
- uint32Array: (value: unknown) => asserts value is Uint32Array;
182
- float32Array: (value: unknown) => asserts value is Float32Array;
183
- float64Array: (value: unknown) => asserts value is Float64Array;
184
- bigInt64Array: (value: unknown) => asserts value is BigInt64Array;
185
- bigUint64Array: (value: unknown) => asserts value is BigUint64Array;
186
- arrayBuffer: (value: unknown) => asserts value is ArrayBuffer;
187
- sharedArrayBuffer: (value: unknown) => asserts value is SharedArrayBuffer;
188
- dataView: (value: unknown) => asserts value is DataView;
189
- urlInstance: (value: unknown) => asserts value is URL;
190
- urlString: (value: unknown) => asserts value is string;
191
- truthy: (value: unknown) => asserts value is unknown;
192
- falsy: (value: unknown) => asserts value is unknown;
193
- nan: (value: unknown) => asserts value is unknown;
194
- primitive: (value: unknown) => asserts value is Primitive;
195
- integer: (value: unknown) => asserts value is number;
196
- safeInteger: (value: unknown) => asserts value is number;
197
- plainObject: <Value = unknown>(value: unknown) => asserts value is Record<PropertyKey, Value>;
198
- typedArray: (value: unknown) => asserts value is TypedArray;
199
- arrayLike: <T = unknown>(value: unknown) => asserts value is ArrayLike<T>;
200
- domElement: (value: unknown) => asserts value is HTMLElement;
201
- observable: (value: unknown) => asserts value is ObservableLike;
202
- nodeStream: (value: unknown) => asserts value is NodeStream;
203
- infinite: (value: unknown) => asserts value is number;
204
- emptyArray: (value: unknown) => asserts value is never[];
205
- nonEmptyArray: (value: unknown) => asserts value is unknown[];
206
- emptyString: (value: unknown) => asserts value is '';
207
- nonEmptyString: (value: unknown) => asserts value is string;
208
- emptyStringOrWhitespace: (value: unknown) => asserts value is string;
209
- emptyObject: <Key extends keyof any = string>(value: unknown) => asserts value is Record<Key, never>;
210
- nonEmptyObject: <Key extends keyof any = string, Value = unknown>(value: unknown) => asserts value is Record<Key, Value>;
211
- emptySet: (value: unknown) => asserts value is Set<never>;
212
- nonEmptySet: <T = unknown>(value: unknown) => asserts value is Set<T>;
213
- emptyMap: (value: unknown) => asserts value is Map<never, never>;
214
- nonEmptyMap: <Key = unknown, Value = unknown>(value: unknown) => asserts value is Map<Key, Value>;
215
- propertyKey: (value: unknown) => asserts value is PropertyKey;
216
- formData: (value: unknown) => asserts value is FormData;
217
- urlSearchParams: (value: unknown) => asserts value is URLSearchParams;
218
- evenInteger: (value: number) => asserts value is number;
219
- oddInteger: (value: number) => asserts value is number;
220
- directInstanceOf: <T>(instance: unknown, class_: Class<T>) => asserts instance is T;
221
- inRange: (value: number, range: number | number[]) => asserts value is number;
222
- any: (predicate: Predicate | Predicate[], ...values: unknown[]) => void | never;
223
- all: (predicate: Predicate, ...values: unknown[]) => void | never;
224
- }
225
- export declare const assert: Assert;
226
- export {};