iterflow 0.5.0 → 0.7.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/README.md +3 -20
- package/dist/fn/index.cjs +48 -22
- package/dist/fn/index.cjs.map +1 -1
- package/dist/fn/index.js +48 -22
- package/dist/fn/index.js.map +1 -1
- package/dist/index.cjs +86 -115
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -136
- package/dist/index.d.ts +2 -136
- package/dist/index.js +87 -109
- package/dist/index.js.map +1 -1
- package/package.json +6 -2
package/dist/index.d.cts
CHANGED
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
*/
|
|
14
14
|
declare class iterflow<T> implements Iterable<T> {
|
|
15
15
|
private source;
|
|
16
|
+
private _sourceArray?;
|
|
16
17
|
/**
|
|
17
18
|
* Creates a new iterflow instance from an iterable or iterator.
|
|
18
19
|
*
|
|
@@ -1970,141 +1971,6 @@ declare function errorBoundary<T extends any[], R>(fn: (...args: T) => R, option
|
|
|
1970
1971
|
defaultValue?: R;
|
|
1971
1972
|
}): (...args: T) => R | undefined;
|
|
1972
1973
|
|
|
1973
|
-
/**
|
|
1974
|
-
* Deprecation warnings system for iterflow
|
|
1975
|
-
*
|
|
1976
|
-
* This module provides utilities for marking APIs as deprecated and emitting
|
|
1977
|
-
* warnings to help users migrate away from deprecated functionality.
|
|
1978
|
-
*
|
|
1979
|
-
* @module deprecation
|
|
1980
|
-
*/
|
|
1981
|
-
/**
|
|
1982
|
-
* Configuration options for deprecation warnings
|
|
1983
|
-
*/
|
|
1984
|
-
interface DeprecationConfig {
|
|
1985
|
-
/** Whether to show deprecation warnings (default: true in development, false in production) */
|
|
1986
|
-
enabled: boolean;
|
|
1987
|
-
/** Whether to show stack traces with warnings (default: false) */
|
|
1988
|
-
showStackTrace: boolean;
|
|
1989
|
-
/** Custom handler for deprecation warnings */
|
|
1990
|
-
handler?: (warning: DeprecationWarning) => void;
|
|
1991
|
-
}
|
|
1992
|
-
/**
|
|
1993
|
-
* Information about a deprecated API
|
|
1994
|
-
*/
|
|
1995
|
-
interface DeprecationWarning {
|
|
1996
|
-
/** The deprecated feature name */
|
|
1997
|
-
feature: string;
|
|
1998
|
-
/** Version when it was deprecated */
|
|
1999
|
-
since: string;
|
|
2000
|
-
/** Version when it will be removed (if known) */
|
|
2001
|
-
removeIn?: string;
|
|
2002
|
-
/** Alternative to use instead */
|
|
2003
|
-
alternative?: string;
|
|
2004
|
-
/** Additional message with migration guidance */
|
|
2005
|
-
message?: string;
|
|
2006
|
-
/** Stack trace (if enabled) */
|
|
2007
|
-
stack?: string;
|
|
2008
|
-
}
|
|
2009
|
-
/**
|
|
2010
|
-
* Configure the deprecation warning system
|
|
2011
|
-
*
|
|
2012
|
-
* @param options - Configuration options to update
|
|
2013
|
-
* @example
|
|
2014
|
-
* ```typescript
|
|
2015
|
-
* // Disable all deprecation warnings
|
|
2016
|
-
* configureDeprecation({ enabled: false });
|
|
2017
|
-
*
|
|
2018
|
-
* // Enable stack traces
|
|
2019
|
-
* configureDeprecation({ showStackTrace: true });
|
|
2020
|
-
*
|
|
2021
|
-
* // Use custom handler
|
|
2022
|
-
* configureDeprecation({
|
|
2023
|
-
* handler: (warning) => {
|
|
2024
|
-
* logger.warn(`Deprecated: ${warning.feature}`, warning);
|
|
2025
|
-
* }
|
|
2026
|
-
* });
|
|
2027
|
-
* ```
|
|
2028
|
-
*/
|
|
2029
|
-
declare function configureDeprecation(options: Partial<DeprecationConfig>): void;
|
|
2030
|
-
/**
|
|
2031
|
-
* Get current deprecation configuration
|
|
2032
|
-
*
|
|
2033
|
-
* @returns Current deprecation configuration
|
|
2034
|
-
*/
|
|
2035
|
-
declare function getDeprecationConfig(): Readonly<DeprecationConfig>;
|
|
2036
|
-
/**
|
|
2037
|
-
* Clear the set of warned features (mainly for testing)
|
|
2038
|
-
*/
|
|
2039
|
-
declare function clearDeprecationWarnings(): void;
|
|
2040
|
-
/**
|
|
2041
|
-
* Mark a feature as deprecated and emit a warning when called
|
|
2042
|
-
*
|
|
2043
|
-
* @param options - Deprecation warning details
|
|
2044
|
-
* @example
|
|
2045
|
-
* ```typescript
|
|
2046
|
-
* // In your code
|
|
2047
|
-
* function oldMethod() {
|
|
2048
|
-
* deprecate({
|
|
2049
|
-
* feature: 'oldMethod()',
|
|
2050
|
-
* since: '0.9.0',
|
|
2051
|
-
* removeIn: '2.0.0',
|
|
2052
|
-
* alternative: 'newMethod()',
|
|
2053
|
-
* message: 'See migration guide: https://...'
|
|
2054
|
-
* });
|
|
2055
|
-
*
|
|
2056
|
-
* // ... implementation
|
|
2057
|
-
* }
|
|
2058
|
-
* ```
|
|
2059
|
-
*/
|
|
2060
|
-
declare function deprecate(options: Omit<DeprecationWarning, "stack">): void;
|
|
2061
|
-
/**
|
|
2062
|
-
* Decorator to mark a method or function as deprecated
|
|
2063
|
-
*
|
|
2064
|
-
* @param options - Deprecation warning details
|
|
2065
|
-
* @returns Decorator function
|
|
2066
|
-
* @example
|
|
2067
|
-
* ```typescript
|
|
2068
|
-
* class MyClass {
|
|
2069
|
-
* @deprecated({
|
|
2070
|
-
* feature: 'MyClass.oldMethod',
|
|
2071
|
-
* since: '0.9.0',
|
|
2072
|
-
* alternative: 'MyClass.newMethod'
|
|
2073
|
-
* })
|
|
2074
|
-
* oldMethod() {
|
|
2075
|
-
* // implementation
|
|
2076
|
-
* }
|
|
2077
|
-
* }
|
|
2078
|
-
* ```
|
|
2079
|
-
*/
|
|
2080
|
-
declare function deprecated(options: Omit<DeprecationWarning, "stack" | "feature">): <T extends Function>(target: any, propertyKey: string, descriptor: TypedPropertyDescriptor<T>) => TypedPropertyDescriptor<T> | void;
|
|
2081
|
-
/**
|
|
2082
|
-
* Create a wrapper function that marks the original function as deprecated
|
|
2083
|
-
*
|
|
2084
|
-
* @param fn - The function to wrap
|
|
2085
|
-
* @param options - Deprecation warning details
|
|
2086
|
-
* @returns Wrapped function that emits deprecation warning
|
|
2087
|
-
* @example
|
|
2088
|
-
* ```typescript
|
|
2089
|
-
* const oldFunction = deprecatedFunction(
|
|
2090
|
-
* (x: number) => x * 2,
|
|
2091
|
-
* {
|
|
2092
|
-
* feature: 'oldFunction',
|
|
2093
|
-
* since: '0.9.0',
|
|
2094
|
-
* alternative: 'newFunction'
|
|
2095
|
-
* }
|
|
2096
|
-
* );
|
|
2097
|
-
* ```
|
|
2098
|
-
*/
|
|
2099
|
-
declare function deprecatedFunction<T extends (...args: any[]) => any>(fn: T, options: Omit<DeprecationWarning, "stack">): T;
|
|
2100
|
-
/**
|
|
2101
|
-
* Check if a feature has been marked as deprecated (for testing)
|
|
2102
|
-
*
|
|
2103
|
-
* @param feature - The feature name to check
|
|
2104
|
-
* @returns True if the feature has been warned about
|
|
2105
|
-
*/
|
|
2106
|
-
declare function hasDeprecationWarning(feature: string): boolean;
|
|
2107
|
-
|
|
2108
1974
|
/**
|
|
2109
1975
|
* Creates an iterflow instance from an iterable.
|
|
2110
1976
|
* This is the main entry point for working with iterables in a fluent API style.
|
|
@@ -2261,4 +2127,4 @@ declare namespace iter {
|
|
|
2261
2127
|
function chain<T>(...iterables: Iterable<T>[]): iterflow<T>;
|
|
2262
2128
|
}
|
|
2263
2129
|
|
|
2264
|
-
export { Asynciterflow, type DebugConfig,
|
|
2130
|
+
export { Asynciterflow, type DebugConfig, EmptySequenceError, type ErrorHandler, IndexOutOfBoundsError, OperationError, type Result, type RetryOptions, type TraceEntry, TypeConversionError, ValidationError, addTrace, asyncIter, clearTraces, disableDebug, enableDebug, errorBoundary, getDebugConfig, getTraceSummary, getTraces, getTracesForOperation, isDebugEnabled, iter, iterflow, iterflowError, safeComparator, safePredicate, toInteger, toNumber, toResult, toResultAsync, traceOperation, traceOperationAsync, tryCatch, tryCatchAsync, tryOr, validateComparator, validateFiniteNumber, validateFunction, validateIndex, validateIterable, validateNonEmpty, validateNonNegativeInteger, validateNonZero, validatePositiveInteger, validateRange, withDefault, withErrorRecovery, withRetry, withRetryAsync };
|
package/dist/index.d.ts
CHANGED
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
*/
|
|
14
14
|
declare class iterflow<T> implements Iterable<T> {
|
|
15
15
|
private source;
|
|
16
|
+
private _sourceArray?;
|
|
16
17
|
/**
|
|
17
18
|
* Creates a new iterflow instance from an iterable or iterator.
|
|
18
19
|
*
|
|
@@ -1970,141 +1971,6 @@ declare function errorBoundary<T extends any[], R>(fn: (...args: T) => R, option
|
|
|
1970
1971
|
defaultValue?: R;
|
|
1971
1972
|
}): (...args: T) => R | undefined;
|
|
1972
1973
|
|
|
1973
|
-
/**
|
|
1974
|
-
* Deprecation warnings system for iterflow
|
|
1975
|
-
*
|
|
1976
|
-
* This module provides utilities for marking APIs as deprecated and emitting
|
|
1977
|
-
* warnings to help users migrate away from deprecated functionality.
|
|
1978
|
-
*
|
|
1979
|
-
* @module deprecation
|
|
1980
|
-
*/
|
|
1981
|
-
/**
|
|
1982
|
-
* Configuration options for deprecation warnings
|
|
1983
|
-
*/
|
|
1984
|
-
interface DeprecationConfig {
|
|
1985
|
-
/** Whether to show deprecation warnings (default: true in development, false in production) */
|
|
1986
|
-
enabled: boolean;
|
|
1987
|
-
/** Whether to show stack traces with warnings (default: false) */
|
|
1988
|
-
showStackTrace: boolean;
|
|
1989
|
-
/** Custom handler for deprecation warnings */
|
|
1990
|
-
handler?: (warning: DeprecationWarning) => void;
|
|
1991
|
-
}
|
|
1992
|
-
/**
|
|
1993
|
-
* Information about a deprecated API
|
|
1994
|
-
*/
|
|
1995
|
-
interface DeprecationWarning {
|
|
1996
|
-
/** The deprecated feature name */
|
|
1997
|
-
feature: string;
|
|
1998
|
-
/** Version when it was deprecated */
|
|
1999
|
-
since: string;
|
|
2000
|
-
/** Version when it will be removed (if known) */
|
|
2001
|
-
removeIn?: string;
|
|
2002
|
-
/** Alternative to use instead */
|
|
2003
|
-
alternative?: string;
|
|
2004
|
-
/** Additional message with migration guidance */
|
|
2005
|
-
message?: string;
|
|
2006
|
-
/** Stack trace (if enabled) */
|
|
2007
|
-
stack?: string;
|
|
2008
|
-
}
|
|
2009
|
-
/**
|
|
2010
|
-
* Configure the deprecation warning system
|
|
2011
|
-
*
|
|
2012
|
-
* @param options - Configuration options to update
|
|
2013
|
-
* @example
|
|
2014
|
-
* ```typescript
|
|
2015
|
-
* // Disable all deprecation warnings
|
|
2016
|
-
* configureDeprecation({ enabled: false });
|
|
2017
|
-
*
|
|
2018
|
-
* // Enable stack traces
|
|
2019
|
-
* configureDeprecation({ showStackTrace: true });
|
|
2020
|
-
*
|
|
2021
|
-
* // Use custom handler
|
|
2022
|
-
* configureDeprecation({
|
|
2023
|
-
* handler: (warning) => {
|
|
2024
|
-
* logger.warn(`Deprecated: ${warning.feature}`, warning);
|
|
2025
|
-
* }
|
|
2026
|
-
* });
|
|
2027
|
-
* ```
|
|
2028
|
-
*/
|
|
2029
|
-
declare function configureDeprecation(options: Partial<DeprecationConfig>): void;
|
|
2030
|
-
/**
|
|
2031
|
-
* Get current deprecation configuration
|
|
2032
|
-
*
|
|
2033
|
-
* @returns Current deprecation configuration
|
|
2034
|
-
*/
|
|
2035
|
-
declare function getDeprecationConfig(): Readonly<DeprecationConfig>;
|
|
2036
|
-
/**
|
|
2037
|
-
* Clear the set of warned features (mainly for testing)
|
|
2038
|
-
*/
|
|
2039
|
-
declare function clearDeprecationWarnings(): void;
|
|
2040
|
-
/**
|
|
2041
|
-
* Mark a feature as deprecated and emit a warning when called
|
|
2042
|
-
*
|
|
2043
|
-
* @param options - Deprecation warning details
|
|
2044
|
-
* @example
|
|
2045
|
-
* ```typescript
|
|
2046
|
-
* // In your code
|
|
2047
|
-
* function oldMethod() {
|
|
2048
|
-
* deprecate({
|
|
2049
|
-
* feature: 'oldMethod()',
|
|
2050
|
-
* since: '0.9.0',
|
|
2051
|
-
* removeIn: '2.0.0',
|
|
2052
|
-
* alternative: 'newMethod()',
|
|
2053
|
-
* message: 'See migration guide: https://...'
|
|
2054
|
-
* });
|
|
2055
|
-
*
|
|
2056
|
-
* // ... implementation
|
|
2057
|
-
* }
|
|
2058
|
-
* ```
|
|
2059
|
-
*/
|
|
2060
|
-
declare function deprecate(options: Omit<DeprecationWarning, "stack">): void;
|
|
2061
|
-
/**
|
|
2062
|
-
* Decorator to mark a method or function as deprecated
|
|
2063
|
-
*
|
|
2064
|
-
* @param options - Deprecation warning details
|
|
2065
|
-
* @returns Decorator function
|
|
2066
|
-
* @example
|
|
2067
|
-
* ```typescript
|
|
2068
|
-
* class MyClass {
|
|
2069
|
-
* @deprecated({
|
|
2070
|
-
* feature: 'MyClass.oldMethod',
|
|
2071
|
-
* since: '0.9.0',
|
|
2072
|
-
* alternative: 'MyClass.newMethod'
|
|
2073
|
-
* })
|
|
2074
|
-
* oldMethod() {
|
|
2075
|
-
* // implementation
|
|
2076
|
-
* }
|
|
2077
|
-
* }
|
|
2078
|
-
* ```
|
|
2079
|
-
*/
|
|
2080
|
-
declare function deprecated(options: Omit<DeprecationWarning, "stack" | "feature">): <T extends Function>(target: any, propertyKey: string, descriptor: TypedPropertyDescriptor<T>) => TypedPropertyDescriptor<T> | void;
|
|
2081
|
-
/**
|
|
2082
|
-
* Create a wrapper function that marks the original function as deprecated
|
|
2083
|
-
*
|
|
2084
|
-
* @param fn - The function to wrap
|
|
2085
|
-
* @param options - Deprecation warning details
|
|
2086
|
-
* @returns Wrapped function that emits deprecation warning
|
|
2087
|
-
* @example
|
|
2088
|
-
* ```typescript
|
|
2089
|
-
* const oldFunction = deprecatedFunction(
|
|
2090
|
-
* (x: number) => x * 2,
|
|
2091
|
-
* {
|
|
2092
|
-
* feature: 'oldFunction',
|
|
2093
|
-
* since: '0.9.0',
|
|
2094
|
-
* alternative: 'newFunction'
|
|
2095
|
-
* }
|
|
2096
|
-
* );
|
|
2097
|
-
* ```
|
|
2098
|
-
*/
|
|
2099
|
-
declare function deprecatedFunction<T extends (...args: any[]) => any>(fn: T, options: Omit<DeprecationWarning, "stack">): T;
|
|
2100
|
-
/**
|
|
2101
|
-
* Check if a feature has been marked as deprecated (for testing)
|
|
2102
|
-
*
|
|
2103
|
-
* @param feature - The feature name to check
|
|
2104
|
-
* @returns True if the feature has been warned about
|
|
2105
|
-
*/
|
|
2106
|
-
declare function hasDeprecationWarning(feature: string): boolean;
|
|
2107
|
-
|
|
2108
1974
|
/**
|
|
2109
1975
|
* Creates an iterflow instance from an iterable.
|
|
2110
1976
|
* This is the main entry point for working with iterables in a fluent API style.
|
|
@@ -2261,4 +2127,4 @@ declare namespace iter {
|
|
|
2261
2127
|
function chain<T>(...iterables: Iterable<T>[]): iterflow<T>;
|
|
2262
2128
|
}
|
|
2263
2129
|
|
|
2264
|
-
export { Asynciterflow, type DebugConfig,
|
|
2130
|
+
export { Asynciterflow, type DebugConfig, EmptySequenceError, type ErrorHandler, IndexOutOfBoundsError, OperationError, type Result, type RetryOptions, type TraceEntry, TypeConversionError, ValidationError, addTrace, asyncIter, clearTraces, disableDebug, enableDebug, errorBoundary, getDebugConfig, getTraceSummary, getTraces, getTracesForOperation, isDebugEnabled, iter, iterflow, iterflowError, safeComparator, safePredicate, toInteger, toNumber, toResult, toResultAsync, traceOperation, traceOperationAsync, tryCatch, tryCatchAsync, tryOr, validateComparator, validateFiniteNumber, validateFunction, validateIndex, validateIterable, validateNonEmpty, validateNonNegativeInteger, validateNonZero, validatePositiveInteger, validateRange, withDefault, withErrorRecovery, withRetry, withRetryAsync };
|
package/dist/index.js
CHANGED
|
@@ -211,6 +211,7 @@ function validateIndex(index, size, operation) {
|
|
|
211
211
|
// src/iter-flow.ts
|
|
212
212
|
var iterflow = class _iterflow {
|
|
213
213
|
source;
|
|
214
|
+
_sourceArray;
|
|
214
215
|
/**
|
|
215
216
|
* Creates a new iterflow instance from an iterable or iterator.
|
|
216
217
|
*
|
|
@@ -222,7 +223,13 @@ var iterflow = class _iterflow {
|
|
|
222
223
|
* ```
|
|
223
224
|
*/
|
|
224
225
|
constructor(source) {
|
|
225
|
-
|
|
226
|
+
if (Array.isArray(source)) {
|
|
227
|
+
this._sourceArray = source;
|
|
228
|
+
this.source = source[Symbol.iterator]();
|
|
229
|
+
} else {
|
|
230
|
+
this._sourceArray = void 0;
|
|
231
|
+
this.source = Symbol.iterator in source ? source[Symbol.iterator]() : source;
|
|
232
|
+
}
|
|
226
233
|
}
|
|
227
234
|
// Iterator protocol
|
|
228
235
|
/**
|
|
@@ -298,6 +305,9 @@ var iterflow = class _iterflow {
|
|
|
298
305
|
* ```
|
|
299
306
|
*/
|
|
300
307
|
take(limit) {
|
|
308
|
+
if (this._sourceArray) {
|
|
309
|
+
return new _iterflow(this._sourceArray.slice(0, limit));
|
|
310
|
+
}
|
|
301
311
|
const self = this;
|
|
302
312
|
return new _iterflow({
|
|
303
313
|
*[Symbol.iterator]() {
|
|
@@ -321,6 +331,9 @@ var iterflow = class _iterflow {
|
|
|
321
331
|
* ```
|
|
322
332
|
*/
|
|
323
333
|
drop(count) {
|
|
334
|
+
if (this._sourceArray) {
|
|
335
|
+
return new _iterflow(this._sourceArray.slice(count));
|
|
336
|
+
}
|
|
324
337
|
const self = this;
|
|
325
338
|
return new _iterflow({
|
|
326
339
|
*[Symbol.iterator]() {
|
|
@@ -473,6 +486,9 @@ var iterflow = class _iterflow {
|
|
|
473
486
|
* ```
|
|
474
487
|
*/
|
|
475
488
|
reverse() {
|
|
489
|
+
if (this._sourceArray) {
|
|
490
|
+
return new _iterflow(this._sourceArray.slice().reverse());
|
|
491
|
+
}
|
|
476
492
|
const self = this;
|
|
477
493
|
return new _iterflow({
|
|
478
494
|
*[Symbol.iterator]() {
|
|
@@ -500,6 +516,16 @@ var iterflow = class _iterflow {
|
|
|
500
516
|
* ```
|
|
501
517
|
*/
|
|
502
518
|
sort() {
|
|
519
|
+
if (this._sourceArray) {
|
|
520
|
+
return new _iterflow(
|
|
521
|
+
this._sourceArray.slice().sort((a, b) => {
|
|
522
|
+
if (typeof a === "number" && typeof b === "number") {
|
|
523
|
+
return a - b;
|
|
524
|
+
}
|
|
525
|
+
return String(a).localeCompare(String(b));
|
|
526
|
+
})
|
|
527
|
+
);
|
|
528
|
+
}
|
|
503
529
|
const self = this;
|
|
504
530
|
return new _iterflow({
|
|
505
531
|
*[Symbol.iterator]() {
|
|
@@ -532,6 +558,9 @@ var iterflow = class _iterflow {
|
|
|
532
558
|
* ```
|
|
533
559
|
*/
|
|
534
560
|
sortBy(compareFn) {
|
|
561
|
+
if (this._sourceArray) {
|
|
562
|
+
return new _iterflow(this._sourceArray.slice().sort(compareFn));
|
|
563
|
+
}
|
|
535
564
|
const self = this;
|
|
536
565
|
return new _iterflow({
|
|
537
566
|
*[Symbol.iterator]() {
|
|
@@ -553,6 +582,9 @@ var iterflow = class _iterflow {
|
|
|
553
582
|
* ```
|
|
554
583
|
*/
|
|
555
584
|
toArray() {
|
|
585
|
+
if (this._sourceArray) {
|
|
586
|
+
return this._sourceArray.slice();
|
|
587
|
+
}
|
|
556
588
|
return Array.from(this);
|
|
557
589
|
}
|
|
558
590
|
/**
|
|
@@ -566,6 +598,9 @@ var iterflow = class _iterflow {
|
|
|
566
598
|
* ```
|
|
567
599
|
*/
|
|
568
600
|
count() {
|
|
601
|
+
if (this._sourceArray) {
|
|
602
|
+
return this._sourceArray.length;
|
|
603
|
+
}
|
|
569
604
|
let count = 0;
|
|
570
605
|
for (const _ of this) {
|
|
571
606
|
count++;
|
|
@@ -586,6 +621,13 @@ var iterflow = class _iterflow {
|
|
|
586
621
|
* ```
|
|
587
622
|
*/
|
|
588
623
|
sum() {
|
|
624
|
+
if (this._sourceArray) {
|
|
625
|
+
let total2 = 0;
|
|
626
|
+
for (let i = 0; i < this._sourceArray.length; i++) {
|
|
627
|
+
total2 += this._sourceArray[i];
|
|
628
|
+
}
|
|
629
|
+
return total2;
|
|
630
|
+
}
|
|
589
631
|
let total = 0;
|
|
590
632
|
for (const value of this) {
|
|
591
633
|
total += value;
|
|
@@ -674,14 +716,14 @@ var iterflow = class _iterflow {
|
|
|
674
716
|
* ```
|
|
675
717
|
*/
|
|
676
718
|
median() {
|
|
677
|
-
const values = this.toArray();
|
|
719
|
+
const values = this._sourceArray || this.toArray();
|
|
678
720
|
if (values.length === 0) return void 0;
|
|
679
|
-
values.sort((a, b) => a - b);
|
|
680
|
-
const mid = Math.floor(
|
|
681
|
-
if (
|
|
682
|
-
return (
|
|
721
|
+
const sorted = values.slice().sort((a, b) => a - b);
|
|
722
|
+
const mid = Math.floor(sorted.length / 2);
|
|
723
|
+
if (sorted.length % 2 === 0) {
|
|
724
|
+
return (sorted[mid - 1] + sorted[mid]) / 2;
|
|
683
725
|
} else {
|
|
684
|
-
return
|
|
726
|
+
return sorted[mid];
|
|
685
727
|
}
|
|
686
728
|
}
|
|
687
729
|
/**
|
|
@@ -699,7 +741,7 @@ var iterflow = class _iterflow {
|
|
|
699
741
|
* ```
|
|
700
742
|
*/
|
|
701
743
|
variance() {
|
|
702
|
-
const values = this.toArray();
|
|
744
|
+
const values = this._sourceArray || this.toArray();
|
|
703
745
|
if (values.length === 0) return void 0;
|
|
704
746
|
const mean = values.reduce((sum, val) => sum + val, 0) / values.length;
|
|
705
747
|
let sumSquaredDiffs = 0;
|
|
@@ -747,19 +789,19 @@ var iterflow = class _iterflow {
|
|
|
747
789
|
*/
|
|
748
790
|
percentile(p) {
|
|
749
791
|
validateRange(p, 0, 100, "percentile", "percentile");
|
|
750
|
-
const values = this.toArray();
|
|
792
|
+
const values = this._sourceArray || this.toArray();
|
|
751
793
|
if (values.length === 0) return void 0;
|
|
752
|
-
values.sort((a, b) => a - b);
|
|
753
|
-
if (p === 0) return
|
|
754
|
-
if (p === 100) return
|
|
755
|
-
const index = p / 100 * (
|
|
794
|
+
const sorted = values.slice().sort((a, b) => a - b);
|
|
795
|
+
if (p === 0) return sorted[0];
|
|
796
|
+
if (p === 100) return sorted[sorted.length - 1];
|
|
797
|
+
const index = p / 100 * (sorted.length - 1);
|
|
756
798
|
const lower = Math.floor(index);
|
|
757
799
|
const upper = Math.ceil(index);
|
|
758
800
|
if (lower === upper) {
|
|
759
|
-
return
|
|
801
|
+
return sorted[lower];
|
|
760
802
|
}
|
|
761
803
|
const weight = index - lower;
|
|
762
|
-
return
|
|
804
|
+
return sorted[lower] * (1 - weight) + sorted[upper] * weight;
|
|
763
805
|
}
|
|
764
806
|
/**
|
|
765
807
|
* Finds the most frequent value(s) in the dataset.
|
|
@@ -777,7 +819,7 @@ var iterflow = class _iterflow {
|
|
|
777
819
|
* ```
|
|
778
820
|
*/
|
|
779
821
|
mode() {
|
|
780
|
-
const values = this.toArray();
|
|
822
|
+
const values = this._sourceArray || this.toArray();
|
|
781
823
|
if (values.length === 0) return void 0;
|
|
782
824
|
const frequency = /* @__PURE__ */ new Map();
|
|
783
825
|
let maxFreq = 0;
|
|
@@ -810,20 +852,20 @@ var iterflow = class _iterflow {
|
|
|
810
852
|
* ```
|
|
811
853
|
*/
|
|
812
854
|
quartiles() {
|
|
813
|
-
const values = this.toArray();
|
|
855
|
+
const values = this._sourceArray || this.toArray();
|
|
814
856
|
if (values.length === 0) return void 0;
|
|
815
|
-
values.sort((a, b) => a - b);
|
|
857
|
+
const sorted = values.slice().sort((a, b) => a - b);
|
|
816
858
|
const calculatePercentile = (p) => {
|
|
817
|
-
if (p === 0) return
|
|
818
|
-
if (p === 100) return
|
|
819
|
-
const index = p / 100 * (
|
|
859
|
+
if (p === 0) return sorted[0];
|
|
860
|
+
if (p === 100) return sorted[sorted.length - 1];
|
|
861
|
+
const index = p / 100 * (sorted.length - 1);
|
|
820
862
|
const lower = Math.floor(index);
|
|
821
863
|
const upper = Math.ceil(index);
|
|
822
864
|
if (lower === upper) {
|
|
823
|
-
return
|
|
865
|
+
return sorted[lower];
|
|
824
866
|
}
|
|
825
867
|
const weight = index - lower;
|
|
826
|
-
return
|
|
868
|
+
return sorted[lower] * (1 - weight) + sorted[upper] * weight;
|
|
827
869
|
};
|
|
828
870
|
return {
|
|
829
871
|
Q1: calculatePercentile(25),
|
|
@@ -895,7 +937,7 @@ var iterflow = class _iterflow {
|
|
|
895
937
|
* ```
|
|
896
938
|
*/
|
|
897
939
|
covariance(other) {
|
|
898
|
-
const values1 = this.toArray();
|
|
940
|
+
const values1 = this._sourceArray || this.toArray();
|
|
899
941
|
const values2 = Array.from(other);
|
|
900
942
|
if (values1.length === 0 || values2.length === 0 || values1.length !== values2.length) {
|
|
901
943
|
return void 0;
|
|
@@ -926,7 +968,7 @@ var iterflow = class _iterflow {
|
|
|
926
968
|
* ```
|
|
927
969
|
*/
|
|
928
970
|
correlation(other) {
|
|
929
|
-
const values1 = this.toArray();
|
|
971
|
+
const values1 = this._sourceArray || this.toArray();
|
|
930
972
|
const values2 = Array.from(other);
|
|
931
973
|
if (values1.length === 0 || values2.length === 0 || values1.length !== values2.length) {
|
|
932
974
|
return void 0;
|
|
@@ -1350,6 +1392,9 @@ var iterflow = class _iterflow {
|
|
|
1350
1392
|
* ```
|
|
1351
1393
|
*/
|
|
1352
1394
|
first(defaultValue) {
|
|
1395
|
+
if (this._sourceArray) {
|
|
1396
|
+
return this._sourceArray.length > 0 ? this._sourceArray[0] : defaultValue;
|
|
1397
|
+
}
|
|
1353
1398
|
const result = this.source.next();
|
|
1354
1399
|
return result.done ? defaultValue : result.value;
|
|
1355
1400
|
}
|
|
@@ -1367,6 +1412,9 @@ var iterflow = class _iterflow {
|
|
|
1367
1412
|
* ```
|
|
1368
1413
|
*/
|
|
1369
1414
|
last(defaultValue) {
|
|
1415
|
+
if (this._sourceArray) {
|
|
1416
|
+
return this._sourceArray.length > 0 ? this._sourceArray[this._sourceArray.length - 1] : defaultValue;
|
|
1417
|
+
}
|
|
1370
1418
|
let lastValue = defaultValue;
|
|
1371
1419
|
let hasValue = false;
|
|
1372
1420
|
for (const value of this) {
|
|
@@ -1389,6 +1437,9 @@ var iterflow = class _iterflow {
|
|
|
1389
1437
|
* ```
|
|
1390
1438
|
*/
|
|
1391
1439
|
nth(index) {
|
|
1440
|
+
if (this._sourceArray) {
|
|
1441
|
+
return index >= 0 && index < this._sourceArray.length ? this._sourceArray[index] : void 0;
|
|
1442
|
+
}
|
|
1392
1443
|
if (index < 0) {
|
|
1393
1444
|
return void 0;
|
|
1394
1445
|
}
|
|
@@ -1413,6 +1464,9 @@ var iterflow = class _iterflow {
|
|
|
1413
1464
|
* ```
|
|
1414
1465
|
*/
|
|
1415
1466
|
isEmpty() {
|
|
1467
|
+
if (this._sourceArray) {
|
|
1468
|
+
return this._sourceArray.length === 0;
|
|
1469
|
+
}
|
|
1416
1470
|
const result = this.source.next();
|
|
1417
1471
|
return result.done === true;
|
|
1418
1472
|
}
|
|
@@ -1431,6 +1485,9 @@ var iterflow = class _iterflow {
|
|
|
1431
1485
|
* ```
|
|
1432
1486
|
*/
|
|
1433
1487
|
includes(searchValue) {
|
|
1488
|
+
if (this._sourceArray) {
|
|
1489
|
+
return this._sourceArray.includes(searchValue);
|
|
1490
|
+
}
|
|
1434
1491
|
for (const value of this) {
|
|
1435
1492
|
if (value === searchValue) {
|
|
1436
1493
|
return true;
|
|
@@ -3373,12 +3430,12 @@ var DebugState = class {
|
|
|
3373
3430
|
/**
|
|
3374
3431
|
* Enable debug mode with optional configuration
|
|
3375
3432
|
*/
|
|
3376
|
-
enable(
|
|
3433
|
+
enable(config) {
|
|
3377
3434
|
this.config = {
|
|
3378
3435
|
...this.config,
|
|
3379
3436
|
enabled: true,
|
|
3380
3437
|
traceOperations: true,
|
|
3381
|
-
...
|
|
3438
|
+
...config
|
|
3382
3439
|
};
|
|
3383
3440
|
if (this.config.logToConsole) {
|
|
3384
3441
|
console.log("[iterflow Debug] Debug mode enabled", this.config);
|
|
@@ -3498,8 +3555,8 @@ var DebugState = class {
|
|
|
3498
3555
|
}
|
|
3499
3556
|
};
|
|
3500
3557
|
var debugState = new DebugState();
|
|
3501
|
-
function enableDebug(
|
|
3502
|
-
debugState.enable(
|
|
3558
|
+
function enableDebug(config) {
|
|
3559
|
+
debugState.enable(config);
|
|
3503
3560
|
}
|
|
3504
3561
|
function disableDebug() {
|
|
3505
3562
|
debugState.disable();
|
|
@@ -3732,85 +3789,6 @@ function errorBoundary(fn, options = {}) {
|
|
|
3732
3789
|
};
|
|
3733
3790
|
}
|
|
3734
3791
|
|
|
3735
|
-
// src/deprecation.ts
|
|
3736
|
-
var config = {
|
|
3737
|
-
enabled: typeof process !== "undefined" && process.env.NODE_ENV !== "production",
|
|
3738
|
-
showStackTrace: false
|
|
3739
|
-
};
|
|
3740
|
-
var warnedFeatures = /* @__PURE__ */ new Set();
|
|
3741
|
-
function configureDeprecation(options) {
|
|
3742
|
-
config = { ...config, ...options };
|
|
3743
|
-
}
|
|
3744
|
-
function getDeprecationConfig() {
|
|
3745
|
-
return { ...config };
|
|
3746
|
-
}
|
|
3747
|
-
function clearDeprecationWarnings() {
|
|
3748
|
-
warnedFeatures.clear();
|
|
3749
|
-
}
|
|
3750
|
-
function emitWarning(warning) {
|
|
3751
|
-
if (!config.enabled) return;
|
|
3752
|
-
if (warnedFeatures.has(warning.feature)) return;
|
|
3753
|
-
warnedFeatures.add(warning.feature);
|
|
3754
|
-
if (config.handler) {
|
|
3755
|
-
config.handler(warning);
|
|
3756
|
-
return;
|
|
3757
|
-
}
|
|
3758
|
-
let message = `[iterflow] DEPRECATED: ${warning.feature} has been deprecated since v${warning.since}`;
|
|
3759
|
-
if (warning.removeIn) {
|
|
3760
|
-
message += ` and will be removed in v${warning.removeIn}`;
|
|
3761
|
-
}
|
|
3762
|
-
if (warning.alternative) {
|
|
3763
|
-
message += `
|
|
3764
|
-
Please use ${warning.alternative} instead.`;
|
|
3765
|
-
}
|
|
3766
|
-
if (warning.message) {
|
|
3767
|
-
message += `
|
|
3768
|
-
${warning.message}`;
|
|
3769
|
-
}
|
|
3770
|
-
if (typeof process !== "undefined" && process.emitWarning) {
|
|
3771
|
-
const options = {
|
|
3772
|
-
type: "DeprecationWarning",
|
|
3773
|
-
code: "ITERFLOW_DEPRECATION",
|
|
3774
|
-
detail: warning.message
|
|
3775
|
-
};
|
|
3776
|
-
process.emitWarning(message, options);
|
|
3777
|
-
} else {
|
|
3778
|
-
console.warn(message);
|
|
3779
|
-
}
|
|
3780
|
-
if (config.showStackTrace && warning.stack) {
|
|
3781
|
-
console.warn("Stack trace:", warning.stack);
|
|
3782
|
-
}
|
|
3783
|
-
}
|
|
3784
|
-
function deprecate(options) {
|
|
3785
|
-
const warning = {
|
|
3786
|
-
...options,
|
|
3787
|
-
stack: config.showStackTrace ? new Error().stack : void 0
|
|
3788
|
-
};
|
|
3789
|
-
emitWarning(warning);
|
|
3790
|
-
}
|
|
3791
|
-
function deprecated(options) {
|
|
3792
|
-
return function(target, propertyKey, descriptor) {
|
|
3793
|
-
const originalMethod = descriptor.value;
|
|
3794
|
-
if (!originalMethod) return;
|
|
3795
|
-
const className = target.constructor?.name || "Object";
|
|
3796
|
-
const feature = `${className}.${propertyKey}`;
|
|
3797
|
-
descriptor.value = function(...args) {
|
|
3798
|
-
deprecate({ ...options, feature });
|
|
3799
|
-
return originalMethod.apply(this, args);
|
|
3800
|
-
};
|
|
3801
|
-
return descriptor;
|
|
3802
|
-
};
|
|
3803
|
-
}
|
|
3804
|
-
function deprecatedFunction(fn, options) {
|
|
3805
|
-
return function(...args) {
|
|
3806
|
-
deprecate(options);
|
|
3807
|
-
return fn.apply(this, args);
|
|
3808
|
-
};
|
|
3809
|
-
}
|
|
3810
|
-
function hasDeprecationWarning(feature) {
|
|
3811
|
-
return warnedFeatures.has(feature);
|
|
3812
|
-
}
|
|
3813
|
-
|
|
3814
3792
|
// src/index.ts
|
|
3815
3793
|
function iter(source) {
|
|
3816
3794
|
return new iterflow(source);
|
|
@@ -3969,6 +3947,6 @@ function iter(source) {
|
|
|
3969
3947
|
iter2.chain = chain;
|
|
3970
3948
|
})(iter || (iter = {}));
|
|
3971
3949
|
|
|
3972
|
-
export { Asynciterflow, EmptySequenceError, IndexOutOfBoundsError, OperationError, TypeConversionError, ValidationError, addTrace, asyncIter,
|
|
3950
|
+
export { Asynciterflow, EmptySequenceError, IndexOutOfBoundsError, OperationError, TypeConversionError, ValidationError, addTrace, asyncIter, clearTraces, disableDebug, enableDebug, errorBoundary, getDebugConfig, getTraceSummary, getTraces, getTracesForOperation, isDebugEnabled, iter, iterflow, iterflowError, safeComparator, safePredicate, toInteger, toNumber, toResult, toResultAsync, traceOperation, traceOperationAsync, tryCatch, tryCatchAsync, tryOr, validateComparator, validateFiniteNumber, validateFunction, validateIndex, validateIterable, validateNonEmpty, validateNonNegativeInteger, validateNonZero, validatePositiveInteger, validateRange, withDefault, withErrorRecovery, withRetry, withRetryAsync };
|
|
3973
3951
|
//# sourceMappingURL=index.js.map
|
|
3974
3952
|
//# sourceMappingURL=index.js.map
|