@rimbu/base 2.0.0 → 2.0.2

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,62 @@
1
+ /**
2
+ * Matches any type of function
3
+ */
4
+ export type AnyFunc = (...args: any[]) => any;
5
+ /**
6
+ * Gives true if the given type T is a function, false otherwise.
7
+ * @typeparam T - the input type
8
+ */
9
+ export type IsAnyFunc<T> = AnyFunc extends T ? true : false;
10
+ /**
11
+ * A predicate type for any record that resolves to true if any of the record
12
+ * properties is a function, false otherwise.
13
+ * This is useful to have a coarse discrimination between pure data objects and class instances.
14
+ * @typeparam T - the input type
15
+ */
16
+ export type IsObjWithoutFunctions<T> = AnyFunc extends T[keyof T] ? false : true;
17
+ /**
18
+ * A predicate type that resolves to true if the given type satisfies:
19
+ * - it is an object type (not a primitive)
20
+ * - it is not a function
21
+ * - it is not iterable
22
+ * - it does not have any properties that are functions
23
+ * Otherwise, it resolves to false
24
+ * @typeparam T - the input type
25
+ */
26
+ export type IsPlainObj<T> = T extends null | undefined | number | string | boolean | bigint | symbol | AnyFunc | Iterable<any> | AsyncIterable<any> ? false : IsObjWithoutFunctions<T>;
27
+ /**
28
+ * Utility type that will only accept objects that are considered 'plain objects' according
29
+ * to the `IsPlainObj` predicate type.
30
+ * @typeparam T - the value type to test
31
+ */
32
+ export type PlainObj<T> = IsPlainObj<T> extends true ? T : never;
33
+ /**
34
+ * Utility type that will only return true if the input type T is equal to `any`.
35
+ * @typeparam T - the value type to test
36
+ */
37
+ export type IsAny<T> = 0 extends 1 & T ? true : false;
38
+ /**
39
+ * Utility type that will only return true if the input type T is a (readonly) array.
40
+ * @typeparm T - the value type to test
41
+ */
42
+ export type IsArray<T> = T extends readonly any[] ? true : false;
43
+ /**
44
+ * Utility type to exclude any types that are iterable. Useful in cases where
45
+ * plain objects are required as inputs but not arrays.
46
+ */
47
+ export type NotIterable = {
48
+ [Symbol.iterator]?: never;
49
+ };
50
+ /**
51
+ * Companion function to the `IsRecord<T>` type that checks whether the given object is a pure
52
+ * data object.
53
+ * @param obj - the object to check
54
+ * @returns true if the given object is a pure data object
55
+ * @note does not check whether a record's properties are not functions
56
+ */
57
+ export declare function isPlainObj(obj: any): obj is object;
58
+ /**
59
+ * Returns true if the given object is Iterable
60
+ * @param obj - the object to check
61
+ */
62
+ export declare function isIterable(obj: any): obj is Iterable<unknown>;
@@ -0,0 +1,16 @@
1
+ import { ErrBase } from '@rimbu/common';
2
+ export declare class EmptyCollectionAssumedNonEmptyError extends ErrBase.CustomError {
3
+ constructor();
4
+ }
5
+ export declare class ModifiedBuilderWhileLoopingOverItError extends ErrBase.CustomError {
6
+ constructor();
7
+ }
8
+ export declare class InvalidStateError extends ErrBase.CustomError {
9
+ constructor();
10
+ }
11
+ export declare class InvalidUsageError extends ErrBase.CustomError {
12
+ }
13
+ export declare function throwEmptyCollectionAssumedNonEmptyError(): never;
14
+ export declare function throwModifiedBuilderWhileLoopingOverItError(): never;
15
+ export declare function throwInvalidStateError(): never;
16
+ export declare function throwInvalidUsageError(msg: string): never;
@@ -0,0 +1,2 @@
1
+ export declare const Token: unique symbol;
2
+ export type Token = typeof Token;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rimbu/base",
3
- "version": "2.0.0",
3
+ "version": "2.0.2",
4
4
  "description": "Utilities to implement Rimbu collections",
