@oscarpalmer/atoms 0.192.0 → 0.193.1
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.mts +25 -23
- package/dist/index.mjs +30 -31
- package/dist/queue.d.mts +25 -23
- package/dist/queue.mjs +27 -28
- package/package.json +3 -4
- package/src/array/difference.ts +0 -73
- package/src/array/exists.ts +0 -93
- package/src/array/filter.ts +0 -182
- package/src/array/find.ts +0 -183
- package/src/array/first.ts +0 -196
- package/src/array/flatten.ts +0 -20
- package/src/array/from.ts +0 -129
- package/src/array/get.ts +0 -131
- package/src/array/group-by.ts +0 -369
- package/src/array/index.ts +0 -26
- package/src/array/insert.ts +0 -52
- package/src/array/intersection.ts +0 -72
- package/src/array/last.ts +0 -194
- package/src/array/match.ts +0 -436
- package/src/array/move.ts +0 -315
- package/src/array/partition.ts +0 -91
- package/src/array/push.ts +0 -23
- package/src/array/reverse.ts +0 -33
- package/src/array/select.ts +0 -260
- package/src/array/single.ts +0 -93
- package/src/array/slice.ts +0 -335
- package/src/array/sort.ts +0 -607
- package/src/array/splice.ts +0 -106
- package/src/array/swap.ts +0 -322
- package/src/array/to-map.ts +0 -371
- package/src/array/to-record.ts +0 -351
- package/src/array/to-set.ts +0 -80
- package/src/array/toggle.ts +0 -79
- package/src/array/union.ts +0 -72
- package/src/array/unique.ts +0 -67
- package/src/array/update.ts +0 -75
- package/src/beacon.ts +0 -378
- package/src/color/constants.ts +0 -137
- package/src/color/index.ts +0 -83
- package/src/color/instance.ts +0 -162
- package/src/color/misc/alpha.ts +0 -56
- package/src/color/misc/format.ts +0 -29
- package/src/color/misc/get.ts +0 -210
- package/src/color/misc/is.ts +0 -221
- package/src/color/misc/state.ts +0 -243
- package/src/color/models.ts +0 -389
- package/src/color/space/hex.ts +0 -184
- package/src/color/space/hsl.ts +0 -174
- package/src/color/space/hwb.ts +0 -153
- package/src/color/space/rgb.ts +0 -240
- package/src/function/assert.ts +0 -174
- package/src/function/index.ts +0 -2
- package/src/function/limit.ts +0 -83
- package/src/function/memoize.ts +0 -202
- package/src/function/once.ts +0 -200
- package/src/function/retry.ts +0 -175
- package/src/function/work.ts +0 -1007
- package/src/herald.ts +0 -216
- package/src/index.ts +0 -68
- package/src/internal/array/callbacks.ts +0 -46
- package/src/internal/array/chunk.ts +0 -51
- package/src/internal/array/compact.ts +0 -56
- package/src/internal/array/find.ts +0 -200
- package/src/internal/array/group.ts +0 -42
- package/src/internal/array/index-of.ts +0 -182
- package/src/internal/array/insert.ts +0 -80
- package/src/internal/array/overlap.ts +0 -35
- package/src/internal/array/sets.ts +0 -74
- package/src/internal/array/shuffle.ts +0 -33
- package/src/internal/array/update.ts +0 -52
- package/src/internal/function/misc.ts +0 -8
- package/src/internal/function/timer.ts +0 -168
- package/src/internal/is.ts +0 -244
- package/src/internal/math/aggregate.ts +0 -164
- package/src/internal/math/misc.ts +0 -28
- package/src/internal/number.ts +0 -129
- package/src/internal/random.ts +0 -49
- package/src/internal/result.ts +0 -92
- package/src/internal/sized.ts +0 -25
- package/src/internal/string.ts +0 -128
- package/src/internal/subscription.ts +0 -264
- package/src/internal/value/compare.ts +0 -170
- package/src/internal/value/equal.ts +0 -465
- package/src/internal/value/get.ts +0 -57
- package/src/internal/value/handlers.ts +0 -95
- package/src/internal/value/has.ts +0 -118
- package/src/internal/value/misc.ts +0 -125
- package/src/internal/value/partial.ts +0 -46
- package/src/internal/value/set.ts +0 -132
- package/src/is.ts +0 -182
- package/src/logger.ts +0 -230
- package/src/math.ts +0 -281
- package/src/models.ts +0 -286
- package/src/number.ts +0 -1
- package/src/promise/delay.ts +0 -62
- package/src/promise/helpers.ts +0 -96
- package/src/promise/index.ts +0 -300
- package/src/promise/misc.ts +0 -96
- package/src/promise/models.ts +0 -195
- package/src/promise/timed.ts +0 -91
- package/src/query.ts +0 -147
- package/src/queue.ts +0 -814
- package/src/random.ts +0 -125
- package/src/result/index.ts +0 -105
- package/src/result/match.ts +0 -124
- package/src/result/misc.ts +0 -129
- package/src/result/models.ts +0 -83
- package/src/result/work/flow.ts +0 -488
- package/src/result/work/pipe.ts +0 -496
- package/src/sized/map.ts +0 -110
- package/src/sized/set.ts +0 -107
- package/src/string/case.ts +0 -236
- package/src/string/fuzzy.ts +0 -444
- package/src/string/index.ts +0 -199
- package/src/string/match.ts +0 -80
- package/src/string/normalize.ts +0 -205
- package/src/string/template.ts +0 -161
- package/src/value/clone.ts +0 -319
- package/src/value/collection.ts +0 -63
- package/src/value/diff.ts +0 -232
- package/src/value/freeze.ts +0 -322
- package/src/value/handle.ts +0 -3
- package/src/value/index.ts +0 -5
- package/src/value/merge.ts +0 -278
- package/src/value/omit.ts +0 -20
- package/src/value/pick.ts +0 -20
- package/src/value/shake.ts +0 -45
- package/src/value/smush.ts +0 -89
- package/src/value/transform.ts +0 -153
- package/src/value/unsmush.ts +0 -84
package/src/logger.ts
DELETED
|
@@ -1,230 +0,0 @@
|
|
|
1
|
-
import {noop} from './internal/function/misc';
|
|
2
|
-
|
|
3
|
-
// #region Types
|
|
4
|
-
|
|
5
|
-
type Logger = {
|
|
6
|
-
/**
|
|
7
|
-
* Log any number of values at the "debug" log level
|
|
8
|
-
*/
|
|
9
|
-
get debug(): typeof console.debug;
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Log the value and shows all its properties
|
|
13
|
-
*/
|
|
14
|
-
get dir(): typeof console.dir;
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* Is logging to the console enabled? _(defaults to `true`)_
|
|
18
|
-
*/
|
|
19
|
-
get enabled(): boolean;
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* Enable or disable logging to the console
|
|
23
|
-
*/
|
|
24
|
-
set enabled(value: boolean);
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* Log any number of values at the "error" log level
|
|
28
|
-
*/
|
|
29
|
-
get error(): typeof console.error;
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* Log any number of values at the "info" log level
|
|
33
|
-
*/
|
|
34
|
-
get info(): typeof console.info;
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* Log any number of values at the "log" log level
|
|
38
|
-
*/
|
|
39
|
-
get log(): typeof console.log;
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* Log data as a table, with optional properties to use as columns
|
|
43
|
-
*/
|
|
44
|
-
get table(): typeof console.table;
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* Log any number of values together with a trace from where it was called
|
|
48
|
-
*/
|
|
49
|
-
get trace(): typeof console.trace;
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* Log any number of values at the "warn" log level
|
|
53
|
-
*/
|
|
54
|
-
get warn(): typeof console.warn;
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
* Start a timed logger with a label
|
|
58
|
-
*
|
|
59
|
-
* @param label Label for the logger
|
|
60
|
-
* @returns _TimedLogger_ instance
|
|
61
|
-
*/
|
|
62
|
-
time(label: string): TimedLogger;
|
|
63
|
-
};
|
|
64
|
-
|
|
65
|
-
/**
|
|
66
|
-
* A named timer that can be used to log durations to the console
|
|
67
|
-
*/
|
|
68
|
-
type TimedLogger = {
|
|
69
|
-
/**
|
|
70
|
-
* Is the timer active? _(i.e. has it been started and not stopped, and is logging enabled?)_
|
|
71
|
-
*/
|
|
72
|
-
get active(): boolean;
|
|
73
|
-
|
|
74
|
-
/**
|
|
75
|
-
* Log the current duration of the timer _(ignored if logging is disabled)_
|
|
76
|
-
*/
|
|
77
|
-
get log(): () => void;
|
|
78
|
-
|
|
79
|
-
/**
|
|
80
|
-
* Stop the timer and logs the total duration
|
|
81
|
-
*
|
|
82
|
-
* _(Will always log the total duration, even if logging is disabled)_
|
|
83
|
-
*/
|
|
84
|
-
get stop(): () => void;
|
|
85
|
-
};
|
|
86
|
-
|
|
87
|
-
type TimeState = {
|
|
88
|
-
label: string;
|
|
89
|
-
started: boolean;
|
|
90
|
-
stopped: boolean;
|
|
91
|
-
};
|
|
92
|
-
|
|
93
|
-
// #endregion
|
|
94
|
-
|
|
95
|
-
// #region Functions
|
|
96
|
-
|
|
97
|
-
function isLogger(value: unknown): value is Logger {
|
|
98
|
-
return isLoggerInstance<Logger>(NAME_LOGGER, value);
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
function isLoggerInstance<Instance>(name: string, value: unknown): value is Instance {
|
|
102
|
-
return (
|
|
103
|
-
typeof value === 'object' &&
|
|
104
|
-
value !== null &&
|
|
105
|
-
(value as Record<string, unknown>)[KEY_LOGGER] === name
|
|
106
|
-
);
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
function isTimedLogger(value: unknown): value is TimedLogger {
|
|
110
|
-
return isLoggerInstance<TimedLogger>(NAME_TIMED, value);
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
function timedLogger(label: string): TimedLogger {
|
|
114
|
-
function stop() {
|
|
115
|
-
const fn = stopper;
|
|
116
|
-
|
|
117
|
-
state.stopped = true;
|
|
118
|
-
|
|
119
|
-
logger = undefined as never;
|
|
120
|
-
stopper = undefined as never;
|
|
121
|
-
|
|
122
|
-
return fn;
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
let logger = console.timeLog.bind(console, label);
|
|
126
|
-
let stopper = console.timeEnd.bind(console, label);
|
|
127
|
-
|
|
128
|
-
const state: TimeState = {
|
|
129
|
-
label,
|
|
130
|
-
started: enabled,
|
|
131
|
-
stopped: false,
|
|
132
|
-
};
|
|
133
|
-
|
|
134
|
-
const instance = {};
|
|
135
|
-
|
|
136
|
-
Object.defineProperties(instance, {
|
|
137
|
-
[KEY_LOGGER]: {
|
|
138
|
-
enumerable: false,
|
|
139
|
-
value: NAME_TIMED,
|
|
140
|
-
},
|
|
141
|
-
active: {
|
|
142
|
-
enumerable: true,
|
|
143
|
-
get() {
|
|
144
|
-
return state.started && !state.stopped && enabled;
|
|
145
|
-
},
|
|
146
|
-
},
|
|
147
|
-
log: {
|
|
148
|
-
enumerable: true,
|
|
149
|
-
get() {
|
|
150
|
-
return this.active ? logger : noop;
|
|
151
|
-
},
|
|
152
|
-
},
|
|
153
|
-
stop: {
|
|
154
|
-
enumerable: true,
|
|
155
|
-
get() {
|
|
156
|
-
return (instance as TimedLogger).active ? stop() : noop;
|
|
157
|
-
},
|
|
158
|
-
},
|
|
159
|
-
});
|
|
160
|
-
|
|
161
|
-
if (state.started) {
|
|
162
|
-
console.time(label);
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
return Object.freeze(instance) as TimedLogger;
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
// #endregion
|
|
169
|
-
|
|
170
|
-
// #region Variables
|
|
171
|
-
|
|
172
|
-
const KEY_LOGGER = '$logger';
|
|
173
|
-
|
|
174
|
-
const NAME_LOGGER = 'Logger';
|
|
175
|
-
|
|
176
|
-
const NAME_TIMED = 'TimedLogger';
|
|
177
|
-
|
|
178
|
-
const methods = ['debug', 'dir', 'error', 'info', 'log', 'table', 'trace', 'warn'] as const;
|
|
179
|
-
|
|
180
|
-
/**
|
|
181
|
-
* A logger that can be used to log messages to the console
|
|
182
|
-
*
|
|
183
|
-
* _(Logging can be enabled or disabled by setting the `enabled` property)_
|
|
184
|
-
*/
|
|
185
|
-
const Logger = (() => {
|
|
186
|
-
const instance = {};
|
|
187
|
-
|
|
188
|
-
Object.defineProperties(instance, {
|
|
189
|
-
[KEY_LOGGER]: {
|
|
190
|
-
enumerable: false,
|
|
191
|
-
value: NAME_LOGGER,
|
|
192
|
-
},
|
|
193
|
-
enabled: {
|
|
194
|
-
enumerable: true,
|
|
195
|
-
get() {
|
|
196
|
-
return enabled;
|
|
197
|
-
},
|
|
198
|
-
set(value: boolean) {
|
|
199
|
-
enabled = typeof value === 'boolean' ? value : enabled;
|
|
200
|
-
},
|
|
201
|
-
},
|
|
202
|
-
time: {
|
|
203
|
-
enumerable: true,
|
|
204
|
-
value(label: string) {
|
|
205
|
-
return timedLogger(label);
|
|
206
|
-
},
|
|
207
|
-
},
|
|
208
|
-
});
|
|
209
|
-
|
|
210
|
-
for (const method of methods) {
|
|
211
|
-
Object.defineProperty(instance, method, {
|
|
212
|
-
enumerable: true,
|
|
213
|
-
get() {
|
|
214
|
-
return enabled ? console[method].bind(console) : noop;
|
|
215
|
-
},
|
|
216
|
-
});
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
return Object.freeze(instance);
|
|
220
|
-
})() as Logger;
|
|
221
|
-
|
|
222
|
-
let enabled = true;
|
|
223
|
-
|
|
224
|
-
// #endregion
|
|
225
|
-
|
|
226
|
-
// #region Exports
|
|
227
|
-
|
|
228
|
-
export {isLogger, isTimedLogger, Logger, type TimedLogger};
|
|
229
|
-
|
|
230
|
-
// #endregion
|
package/src/math.ts
DELETED
|
@@ -1,281 +0,0 @@
|
|
|
1
|
-
import {isNumber} from './internal/is';
|
|
2
|
-
import {
|
|
3
|
-
aggregate,
|
|
4
|
-
AGGREGATION_AVERAGE,
|
|
5
|
-
AGGREGATION_MIN,
|
|
6
|
-
AGGREGATION_SUM,
|
|
7
|
-
getAggregateCallback,
|
|
8
|
-
getAggregated,
|
|
9
|
-
} from './internal/math/aggregate';
|
|
10
|
-
import {roundNumber} from './internal/math/misc';
|
|
11
|
-
import type {NumericalValues, PlainObject} from './models';
|
|
12
|
-
|
|
13
|
-
// #region Functions
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Get the average value from a list of items
|
|
17
|
-
*
|
|
18
|
-
* @param items List of items
|
|
19
|
-
* @param callback Callback to get an item's value
|
|
20
|
-
* @returns Average value, or `Number.NaN` if no average can be calculated
|
|
21
|
-
*/
|
|
22
|
-
export function average<Item>(
|
|
23
|
-
items: Item[],
|
|
24
|
-
callback: (item: Item, index: number, array: Item[]) => number,
|
|
25
|
-
): number;
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* Get the average value from a list of items
|
|
29
|
-
*
|
|
30
|
-
* @param items List of items
|
|
31
|
-
* @param key Key to use for value
|
|
32
|
-
* @returns Average value, or `Number.NaN` if no average can be calculated
|
|
33
|
-
*/
|
|
34
|
-
export function average<Item extends PlainObject>(
|
|
35
|
-
items: Item[],
|
|
36
|
-
key: keyof NumericalValues<Item>,
|
|
37
|
-
): number;
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* Get the average value from a list of numbers
|
|
41
|
-
*
|
|
42
|
-
* @param numbers List of numbers
|
|
43
|
-
* @returns Average value, or `Number.NaN` if no average can be calculated
|
|
44
|
-
*/
|
|
45
|
-
export function average(numbers: number[]): number;
|
|
46
|
-
|
|
47
|
-
export function average(array: unknown[], key?: unknown): number {
|
|
48
|
-
const aggregated = aggregate(AGGREGATION_AVERAGE, array, key);
|
|
49
|
-
|
|
50
|
-
return aggregated.count > 0 ? aggregated.value / aggregated.count : Number.NaN;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
/**
|
|
54
|
-
* Round a number up
|
|
55
|
-
*
|
|
56
|
-
* @param value Number to round up
|
|
57
|
-
* @param decimals Number of decimal places to round to _(defaults to `0`)_
|
|
58
|
-
* @returns Rounded number, or `Number.NaN` if the value if unable to be rounded
|
|
59
|
-
*/
|
|
60
|
-
export function ceil(value: number, decimals?: number): number {
|
|
61
|
-
return roundNumber(Math.ceil, value, decimals);
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
/**
|
|
65
|
-
* Count the number of items in an array that match a specific value
|
|
66
|
-
*
|
|
67
|
-
* @param array Array to count for
|
|
68
|
-
* @param callback Callback to get an item's value
|
|
69
|
-
* @param value Value to match and count
|
|
70
|
-
* @returns Number of items that match the condition, or `Number.NaN` if no count can be calculated
|
|
71
|
-
*/
|
|
72
|
-
export function count<Item>(
|
|
73
|
-
array: Item[],
|
|
74
|
-
callback: (item: Item, index: number, array: Item[]) => unknown,
|
|
75
|
-
value: unknown,
|
|
76
|
-
): number;
|
|
77
|
-
|
|
78
|
-
/**
|
|
79
|
-
* Count the number of items in an array that have a specific value
|
|
80
|
-
*
|
|
81
|
-
* @param array Array to count for
|
|
82
|
-
* @param key Key to use for value
|
|
83
|
-
* @param value Value to match and count
|
|
84
|
-
* @returns Number of items with the specified key value, or `Number.NaN` if no count can be calculated
|
|
85
|
-
*/
|
|
86
|
-
export function count<Item extends PlainObject, ItemKey extends keyof Item>(
|
|
87
|
-
array: Item[],
|
|
88
|
-
key: ItemKey,
|
|
89
|
-
value: Item[ItemKey],
|
|
90
|
-
): number;
|
|
91
|
-
|
|
92
|
-
/**
|
|
93
|
-
* Count the number of items in an array
|
|
94
|
-
*
|
|
95
|
-
* @param values Array to count for
|
|
96
|
-
* @returns Number of items, or `Number.NaN` if no count can be calculated
|
|
97
|
-
*/
|
|
98
|
-
export function count(values: unknown[]): number;
|
|
99
|
-
|
|
100
|
-
export function count(array: unknown[], key?: unknown, value?: unknown): number {
|
|
101
|
-
if (!Array.isArray(array)) {
|
|
102
|
-
return Number.NaN;
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
const {length} = array;
|
|
106
|
-
|
|
107
|
-
const callback = getAggregateCallback(key);
|
|
108
|
-
|
|
109
|
-
if (callback == null) {
|
|
110
|
-
return length;
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
let counted = 0;
|
|
114
|
-
|
|
115
|
-
for (let index = 0; index < length; index += 1) {
|
|
116
|
-
const item = array[index];
|
|
117
|
-
|
|
118
|
-
if (Object.is(callback(item as never, index, array), value)) {
|
|
119
|
-
counted += 1;
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
return counted;
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
/**
|
|
127
|
-
* Round a number down
|
|
128
|
-
*
|
|
129
|
-
* @param value Number to round down
|
|
130
|
-
* @param decimals Number of decimal places to round to _(defaults to `0`)_
|
|
131
|
-
* @returns Rounded number, or `Number.NaN` if the value if unable to be rounded
|
|
132
|
-
*/
|
|
133
|
-
export function floor(value: number, decimals?: number): number {
|
|
134
|
-
return roundNumber(Math.floor, value, decimals);
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
/**
|
|
138
|
-
* Get the median value from a list of items
|
|
139
|
-
*
|
|
140
|
-
* @param array List of items
|
|
141
|
-
* @param callback Callback to get an item's value
|
|
142
|
-
* @returns Median value, or `Number.NaN` if no median can be calculated
|
|
143
|
-
*/
|
|
144
|
-
export function median<Item>(
|
|
145
|
-
array: Item[],
|
|
146
|
-
callback: (item: Item, index: number, array: Item[]) => number,
|
|
147
|
-
): number;
|
|
148
|
-
|
|
149
|
-
/**
|
|
150
|
-
* Get the median value from a list of items
|
|
151
|
-
*
|
|
152
|
-
* @param array List of items
|
|
153
|
-
* @param key Key to use for value
|
|
154
|
-
* @returns Median value, or `Number.NaN` if no median can be calculated
|
|
155
|
-
*/
|
|
156
|
-
export function median<Item extends PlainObject>(
|
|
157
|
-
array: Item[],
|
|
158
|
-
key: keyof NumericalValues<Item>,
|
|
159
|
-
): number;
|
|
160
|
-
|
|
161
|
-
/**
|
|
162
|
-
* Get the median value from a list of numbers
|
|
163
|
-
*
|
|
164
|
-
* @param array List of numbers
|
|
165
|
-
* @returns Median value, or `Number.NaN` if no median can be calculated
|
|
166
|
-
*/
|
|
167
|
-
export function median(array: number[]): number;
|
|
168
|
-
|
|
169
|
-
export function median(array: unknown[], key?: unknown): number {
|
|
170
|
-
let length = Array.isArray(array) ? array.length : 0;
|
|
171
|
-
|
|
172
|
-
if (!Array.isArray(array) || length === 0) {
|
|
173
|
-
return Number.NaN;
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
let values: unknown[] = array;
|
|
177
|
-
|
|
178
|
-
const callback = getAggregateCallback(key);
|
|
179
|
-
|
|
180
|
-
if (callback != null) {
|
|
181
|
-
values = array.map((item, index) => callback(item as never, index, array));
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
const numbers = values.filter(isNumber).sort((first, second) => first - second);
|
|
185
|
-
|
|
186
|
-
length = numbers.length;
|
|
187
|
-
|
|
188
|
-
if (length === 1) {
|
|
189
|
-
return numbers[0];
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
if (length % 2 === 0) {
|
|
193
|
-
const first = length / 2 - 1;
|
|
194
|
-
const second = length / 2;
|
|
195
|
-
|
|
196
|
-
return (numbers[first] + numbers[second]) / 2;
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
return numbers[Math.floor(length / 2)];
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
/**
|
|
203
|
-
* Get the minimum value from a list of items
|
|
204
|
-
*
|
|
205
|
-
* @param items List of items
|
|
206
|
-
* @param callback Callback to get an item's value
|
|
207
|
-
* @returns Minimum value, or `Number.NaN` if no minimum can be found
|
|
208
|
-
*/
|
|
209
|
-
export function min<Item>(
|
|
210
|
-
items: Item[],
|
|
211
|
-
callback: (item: Item, index: number, array: Item[]) => number,
|
|
212
|
-
): number;
|
|
213
|
-
|
|
214
|
-
/**
|
|
215
|
-
* Get the minimum value from a list of items
|
|
216
|
-
*
|
|
217
|
-
* @param items List of items
|
|
218
|
-
* @param key Key to use for value
|
|
219
|
-
* @returns Minimum value, or `Number.NaN` if no minimum can be found
|
|
220
|
-
*/
|
|
221
|
-
export function min<Item extends PlainObject>(
|
|
222
|
-
items: Item[],
|
|
223
|
-
key: keyof NumericalValues<Item>,
|
|
224
|
-
): number;
|
|
225
|
-
|
|
226
|
-
/**
|
|
227
|
-
* Get the minimum value from a list of numbers
|
|
228
|
-
*
|
|
229
|
-
* @param values List of numbers
|
|
230
|
-
* @returns Minimum value, or `Number.NaN` if no minimum can be found
|
|
231
|
-
*/
|
|
232
|
-
export function min(values: number[]): number;
|
|
233
|
-
|
|
234
|
-
export function min(array: unknown[], key?: unknown): number {
|
|
235
|
-
return getAggregated(AGGREGATION_MIN, array, key);
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
/**
|
|
239
|
-
* Get the sum of a list of items
|
|
240
|
-
*
|
|
241
|
-
* @param items List of items
|
|
242
|
-
* @param callback Callback to get an item's value
|
|
243
|
-
* @returns Sum of the values, or `Number.NaN` if no sum can be calculated
|
|
244
|
-
*/
|
|
245
|
-
export function sum<Item>(
|
|
246
|
-
items: Item[],
|
|
247
|
-
callback: (item: Item, index: number, array: Item[]) => number,
|
|
248
|
-
): number;
|
|
249
|
-
|
|
250
|
-
/**
|
|
251
|
-
* Get the sum of a list of items
|
|
252
|
-
*
|
|
253
|
-
* @param items List of items
|
|
254
|
-
* @param key Key to use for value
|
|
255
|
-
* @returns Sum of the values, or `Number.NaN` if no sum can be calculated
|
|
256
|
-
*/
|
|
257
|
-
export function sum<Item extends PlainObject>(
|
|
258
|
-
items: Item[],
|
|
259
|
-
key: keyof NumericalValues<Item>,
|
|
260
|
-
): number;
|
|
261
|
-
|
|
262
|
-
/**
|
|
263
|
-
* Get the sum of a list of numbers
|
|
264
|
-
*
|
|
265
|
-
* @param values List of numbers
|
|
266
|
-
* @returns Sum of the numbers, or `Number.NaN` if no sum can be calculated
|
|
267
|
-
*/
|
|
268
|
-
export function sum(values: number[]): number;
|
|
269
|
-
|
|
270
|
-
export function sum(array: unknown[], key?: unknown): number {
|
|
271
|
-
return getAggregated(AGGREGATION_SUM, array, key);
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
// #endregion
|
|
275
|
-
|
|
276
|
-
// #region Exports
|
|
277
|
-
|
|
278
|
-
export {max} from './internal/math/aggregate';
|
|
279
|
-
export {round} from './internal/math/misc';
|
|
280
|
-
|
|
281
|
-
// #endregion
|