@helpers4/observable 3.1.8 → 3.1.10
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/README.md +3 -1
- package/lib/index.js +4 -8
- package/lib/index.js.map +1 -1
- package/llms.txt +1 -1
- package/meta/api.json +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -41,6 +41,7 @@ A set of helpers for working with URLs.
|
|
|
41
41
|
- [node](../node)
|
|
42
42
|
- [number](../number)
|
|
43
43
|
- [object](../object)
|
|
44
|
+
- [package](../package)
|
|
44
45
|
- [promise](../promise)
|
|
45
46
|
- [set](../set)
|
|
46
47
|
- [string](../string)
|
|
@@ -57,7 +58,7 @@ A set of helpers for working with URLs.
|
|
|
57
58
|
|------|---------|-------------|-------------|
|
|
58
59
|
| animation | [@helpers4/animation](https://www.npmjs.com/package/@helpers4/animation) | [Source](https://github.com/helpers4/helpers4/tree/main/helpers/animation) | Timing and interpolation for animations |
|
|
59
60
|
| array | [@helpers4/array](https://www.npmjs.com/package/@helpers4/array) | [Source](https://github.com/helpers4/helpers4/tree/main/helpers/array) | Array manipulation utilities |
|
|
60
|
-
| binary | [@helpers4/binary](https://www.npmjs.com/package/@helpers4/binary) | [Source](https://github.com/helpers4/helpers4/tree/main/helpers/binary) | Read and
|
|
61
|
+
| binary | [@helpers4/binary](https://www.npmjs.com/package/@helpers4/binary) | [Source](https://github.com/helpers4/helpers4/tree/main/helpers/binary) | Read, write and identify binary formats |
|
|
61
62
|
| browser | [@helpers4/browser](https://www.npmjs.com/package/@helpers4/browser) | [Source](https://github.com/helpers4/helpers4/tree/main/helpers/browser) | Browser-specific utilities |
|
|
62
63
|
| ci | [@helpers4/ci](https://www.npmjs.com/package/@helpers4/ci) | [Source](https://github.com/helpers4/helpers4/tree/main/helpers/ci) | CI/CD workflow status utilities |
|
|
63
64
|
| color | [@helpers4/color](https://www.npmjs.com/package/@helpers4/color) | [Source](https://github.com/helpers4/helpers4/tree/main/helpers/color) | Color conversion and validation utilities |
|
|
@@ -77,6 +78,7 @@ A set of helpers for working with URLs.
|
|
|
77
78
|
| number | [@helpers4/number](https://www.npmjs.com/package/@helpers4/number) | [Source](https://github.com/helpers4/helpers4/tree/main/helpers/number) | Number utility functions and validation |
|
|
78
79
|
| object | [@helpers4/object](https://www.npmjs.com/package/@helpers4/object) | [Source](https://github.com/helpers4/helpers4/tree/main/helpers/object) | Object manipulation utilities |
|
|
79
80
|
| observable | [@helpers4/observable](https://www.npmjs.com/package/@helpers4/observable) | [Source](https://github.com/helpers4/helpers4/tree/main/helpers/observable) | Observable utilities and combinators |
|
|
81
|
+
| package | [@helpers4/package](https://www.npmjs.com/package/@helpers4/package) | [Source](https://github.com/helpers4/helpers4/tree/main/helpers/package) | Package metadata parsers |
|
|
80
82
|
| promise | [@helpers4/promise](https://www.npmjs.com/package/@helpers4/promise) | [Source](https://github.com/helpers4/helpers4/tree/main/helpers/promise) | Promise utilities and error handling |
|
|
81
83
|
| set | [@helpers4/set](https://www.npmjs.com/package/@helpers4/set) | [Source](https://github.com/helpers4/helpers4/tree/main/helpers/set) | Native Set manipulation utilities |
|
|
82
84
|
| string | [@helpers4/string](https://www.npmjs.com/package/@helpers4/string) | [Source](https://github.com/helpers4/helpers4/tree/main/helpers/string) | String manipulation and formatting utilities |
|
package/lib/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { combineLatest as combineLatest$1, map, of } from "rxjs";
|
|
2
|
-
|
|
2
|
+
// helpers/observable/combine.ts
|
|
3
3
|
/**
|
|
4
4
|
* This file is part of helpers4.
|
|
5
5
|
* Copyright (C) 2025 baxyz
|
|
@@ -25,8 +25,7 @@ function combine(source1, source2, map$1, options) {
|
|
|
25
25
|
if (options?.preTreatment) return combineLatest$1([source1, source2]).pipe(options.preTreatment, map(map$1));
|
|
26
26
|
else return combineLatest$1([source1, source2]).pipe(map(map$1));
|
|
27
27
|
}
|
|
28
|
-
|
|
29
|
-
//#region helpers/guard/isDefined.ts
|
|
28
|
+
// helpers/guard/isDefined.ts
|
|
30
29
|
/**
|
|
31
30
|
* Checks if a value is defined (not undefined nor null).
|
|
32
31
|
* This is the inverse of {@link isNullish}.
|
|
@@ -54,8 +53,7 @@ function combine(source1, source2, map$1, options) {
|
|
|
54
53
|
function isDefined(value) {
|
|
55
54
|
return value !== void 0 && value !== null;
|
|
56
55
|
}
|
|
57
|
-
|
|
58
|
-
//#region helpers/observable/combineLatest.ts
|
|
56
|
+
// helpers/observable/combineLatest.ts
|
|
59
57
|
/**
|
|
60
58
|
* This file is part of helpers4.
|
|
61
59
|
* Copyright (C) 2025 baxyz
|
|
@@ -95,8 +93,7 @@ function combineLatest(input) {
|
|
|
95
93
|
return Object.keys(filtered).length ? combineLatest$1(filtered) : of({});
|
|
96
94
|
}
|
|
97
95
|
}
|
|
98
|
-
|
|
99
|
-
//#region helpers/observable/isObservable.ts
|
|
96
|
+
// helpers/observable/isObservable.ts
|
|
100
97
|
/**
|
|
101
98
|
* Checks if a value is an RxJS Observable or any compatible observable.
|
|
102
99
|
*
|
|
@@ -117,7 +114,6 @@ function combineLatest(input) {
|
|
|
117
114
|
function isObservable(value) {
|
|
118
115
|
return value !== null && typeof value === "object" && typeof value["subscribe"] === "function" && typeof value["pipe"] === "function";
|
|
119
116
|
}
|
|
120
|
-
//#endregion
|
|
121
117
|
export { combine, combineLatest, isObservable };
|
|
122
118
|
|
|
123
119
|
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["combineLatestOperator","mapOperator","map","combineLatestOperator"],"sources":["../../../helpers/observable/combine.ts","../../../helpers/guard/isDefined.ts","../../../helpers/observable/combineLatest.ts","../../../helpers/observable/isObservable.ts"],"sourcesContent":["/**\n * This file is part of helpers4.\n * Copyright (C) 2025 baxyz\n * SPDX-License-Identifier: LGPL-3.0-or-later\n */\n\n/*\n * This program is under the terms of the GNU Lesser General Public License version 3\n * The full license information can be found in LICENSE in the root directory of this project.\n */\nimport {\n Observable,\n OperatorFunction,\n combineLatest as combineLatestOperator,\n map as mapOperator,\n} from \"rxjs\";\n\n\ntype combineOptions<T, U> = {\n readonly preTreatment?: OperatorFunction<readonly [T, U], readonly [T, U]>;\n};\n\n/**\n * Combine two observables with a map function and an optional pre-treatment.\n *\n * Note: you can use the pre-treatment to add a filter, a distinctUntilChanged,\n * any other operator that can be used in a pipe, or even an `UntilDestroy`\n * operator.\n *\n * @param source1 first source of data\n * @param source2 second source of data\n * @param map way to combine data\n * @param options options for the combineLatest operator\n * @returns an observable that emits the result of the map function\n * @see combineLatestOperator\n * @see mapOperator\n * @since 1.0.0\n */\nexport function combine<T, U, R>(\n source1: Observable<T>,\n source2: Observable<U>,\n map: (c: readonly [T, U]) => R,\n options?: combineOptions<T, U>\n): Observable<R> {\n if (options?.preTreatment) {\n return combineLatestOperator([source1, source2]).pipe(\n options.preTreatment,\n mapOperator(map)\n );\n } else {\n return combineLatestOperator([source1, source2]).pipe(mapOperator(map));\n }\n}\n","/**\n * This file is part of helpers4.\n * Copyright (C) 2025 baxyz\n * SPDX-License-Identifier: LGPL-3.0-or-later\n */\n\nimport type { Maybe } from '../type/Maybe';\n\n/**\n * Checks if a value is defined (not undefined nor null).\n * This is the inverse of {@link isNullish}.\n *\n * Use as a type-safe filter callback to remove `null`/`undefined` from arrays.\n *\n * @param value - The value to check\n * @returns True if value is not undefined nor null\n * @example\n * isDefined(42) // => true\n * isDefined('') // => true (empty string is defined)\n * isDefined(null) // => false\n * isDefined(undefined) // => false\n *\n * @example\n * // Type-safe alternative to filter out null/undefined\n * const items: (string | null | undefined)[] = ['a', null, 'b', undefined];\n * const result = items.filter(isDefined);\n * // => ['a', 'b'] with type string[]\n *\n * @see {@link isNullish} for the inverse check\n * @see {@link isTruthy} to also filter out `0`, `\"\"`, `false`, and `NaN`\n * @since 2.0.0\n */\nexport function isDefined<T>(value: Maybe<T>): value is T {\n return value !== undefined && value !== null;\n}\n","/**\n * This file is part of helpers4.\n * Copyright (C) 2025 baxyz\n * SPDX-License-Identifier: LGPL-3.0-or-later\n */\n\n/*\n * This program is under the terms of the GNU Lesser General Public License version 3\n * The full license information can be found in LICENSE in the root directory of this project.\n */\nimport {\n Observable,\n ObservableInput,\n ObservableInputTuple,\n ObservedValueOf,\n combineLatest as combineLatestOperator,\n of,\n} from \"rxjs\";\nimport { isDefined } from '../guard/isDefined';\n\n// combineLatest([a, b, c])\nexport function combineLatest<A extends readonly unknown[]>(\n sources: readonly [...ObservableInputTuple<A>]\n): Observable<A>;\n\n// combineLatest({a, b, c})\nexport function combineLatest<T extends Record<string, ObservableInput<unknown>>>(\n sourcesObject: T\n): Observable<{ [K in keyof T]: ObservedValueOf<T[K]> }>;\n\n/**\n * Combines multiple Observables to create an Observable whose values are\n * calculated from the latest values of each of its input Observables.\n *\n * This method relies on {@link combineLatestOperator} of rxjs.\n *\n * The main difference with {@link combineLatestOperator} is in case of empty parameters.\n * If the parameter is empty (empty array or empty object), the result will be\n * also empty.\n *\n * ATTENTION: this version doesn't support `scheduler` nor `mapper` as last\n * argument like in {@link combineLatestOperator}.\n *\n * @see {@link combineLatestOperator}\n * @see {@link combineLatestAll}\n * @see {@link merge}\n * @see {@link withLatestFrom}\n *\n * @param {ObservableInput} [observables] An array of input Observables to combine with each other.\n * An array of Observables must be given as the first argument.\n * @returns {Observable} An Observable of projected values from the most recent\n * values from each input Observable, or an array of the most recent values from\n * each input Observable.\n * @since 1.0.0\n */\nexport function combineLatest(input: readonly ObservableInput<unknown>[] | Record<string, ObservableInput<unknown>>): Observable<unknown> {\n if (Array.isArray(input)) {\n const filtered = input.filter(isDefined);\n return filtered.length ? combineLatestOperator(filtered) : of([]);\n } else {\n const filtered = Object.fromEntries(\n Object.entries(input).filter(([_, v]) => isDefined(v)),\n );\n return Object.keys(filtered).length\n ? combineLatestOperator(filtered)\n : of({});\n }\n}\n","/**\n * This file is part of helpers4.\n * Copyright (C) 2025 baxyz\n * SPDX-License-Identifier: LGPL-3.0-or-later\n */\n\nimport type { Observable } from 'rxjs';\n\n/**\n * Checks if a value is an RxJS Observable or any compatible observable.\n *\n * Uses duck-typing: returns `true` for any object with both `.subscribe()` and\n * `.pipe()` methods, covering `Observable`, `Subject`, `BehaviorSubject`,\n * `ReplaySubject`, and any RxJS-compatible observable implementation.\n *\n * @param value - The value to check\n * @returns `true` if value is observable-like\n * @example\n * import { Observable, Subject } from 'rxjs';\n * isObservable(new Observable()) // => true\n * isObservable(new Subject()) // => true\n * isObservable(Promise.resolve()) // => false\n * isObservable({}) // => false\n * @since 2.0.3\n */\nexport function isObservable(value: unknown): value is Observable<unknown> {\n return (\n // Intentionally `object`-only, unlike `isPromiseLike` (see type/isPromiseLike.ts):\n // a callable function exposing `.subscribe()`/`.pipe()` would be an unusual,\n // contrived observable shape.\n value !== null &&\n typeof value === 'object' &&\n typeof (value as Record<string, unknown>)['subscribe'] === 'function' &&\n typeof (value as Record<string, unknown>)['pipe'] === 'function'\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAsCA,SAAgB,QACd,SACA,SACA,OACA,SACe;CACf,IAAI,SAAS,cACX,OAAOA,gBAAsB,CAAC,SAAS,OAAO,CAAC,CAAC,CAAC,KAC/C,QAAQ,cACRC,IAAYC,KAAG,CACjB;MAEA,OAAOF,gBAAsB,CAAC,SAAS,OAAO,CAAC,CAAC,CAAC,KAAKC,IAAYC,KAAG,CAAC;AAE1E
|
|
1
|
+
{"version":3,"file":"index.js","names":["combineLatestOperator","mapOperator","map","combineLatestOperator"],"sources":["../../../helpers/observable/combine.ts","../../../helpers/guard/isDefined.ts","../../../helpers/observable/combineLatest.ts","../../../helpers/observable/isObservable.ts"],"sourcesContent":["/**\n * This file is part of helpers4.\n * Copyright (C) 2025 baxyz\n * SPDX-License-Identifier: LGPL-3.0-or-later\n */\n\n/*\n * This program is under the terms of the GNU Lesser General Public License version 3\n * The full license information can be found in LICENSE in the root directory of this project.\n */\nimport {\n Observable,\n OperatorFunction,\n combineLatest as combineLatestOperator,\n map as mapOperator,\n} from \"rxjs\";\n\n\ntype combineOptions<T, U> = {\n readonly preTreatment?: OperatorFunction<readonly [T, U], readonly [T, U]>;\n};\n\n/**\n * Combine two observables with a map function and an optional pre-treatment.\n *\n * Note: you can use the pre-treatment to add a filter, a distinctUntilChanged,\n * any other operator that can be used in a pipe, or even an `UntilDestroy`\n * operator.\n *\n * @param source1 first source of data\n * @param source2 second source of data\n * @param map way to combine data\n * @param options options for the combineLatest operator\n * @returns an observable that emits the result of the map function\n * @see combineLatestOperator\n * @see mapOperator\n * @since 1.0.0\n */\nexport function combine<T, U, R>(\n source1: Observable<T>,\n source2: Observable<U>,\n map: (c: readonly [T, U]) => R,\n options?: combineOptions<T, U>\n): Observable<R> {\n if (options?.preTreatment) {\n return combineLatestOperator([source1, source2]).pipe(\n options.preTreatment,\n mapOperator(map)\n );\n } else {\n return combineLatestOperator([source1, source2]).pipe(mapOperator(map));\n }\n}\n","/**\n * This file is part of helpers4.\n * Copyright (C) 2025 baxyz\n * SPDX-License-Identifier: LGPL-3.0-or-later\n */\n\nimport type { Maybe } from '../type/Maybe';\n\n/**\n * Checks if a value is defined (not undefined nor null).\n * This is the inverse of {@link isNullish}.\n *\n * Use as a type-safe filter callback to remove `null`/`undefined` from arrays.\n *\n * @param value - The value to check\n * @returns True if value is not undefined nor null\n * @example\n * isDefined(42) // => true\n * isDefined('') // => true (empty string is defined)\n * isDefined(null) // => false\n * isDefined(undefined) // => false\n *\n * @example\n * // Type-safe alternative to filter out null/undefined\n * const items: (string | null | undefined)[] = ['a', null, 'b', undefined];\n * const result = items.filter(isDefined);\n * // => ['a', 'b'] with type string[]\n *\n * @see {@link isNullish} for the inverse check\n * @see {@link isTruthy} to also filter out `0`, `\"\"`, `false`, and `NaN`\n * @since 2.0.0\n */\nexport function isDefined<T>(value: Maybe<T>): value is T {\n return value !== undefined && value !== null;\n}\n","/**\n * This file is part of helpers4.\n * Copyright (C) 2025 baxyz\n * SPDX-License-Identifier: LGPL-3.0-or-later\n */\n\n/*\n * This program is under the terms of the GNU Lesser General Public License version 3\n * The full license information can be found in LICENSE in the root directory of this project.\n */\nimport {\n Observable,\n ObservableInput,\n ObservableInputTuple,\n ObservedValueOf,\n combineLatest as combineLatestOperator,\n of,\n} from \"rxjs\";\nimport { isDefined } from '../guard/isDefined';\n\n// combineLatest([a, b, c])\nexport function combineLatest<A extends readonly unknown[]>(\n sources: readonly [...ObservableInputTuple<A>]\n): Observable<A>;\n\n// combineLatest({a, b, c})\nexport function combineLatest<T extends Record<string, ObservableInput<unknown>>>(\n sourcesObject: T\n): Observable<{ [K in keyof T]: ObservedValueOf<T[K]> }>;\n\n/**\n * Combines multiple Observables to create an Observable whose values are\n * calculated from the latest values of each of its input Observables.\n *\n * This method relies on {@link combineLatestOperator} of rxjs.\n *\n * The main difference with {@link combineLatestOperator} is in case of empty parameters.\n * If the parameter is empty (empty array or empty object), the result will be\n * also empty.\n *\n * ATTENTION: this version doesn't support `scheduler` nor `mapper` as last\n * argument like in {@link combineLatestOperator}.\n *\n * @see {@link combineLatestOperator}\n * @see {@link combineLatestAll}\n * @see {@link merge}\n * @see {@link withLatestFrom}\n *\n * @param {ObservableInput} [observables] An array of input Observables to combine with each other.\n * An array of Observables must be given as the first argument.\n * @returns {Observable} An Observable of projected values from the most recent\n * values from each input Observable, or an array of the most recent values from\n * each input Observable.\n * @since 1.0.0\n */\nexport function combineLatest(input: readonly ObservableInput<unknown>[] | Record<string, ObservableInput<unknown>>): Observable<unknown> {\n if (Array.isArray(input)) {\n const filtered = input.filter(isDefined);\n return filtered.length ? combineLatestOperator(filtered) : of([]);\n } else {\n const filtered = Object.fromEntries(\n Object.entries(input).filter(([_, v]) => isDefined(v)),\n );\n return Object.keys(filtered).length\n ? combineLatestOperator(filtered)\n : of({});\n }\n}\n","/**\n * This file is part of helpers4.\n * Copyright (C) 2025 baxyz\n * SPDX-License-Identifier: LGPL-3.0-or-later\n */\n\nimport type { Observable } from 'rxjs';\n\n/**\n * Checks if a value is an RxJS Observable or any compatible observable.\n *\n * Uses duck-typing: returns `true` for any object with both `.subscribe()` and\n * `.pipe()` methods, covering `Observable`, `Subject`, `BehaviorSubject`,\n * `ReplaySubject`, and any RxJS-compatible observable implementation.\n *\n * @param value - The value to check\n * @returns `true` if value is observable-like\n * @example\n * import { Observable, Subject } from 'rxjs';\n * isObservable(new Observable()) // => true\n * isObservable(new Subject()) // => true\n * isObservable(Promise.resolve()) // => false\n * isObservable({}) // => false\n * @since 2.0.3\n */\nexport function isObservable(value: unknown): value is Observable<unknown> {\n return (\n // Intentionally `object`-only, unlike `isPromiseLike` (see type/isPromiseLike.ts):\n // a callable function exposing `.subscribe()`/`.pipe()` would be an unusual,\n // contrived observable shape.\n value !== null &&\n typeof value === 'object' &&\n typeof (value as Record<string, unknown>)['subscribe'] === 'function' &&\n typeof (value as Record<string, unknown>)['pipe'] === 'function'\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAsCA,SAAgB,QACd,SACA,SACA,OACA,SACe;CACf,IAAI,SAAS,cACX,OAAOA,gBAAsB,CAAC,SAAS,OAAO,CAAC,CAAC,CAAC,KAC/C,QAAQ,cACRC,IAAYC,KAAG,CACjB;MAEA,OAAOF,gBAAsB,CAAC,SAAS,OAAO,CAAC,CAAC,CAAC,KAAKC,IAAYC,KAAG,CAAC;AAE1E;;;;;;;;;;;;;;;;;;;;;;;;;;ACpBA,SAAgB,UAAa,OAA6B;CACxD,OAAO,UAAU,KAAA,KAAa,UAAU;AAC1C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;ACqBA,SAAgB,cAAc,OAA4G;CACxI,IAAI,MAAM,QAAQ,KAAK,GAAG;EACxB,MAAM,WAAW,MAAM,OAAO,SAAS;EACvC,OAAO,SAAS,SAASC,gBAAsB,QAAQ,IAAI,GAAG,CAAC,CAAC;CAClE,OAAO;EACL,MAAM,WAAW,OAAO,YACtB,OAAO,QAAQ,KAAK,CAAC,CAAC,QAAQ,CAAC,GAAG,OAAO,UAAU,CAAC,CAAC,CACvD;EACA,OAAO,OAAO,KAAK,QAAQ,CAAC,CAAC,SACzBA,gBAAsB,QAAQ,IAC9B,GAAG,CAAC,CAAC;CACX;AACF;;;;;;;;;;;;;;;;;;;AC1CA,SAAgB,aAAa,OAA8C;CACzE,OAIE,UAAU,QACV,OAAO,UAAU,YACjB,OAAQ,MAAkC,iBAAiB,cAC3D,OAAQ,MAAkC,YAAY;AAE1D"}
|
package/llms.txt
CHANGED
package/meta/api.json
CHANGED
package/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@helpers4/observable",
|
|
3
|
-
"version": "3.1.
|
|
3
|
+
"version": "3.1.10",
|
|
4
4
|
"description": "A set of helpers in TS/JS, compatible with tree-shaking, for observable.",
|
|
5
5
|
"author": "baxyz <craft@baxyz.dev>",
|
|
6
|
-
"license": "LGPL-3.0",
|
|
6
|
+
"license": "LGPL-3.0-or-later",
|
|
7
7
|
"homepage": "https://helpers4.dev/typescript/categories/observable/",
|
|
8
8
|
"repository": {
|
|
9
9
|
"type": "git",
|