5
5
  "keywords": [
6
6
  "array",
@@ -29,14 +29,18 @@
29
29
  "type": "module",
30
30
  "main": "./dist/cjs/index.cjs",
31
31
  "module": "./dist/esm/index.mjs",
32
- "types": "./dist/types/index.d.mts",
32
+ "types": "./dist/cjs/index.d.cts",
33
33
  "exports": {
34
34
  ".": {
35
- "types": "./dist/types/index.d.mts",
36
- "bun": "./dist/bun/index.mts",
37
- "import": "./dist/esm/index.mjs",
38
- "require": "./dist/cjs/index.cjs",
39
- "default": "./dist/esm/index.mjs"
35
+ "bun": "./dist/bun/main/index.mts",
36
+ "import": {
37
+ "types": "./dist/esm/index.d.mts",
38
+ "default": "./dist/esm/index.mjs"
39
+ },
40
+ "require": {
41
+ "types": "./dist/cjs/index.d.cts",
42
+ "default": "./dist/cjs/index.cjs"
43
+ }
40
44
  }
41
45
  },
42
46
  "files": [
@@ -46,15 +50,17 @@
46
50
  "scripts": {
47
51
  "build": "yarn clean && yarn bundle",
48
52
  "build:deno": "yarn bundle:deno-prepare && yarn bundle:deno-convert && yarn bundle:deno-move && yarn bundle:deno-clean",
49
- "bundle": "yarn bundle:cjs && yarn bundle:esm && yarn bundle:types && yarn bundle:bun",
50
- "bundle:bun": "node ../../config/bunnify.mjs",
51
- "bundle:cjs": "tsup src --format cjs --clean -d dist/cjs --loader '.mts=ts'",
53
+ "bundle": "yarn bundle:cjs && yarn bundle:esm && yarn bundle:bun",
54
+ "bundle:bun": "node ../../config/bunnify.mjs -mode bun",
55
+ "bundle:cjs": "yarn bundle:cjs-prepare && yarn bundle:cjs-build && yarn bundle:cjs-clean",
56
+ "bundle:cjs-prepare": "node ../../config/bunnify.mjs -mode cjs",
57
+ "bundle:cjs-build": "tsc -p tsconfig.cjs.json",
58
+ "bundle:cjs-clean": "rimraf _cjs_prepare",
52
59
  "bundle:deno-prepare": "node ../../config/prepare-denoify.mjs",
53
60
  "bundle:deno-convert": "denoify --src _deno_prepare/src",
54
61
  "bundle:deno-move": "rimraf ../../deno_dist/base && mv deno_dist ../../deno_dist/base",
55
62
  "bundle:deno-clean": "rimraf _deno_prepare",
56
63
  "bundle:esm": "tsc --p tsconfig.esm.json",
57
- "bundle:types": "tsc --p tsconfig.types.json",
58
64
  "clean": "rimraf dist",
59
65
  "format": "yarn format:base --write",
60
66
  "format:base": "prettier \"{!CHANGELOG.md}|**/**/*.{ts,tsx,js,mts,mjs,json,md}\"",
@@ -67,10 +73,10 @@
67
73
  "typecheck": "tsc"
68
74
  },
69
75
  "dependencies": {
70
- "@rimbu/common": "^2.0.0"
76
+ "@rimbu/common": "^2.0.2"
71
77
  },
72
78
  "publishConfig": {
73
79
  "access": "public"
74
80
  },
75
- "gitHead": "d107c858cf84cb27544685cef981067f2fe1612d"
81
+ "gitHead": "f18ddf964507dbd10790da3cd4deef8f455a178e"
76
82
  }
File without changes
File without changes
File without changes
File without changes
File without changes