atomic-fns 0.4.2 → 0.4.3
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 +0 -11
- package/dist/collections/deque.d.ts +1 -1
- package/dist/collections/deque.js +6 -8
- package/dist/collections/index.d.ts +207 -105
- package/dist/collections/index.js +179 -436
- package/dist/functools/index.d.ts +4 -4
- package/dist/functools/index.js +1 -1
- package/dist/globals/decimal.d.ts +142 -0
- package/dist/globals/decimal.js +371 -0
- package/dist/globals/index.d.ts +19 -15
- package/dist/globals/index.js +10 -24
- package/dist/i18n/currency.d.ts +24 -0
- package/dist/i18n/currency.js +85 -0
- package/dist/i18n/date/index.d.ts +9 -9
- package/dist/i18n/date/utils.d.ts +3 -3
- package/dist/i18n/date/utils.js +6 -28
- package/dist/i18n/format.d.ts +2 -2
- package/dist/i18n/format.js +1 -1
- package/dist/i18n/index.d.ts +1 -0
- package/dist/i18n/index.js +1 -0
- package/dist/itertools/index.d.ts +51 -23
- package/dist/itertools/index.js +4 -32
- package/dist/math/index.d.ts +6 -7
- package/dist/math/index.js +3 -1
- package/dist/operators/index.d.ts +2 -2
- package/dist/operators/index.js +0 -6
- package/dist/random/index.d.ts +1 -1
- package/dist/random/index.js +2 -2
- package/package.json +1 -1
package/dist/globals/index.js
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
*
|
|
4
4
|
* @module Globals
|
|
5
5
|
*/
|
|
6
|
+
export * from './decimal.js';
|
|
6
7
|
/** This is just a noop function. */
|
|
7
8
|
export const noop = () => { };
|
|
8
9
|
/** A function that always returns `true`. */
|
|
@@ -69,8 +70,8 @@ export class ValueError extends CustomError {
|
|
|
69
70
|
export class ZeroDivisionError extends CustomError {
|
|
70
71
|
}
|
|
71
72
|
/**
|
|
72
|
-
* Returns the true type of any value with correct detection for null
|
|
73
|
-
* Object
|
|
73
|
+
* Returns the true type of any value with correct detection for `null`, `Array`,
|
|
74
|
+
* `Object`, `Promise`, `Symbol`, and `NaN`. The correct values are inferred from {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/toStringTag | Symbol.toStringTag} and the value's prototype.
|
|
74
75
|
* @param value
|
|
75
76
|
* @returns The value type.
|
|
76
77
|
*/
|
|
@@ -198,12 +199,12 @@ export function len(value) {
|
|
|
198
199
|
if (isNumber(value.length)) {
|
|
199
200
|
return value.length;
|
|
200
201
|
}
|
|
201
|
-
if (isFunction(value.size)) {
|
|
202
|
-
return value.size();
|
|
203
|
-
}
|
|
204
202
|
if (isNumber(value.size)) {
|
|
205
203
|
return value.size;
|
|
206
204
|
}
|
|
205
|
+
if (isFunction(value.size)) {
|
|
206
|
+
return value.size();
|
|
207
|
+
}
|
|
207
208
|
if (isObject(value)) {
|
|
208
209
|
return Object.keys(value).length;
|
|
209
210
|
}
|
|
@@ -274,14 +275,7 @@ export const values = (object) => Object.values(object);
|
|
|
274
275
|
* @returns `true` if the object has the property name.
|
|
275
276
|
*/
|
|
276
277
|
export const has = (obj, attr) => obj && attr in obj;
|
|
277
|
-
|
|
278
|
-
* Check if the attribute is present in the object or return a default value instead.
|
|
279
|
-
* @param {PropertyKey} key
|
|
280
|
-
* @param {*} obj
|
|
281
|
-
* @param {*} [value=undefined]
|
|
282
|
-
* @return The property value or default value.
|
|
283
|
-
*/
|
|
284
|
-
export function get(key, obj, value = undefined) {
|
|
278
|
+
export function get(key, obj, value) {
|
|
285
279
|
if (obj == null)
|
|
286
280
|
return value;
|
|
287
281
|
let paths = Array.isArray(key) ? key : [key];
|
|
@@ -327,11 +321,6 @@ export function set(attr, obj, value, writable = false, enumerable = false) {
|
|
|
327
321
|
});
|
|
328
322
|
}
|
|
329
323
|
export const HASH_KEY = Symbol.for('HASH_KEY');
|
|
330
|
-
/**
|
|
331
|
-
* Return a hash value for a given object. The hash will be the same for subsequent invocations.
|
|
332
|
-
* @param obj The given object.
|
|
333
|
-
* @returns The hash value.
|
|
334
|
-
*/
|
|
335
324
|
export function hash(obj) {
|
|
336
325
|
if (typeof obj === 'string') {
|
|
337
326
|
return hashCode(obj);
|
|
@@ -399,9 +388,6 @@ export const int = (x, base = 10) => parseInt(x, base);
|
|
|
399
388
|
* @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/from Array.from()}
|
|
400
389
|
*/
|
|
401
390
|
export const list = (value) => (value ? Array.from(value) : []);
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
* @returns The next value from the iterator.
|
|
406
|
-
*/
|
|
407
|
-
export const next = (iter) => iter.next().value;
|
|
391
|
+
export function next(iter) {
|
|
392
|
+
return iter.next().value;
|
|
393
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { Decimal } from '../globals/decimal.js';
|
|
2
|
+
/**
|
|
3
|
+
* Currency represents a local currency amount that can be formatted using the `Intl` apis.
|
|
4
|
+
*/
|
|
5
|
+
export declare class Currency extends Decimal {
|
|
6
|
+
locale: string;
|
|
7
|
+
currency: string;
|
|
8
|
+
numberFormat: Intl.NumberFormat;
|
|
9
|
+
options: Intl.NumberFormatOptions;
|
|
10
|
+
constructor(amount: any, currency: string, locale?: string, opts?: Intl.NumberFormatOptions);
|
|
11
|
+
clone(n: any): Currency;
|
|
12
|
+
negated(): Currency;
|
|
13
|
+
add(x: any): Currency;
|
|
14
|
+
sub(x: any): Currency;
|
|
15
|
+
div(x: any): Currency;
|
|
16
|
+
mul(x: any): Currency;
|
|
17
|
+
toDecimal(): any;
|
|
18
|
+
toString(): string;
|
|
19
|
+
format(opts?: Intl.NumberFormatOptions, locale?: string): string;
|
|
20
|
+
displayName(): string;
|
|
21
|
+
accounting(): string;
|
|
22
|
+
precision(digits?: number): string;
|
|
23
|
+
eq(x: any): any;
|
|
24
|
+
}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { defaults } from '../collections/index.js';
|
|
2
|
+
import { isObject } from '../globals/index.js';
|
|
3
|
+
import { Decimal } from '../globals/decimal.js';
|
|
4
|
+
/**
|
|
5
|
+
* Currency represents a local currency amount that can be formatted using the `Intl` apis.
|
|
6
|
+
*/
|
|
7
|
+
export class Currency extends Decimal {
|
|
8
|
+
locale;
|
|
9
|
+
currency;
|
|
10
|
+
numberFormat;
|
|
11
|
+
options = {
|
|
12
|
+
style: 'currency',
|
|
13
|
+
currencyDisplay: 'symbol',
|
|
14
|
+
maximumFractionDigits: 20
|
|
15
|
+
};
|
|
16
|
+
constructor(amount, currency, locale, opts = {}) {
|
|
17
|
+
super(amount);
|
|
18
|
+
if (isObject(locale)) {
|
|
19
|
+
opts = locale;
|
|
20
|
+
locale = undefined;
|
|
21
|
+
}
|
|
22
|
+
const systemLocale = new Intl.NumberFormat(locale, defaults(opts, { currency }, this.options));
|
|
23
|
+
const resolved = systemLocale.resolvedOptions();
|
|
24
|
+
this.numberFormat = systemLocale;
|
|
25
|
+
this.options.currency = currency;
|
|
26
|
+
this.currency = resolved.currency;
|
|
27
|
+
this.locale = resolved.locale;
|
|
28
|
+
}
|
|
29
|
+
// @ts-expect-error overrides
|
|
30
|
+
clone(n) {
|
|
31
|
+
return new Currency(n, this.currency, this.locale, this.options);
|
|
32
|
+
}
|
|
33
|
+
// @ts-expect-error overrides
|
|
34
|
+
negated() {
|
|
35
|
+
const n = super.negated.call(this);
|
|
36
|
+
return this.clone(n);
|
|
37
|
+
}
|
|
38
|
+
// @ts-expect-error overrides
|
|
39
|
+
add(x) {
|
|
40
|
+
const n = super.add.call(this.toDecimal(), x);
|
|
41
|
+
return this.clone(n);
|
|
42
|
+
}
|
|
43
|
+
// @ts-expect-error overrides
|
|
44
|
+
sub(x) {
|
|
45
|
+
const n = super.sub.call(this.toDecimal(), x);
|
|
46
|
+
return this.clone(n);
|
|
47
|
+
}
|
|
48
|
+
// @ts-expect-error overrides
|
|
49
|
+
div(x) {
|
|
50
|
+
const n = super.div.call(this.toDecimal(), x);
|
|
51
|
+
return this.clone(n);
|
|
52
|
+
}
|
|
53
|
+
// @ts-expect-error overrides
|
|
54
|
+
mul(x) {
|
|
55
|
+
const n = super.mul.call(this.toDecimal(), x);
|
|
56
|
+
return this.clone(n);
|
|
57
|
+
}
|
|
58
|
+
toDecimal() {
|
|
59
|
+
return super.clone.call(this);
|
|
60
|
+
}
|
|
61
|
+
toString() {
|
|
62
|
+
const number = this.toNumber();
|
|
63
|
+
return this.numberFormat.format(number);
|
|
64
|
+
}
|
|
65
|
+
format(opts = {}, locale) {
|
|
66
|
+
const number = this.toNumber();
|
|
67
|
+
opts = defaults(opts, this.options);
|
|
68
|
+
return new Intl.NumberFormat(locale ?? this.locale, opts).format(number);
|
|
69
|
+
}
|
|
70
|
+
displayName() {
|
|
71
|
+
return this.format({ currencyDisplay: 'name' });
|
|
72
|
+
}
|
|
73
|
+
accounting() {
|
|
74
|
+
return this.format({ currencySign: 'accounting' });
|
|
75
|
+
}
|
|
76
|
+
precision(digits) {
|
|
77
|
+
return this.format({ maximumFractionDigits: digits });
|
|
78
|
+
}
|
|
79
|
+
eq(x) {
|
|
80
|
+
if (x?.currency && x.currency !== this.currency) {
|
|
81
|
+
return false;
|
|
82
|
+
}
|
|
83
|
+
return super.eq.call(this, x);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { Duration, DurationUnit, TDuration } from '../duration.js';
|
|
2
2
|
import { asDate, formatDate, strftime } from '../format.js';
|
|
3
|
-
import {
|
|
3
|
+
import { DateObject, daysInMonth, daysInYear, isLeapYear, maxDate, minDate, weeksInYear } from './utils.js';
|
|
4
4
|
export { asDate, daysInMonth, daysInYear, formatDate, isLeapYear, maxDate, minDate, strftime, weeksInYear };
|
|
5
|
-
|
|
6
|
-
declare type
|
|
7
|
-
export
|
|
5
|
+
export { DateObject };
|
|
6
|
+
export declare type DateInput = number | string | Date;
|
|
7
|
+
export declare type DateLike = DateInput | IntlDate | DateObject;
|
|
8
8
|
/**
|
|
9
9
|
* Creates a date tied to a given locale (default system locale) which can be formatted in that locale's language using the native {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl Intl Apis} directly or using a formatting string.
|
|
10
10
|
* @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl Intl Apis}
|
|
@@ -49,7 +49,7 @@ export declare class IntlDate {
|
|
|
49
49
|
/** Get the number of days in this date's month. */
|
|
50
50
|
daysInMonth(): number;
|
|
51
51
|
/** Get the number of days in this date's year. */
|
|
52
|
-
daysInYear():
|
|
52
|
+
daysInYear(): number;
|
|
53
53
|
dayOfYear(): number;
|
|
54
54
|
/** Returns `true` if this date's year is a leap year. */
|
|
55
55
|
isLeapYear(): boolean;
|
|
@@ -137,7 +137,7 @@ export declare class IntlDate {
|
|
|
137
137
|
* Returns an object containing year, month, day-of-month, hours, minutes, seconds, milliseconds.
|
|
138
138
|
* @returns {Object} An object like `{year, month, date, hours, minutes, seconds, ms}`
|
|
139
139
|
*/
|
|
140
|
-
toObject():
|
|
140
|
+
toObject(): DateObject;
|
|
141
141
|
/** Returns the number of milliseconds since the Unix Epoch (January 1, 1970 UTC) */
|
|
142
142
|
getTime(): number;
|
|
143
143
|
/** Alias of {@link IntlDate.getTime} */
|
|
@@ -176,7 +176,7 @@ export declare class IntlDate {
|
|
|
176
176
|
lt(other: Date | IntlDate): boolean;
|
|
177
177
|
eq(other: Date | IntlDate): boolean;
|
|
178
178
|
compare(other: Date | IntlDate): number;
|
|
179
|
-
set(values:
|
|
179
|
+
set(values: DateObject): IntlDate;
|
|
180
180
|
get relativeFormat(): Intl.RelativeTimeFormat;
|
|
181
181
|
relativeTime(n: number, unit?: Intl.RelativeTimeFormatUnit): string;
|
|
182
182
|
fromNow(unit?: Intl.RelativeTimeFormatUnit): string;
|
|
@@ -193,7 +193,7 @@ export declare class IntlDate {
|
|
|
193
193
|
static min(...args: any[]): any;
|
|
194
194
|
inspect(): string;
|
|
195
195
|
}
|
|
196
|
-
export declare function addDuration(date: DateInput, duration: number |
|
|
196
|
+
export declare function addDuration(date: DateInput, duration: number | Duration | TDuration, exact?: boolean): Date;
|
|
197
197
|
/**
|
|
198
198
|
* Subtract the specified years, months, weeks, days, hours, minutes and seconds from the given date.
|
|
199
199
|
* @param date
|
|
@@ -201,4 +201,4 @@ export declare function addDuration(date: DateInput, duration: number | TDuratio
|
|
|
201
201
|
* @param exact
|
|
202
202
|
* @returns
|
|
203
203
|
*/
|
|
204
|
-
export declare function subDuration(date: DateInput, duration: TDuration, exact?: boolean): Date;
|
|
204
|
+
export declare function subDuration(date: DateInput, duration: number | Duration | TDuration, exact?: boolean): Date;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export declare type
|
|
1
|
+
export declare type DateObject = {
|
|
2
2
|
year?: number;
|
|
3
3
|
month?: number;
|
|
4
4
|
day?: number;
|
|
@@ -33,7 +33,7 @@ export declare function isLeapYear(year: number): boolean;
|
|
|
33
33
|
* @param year The date year
|
|
34
34
|
* @returns {number} Number of days in year
|
|
35
35
|
*/
|
|
36
|
-
export declare function daysInYear(year: number):
|
|
36
|
+
export declare function daysInYear(year: number): number;
|
|
37
37
|
/**
|
|
38
38
|
* Get the number of days in the given date's month and year.
|
|
39
39
|
* @param date The specified date
|
|
@@ -61,5 +61,5 @@ export declare function weekOfYear(date: string | number | Date, firstDayOfWeek?
|
|
|
61
61
|
week: any;
|
|
62
62
|
year: any;
|
|
63
63
|
};
|
|
64
|
-
export declare function isoWeeksInYear(year:
|
|
64
|
+
export declare function isoWeeksInYear(year: number): number;
|
|
65
65
|
export declare function dayOfYear(input: string | number | Date): number;
|
package/dist/i18n/date/utils.js
CHANGED
|
@@ -1,25 +1,3 @@
|
|
|
1
|
-
import { isInteger, ValueError } from '../../globals/index.js';
|
|
2
|
-
function bestBy(arr, by, compare) {
|
|
3
|
-
if (arr.length === 0) {
|
|
4
|
-
return undefined;
|
|
5
|
-
}
|
|
6
|
-
return arr.reduce((best, next) => {
|
|
7
|
-
const pair = [by(next), next];
|
|
8
|
-
if (!best) {
|
|
9
|
-
return pair;
|
|
10
|
-
}
|
|
11
|
-
else if (compare(best[0], pair[0]) === best[0]) {
|
|
12
|
-
return best;
|
|
13
|
-
}
|
|
14
|
-
else {
|
|
15
|
-
return pair;
|
|
16
|
-
}
|
|
17
|
-
}, null)[1];
|
|
18
|
-
}
|
|
19
|
-
// NUMBERS AND STRINGS
|
|
20
|
-
function integerBetween(thing, bottom, top) {
|
|
21
|
-
return isInteger(thing) && thing >= bottom && thing <= top;
|
|
22
|
-
}
|
|
23
1
|
/**
|
|
24
2
|
* Returns x % n but takes the sign of n instead of x
|
|
25
3
|
* @param x
|
|
@@ -138,13 +116,13 @@ function parseZoneInfo(ts, offsetFormat, locale, timeZone) {
|
|
|
138
116
|
day: '2-digit',
|
|
139
117
|
hour: '2-digit',
|
|
140
118
|
minute: '2-digit',
|
|
141
|
-
timeZone
|
|
119
|
+
timeZone,
|
|
120
|
+
timeZoneName: offsetFormat
|
|
142
121
|
};
|
|
143
|
-
const
|
|
144
|
-
const parsed = new Intl.DateTimeFormat(locale, modified)
|
|
122
|
+
const parsed = new Intl.DateTimeFormat(locale, intlOpts)
|
|
145
123
|
.formatToParts(date)
|
|
146
|
-
.find((m) => m.type
|
|
147
|
-
return parsed
|
|
124
|
+
.find((m) => m.type === 'timeZoneName');
|
|
125
|
+
return parsed?.value;
|
|
148
126
|
}
|
|
149
127
|
// signedOffset('-5', '30') -> -330
|
|
150
128
|
function signedOffset(offHourStr, offMinuteStr) {
|
|
@@ -160,7 +138,7 @@ function signedOffset(offHourStr, offMinuteStr) {
|
|
|
160
138
|
export function asNumber(value) {
|
|
161
139
|
const numericValue = Number(value);
|
|
162
140
|
if (typeof value === 'boolean' || value === '' || Number.isNaN(numericValue))
|
|
163
|
-
throw new
|
|
141
|
+
throw new Error(`Invalid unit value ${value}`);
|
|
164
142
|
return numericValue;
|
|
165
143
|
}
|
|
166
144
|
function formatOffset(offset, format) {
|
package/dist/i18n/format.d.ts
CHANGED
|
@@ -18,9 +18,9 @@ export declare function formatDate(formatStr: string, date: Date, locale?: strin
|
|
|
18
18
|
/**
|
|
19
19
|
* Formats a date using a formatting string in the {@link https://strftime.org/ strftime} format, in any given locale.
|
|
20
20
|
* @param {string} fmt The format string to apply
|
|
21
|
-
* @param {
|
|
21
|
+
* @param {Date} date The date value
|
|
22
22
|
* @param {?string} locale The locale to use when formatting (default is system locale).
|
|
23
23
|
* @returns {string} The string representation of date
|
|
24
24
|
* @see {@link https://strftime.org/ strftime format}
|
|
25
25
|
*/
|
|
26
|
-
export declare function strftime(fmt: string, date:
|
|
26
|
+
export declare function strftime(fmt: string, date: Date, locale?: string): string;
|
package/dist/i18n/format.js
CHANGED
|
@@ -217,7 +217,7 @@ export function formatDate(formatStr, date, locale) {
|
|
|
217
217
|
/**
|
|
218
218
|
* Formats a date using a formatting string in the {@link https://strftime.org/ strftime} format, in any given locale.
|
|
219
219
|
* @param {string} fmt The format string to apply
|
|
220
|
-
* @param {
|
|
220
|
+
* @param {Date} date The date value
|
|
221
221
|
* @param {?string} locale The locale to use when formatting (default is system locale).
|
|
222
222
|
* @returns {string} The string representation of date
|
|
223
223
|
* @see {@link https://strftime.org/ strftime format}
|
package/dist/i18n/index.d.ts
CHANGED
package/dist/i18n/index.js
CHANGED
|
@@ -31,7 +31,7 @@ all([2, 4, 6] => (n) => n > 1)
|
|
|
31
31
|
```
|
|
32
32
|
@see {@link any}
|
|
33
33
|
*/
|
|
34
|
-
export declare const all: <T>(iterable: Iterable<T>, fn?: Predicate<T>) => boolean;
|
|
34
|
+
export declare const all: <T>(iterable: Iterable<T>, fn?: Predicate<T, any>) => boolean;
|
|
35
35
|
/**
|
|
36
36
|
* Returns true when any of the items in iterable are truthy. An optional predicate function can be used to define what truthiness means for this specific collection.
|
|
37
37
|
* @param iterable
|
|
@@ -50,7 +50,7 @@ any([1, 4, 5] => (n) => n % 2 === 0)
|
|
|
50
50
|
```
|
|
51
51
|
@see {@link all}
|
|
52
52
|
*/
|
|
53
|
-
export declare const any: <T>(iterable: Iterable<T>, fn?: Predicate<T>) => boolean;
|
|
53
|
+
export declare const any: <T>(iterable: Iterable<T>, fn?: Predicate<T, any>) => boolean;
|
|
54
54
|
export declare function chain<T>(...iterables: Array<Iterable<T>>): Generator<T, void, unknown>;
|
|
55
55
|
/**
|
|
56
56
|
* Checks if the `value` is in `collection`.
|
|
@@ -81,9 +81,9 @@ export declare function contains(collection: Iterable<any>, value: any): any;
|
|
|
81
81
|
* @param predicate A function invoked per element to check if it should be dropped.
|
|
82
82
|
* @returns Elements
|
|
83
83
|
*/
|
|
84
|
-
export declare function dropWhile<T>(iterable: Iterable<T>, predicate: Predicate): Generator<
|
|
84
|
+
export declare function dropWhile<T>(iterable: Iterable<T>, predicate: Predicate<T>): Generator<T, T, unknown>;
|
|
85
85
|
export declare function iforEach<T>(iterable: Iterable<T>, fun: Iteratee<T>): void;
|
|
86
|
-
export declare function IterableIterator<T = any>(next:
|
|
86
|
+
export declare function IterableIterator<T = any>(next: Iterator<T>['next']): Iterable<T> & Iterator<T>;
|
|
87
87
|
/**
|
|
88
88
|
* Yields elements like `[index, item]` from an iterable. Index starts at zero by default.
|
|
89
89
|
* @template T
|
|
@@ -100,13 +100,13 @@ console.log([...enumerate(['hello', 'world'], 1)])
|
|
|
100
100
|
// [[1, 'hello'], [2, 'world']]
|
|
101
101
|
```
|
|
102
102
|
*/
|
|
103
|
-
export declare function enumerate<T
|
|
103
|
+
export declare function enumerate<T>(iterable: Iterable<T>, start?: number): Generator<[number, T], void, unknown>;
|
|
104
104
|
/**
|
|
105
105
|
* Returns the first element in an iterable.
|
|
106
106
|
* @param iterable The iterable to inspect.
|
|
107
107
|
* @returns The first element found or undefined if iterable is empty.
|
|
108
108
|
*/
|
|
109
|
-
export declare function first<T>(iterable: Iterable<T>):
|
|
109
|
+
export declare function first<T>(iterable: Iterable<T>): T;
|
|
110
110
|
/**
|
|
111
111
|
* Creates a new generator that filters all falsy and empty values from iterable.
|
|
112
112
|
* @param arr The array to compact
|
|
@@ -121,8 +121,8 @@ export declare function icompact<T>(iterable: Iterable<T>): Generator<T, void, u
|
|
|
121
121
|
/**
|
|
122
122
|
* Iterates over elements of collection, producing only those elements where predicate returns a `truthy` value.
|
|
123
123
|
*/
|
|
124
|
-
export declare function ifilter<T>(iterable: Iterable<T>, predicate: Predicate): Generator<T, void, unknown>;
|
|
125
|
-
export declare function imap<T, TReturn = any>(iterable: Iterable<T>, mapFn:
|
|
124
|
+
export declare function ifilter<T>(iterable: Iterable<T>, predicate: Predicate<T, boolean>): Generator<T, void, unknown>;
|
|
125
|
+
export declare function imap<T, TReturn = any>(iterable: Iterable<T>, mapFn: Predicate<T, TReturn>): Generator<TReturn, void, unknown>;
|
|
126
126
|
/**
|
|
127
127
|
* Returns a generator flattening one level of nesting in a list of lists.
|
|
128
128
|
* @param iterables The iterable to flatten
|
|
@@ -134,15 +134,15 @@ export declare function imap<T, TReturn = any>(iterable: Iterable<T>, mapFn: (x:
|
|
|
134
134
|
*/
|
|
135
135
|
export declare function iflatten<T = any>(iterables: Iterable<Iterable<T>>): Generator<T, void, unknown>;
|
|
136
136
|
export declare function flatMap<T>(iterable: Iterable<T>, mapFn?: (x: T) => any): Generator<T, void, unknown>;
|
|
137
|
-
export declare function islice<T>(iterable: Iterable<T>, start: number, stop?: number, step?: number): Generator<
|
|
138
|
-
export declare function itake<T>(n: number, iterable: Iterable<T>): Generator<
|
|
137
|
+
export declare function islice<T>(iterable: Iterable<T>, start: number, stop?: number, step?: number): Generator<T, T, unknown>;
|
|
138
|
+
export declare function itake<T>(n: number, iterable: Iterable<T>): Generator<T, void, unknown>;
|
|
139
139
|
/**
|
|
140
140
|
* Returns an Iterator from the elements of a collection or the object keys.
|
|
141
141
|
* @param obj The given collection to iterate over.
|
|
142
142
|
* @returns An Iterator type.
|
|
143
143
|
*/
|
|
144
|
-
export declare function iter<T>(obj: any): Iterator<T>;
|
|
145
|
-
export declare function partition<T>(iterable: Iterable<T>, predicate: Predicate<T>): T[][];
|
|
144
|
+
export declare function iter<T>(obj: any): Iterator<T, T>;
|
|
145
|
+
export declare function partition<T>(iterable: Iterable<T>, predicate: Predicate<T, boolean>): [T[], T[]];
|
|
146
146
|
/**
|
|
147
147
|
* Returns a generator for a sequence of numbers in the given range, starting from `start` (default 0) to `stop` (not-inclusive) in increments of `step` (default 1).
|
|
148
148
|
*
|
|
@@ -187,23 +187,51 @@ export declare function reduce<T>(iterable: Iterable<T>, reducer: (prev: T, valu
|
|
|
187
187
|
* @returns A new array with the elements reversed.
|
|
188
188
|
*/
|
|
189
189
|
export declare function reversed<T>(iterable: Iterable<T>): T[];
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
190
|
+
/**
|
|
191
|
+
* Creates a new sorted list from the elements in the array. This can be called many ways:
|
|
192
|
+
* - sorted([...], true) => reverse order
|
|
193
|
+
* - sorted([...], fn = (x) => any) => using a key fn
|
|
194
|
+
* - sorted([...], fn = (x) => any, true) => reverse order using key
|
|
195
|
+
* - sorted([...], false, (x, y) => number) => using custom compare
|
|
196
|
+
* - sorted([...], fn = (x) => any, true, (x, y) => number) => custom key, reverse and compare
|
|
197
|
+
*
|
|
198
|
+
* If `args` is an Object, returns the sorted keys.
|
|
199
|
+
*
|
|
200
|
+
*
|
|
201
|
+
* @param {(Array | Object)} args
|
|
202
|
+
* @param {(boolean | Function)} [key]
|
|
203
|
+
* @param {(boolean | Comparer)} [reverse]
|
|
204
|
+
* @param {Comparer} [compareFn]
|
|
205
|
+
* @return
|
|
206
|
+
*/
|
|
207
|
+
export declare function sorted<T>(args: T[]): T[];
|
|
208
|
+
export declare function sorted<T>(args: T[], reverse: boolean): T[];
|
|
209
|
+
export declare function sorted<T>(args: T[], reverse: boolean, comp: Comparer): T[];
|
|
210
|
+
export declare function sorted<T>(args: T[], key: Function): T[];
|
|
211
|
+
export declare function sorted<T>(args: T[], key: Function, reverse: boolean): T[];
|
|
212
|
+
/**
|
|
213
|
+
* Sort `args` in place. Can be called like this:
|
|
214
|
+
* - sort([...], true) => reverse order
|
|
215
|
+
* - sort([...], (x, y) => number) => using custom compare
|
|
216
|
+
* - sort([...], true, (x, y) => number) => reverse and using custom compare
|
|
217
|
+
*
|
|
218
|
+
* @param {any[]} args
|
|
219
|
+
* @param {(boolean | Comparer)} [reverse]
|
|
220
|
+
* @param {Comparer} [compareFn]
|
|
221
|
+
* @return
|
|
222
|
+
*/
|
|
223
|
+
export declare function sort<T>(args: T[]): T[];
|
|
224
|
+
export declare function sort<T>(args: T[], reverse: boolean): T[];
|
|
225
|
+
export declare function sort<T>(args: T[], compareFn: Comparer): T[];
|
|
226
|
+
export declare function sort<T>(args: T[], reverse: boolean, compareFn: Comparer): T[];
|
|
227
|
+
export declare function take<T>(n: number, iterable: Iterable<T>): T[];
|
|
200
228
|
/**
|
|
201
229
|
* Returns a generator that takes elements from the iterable as long as the predicate is `true`.
|
|
202
230
|
* @param iterable The iterable to inspect.
|
|
203
231
|
* @param predicate A function invoked per element to check if it should be taken.
|
|
204
232
|
* @returns Elements
|
|
205
233
|
*/
|
|
206
|
-
export declare function takeWhile<T>(iterable: Iterable<T>, predicate: Predicate): Generator<T, void, unknown>;
|
|
234
|
+
export declare function takeWhile<T>(iterable: Iterable<T>, predicate: Predicate<T>): Generator<T, void, unknown>;
|
|
207
235
|
/** Returns a generator that calls `fn(index)` for each index < n */
|
|
208
236
|
/**
|
|
209
237
|
* Returns a generator that produces `fn(index)` for each `index < n`.
|
package/dist/itertools/index.js
CHANGED
|
@@ -109,7 +109,6 @@ export function contains(collection, value) {
|
|
|
109
109
|
return includes;
|
|
110
110
|
return any(collection, (x) => eq(value, x));
|
|
111
111
|
}
|
|
112
|
-
const compKey = (compare, key) => (x, y) => compare(key(x), key(y));
|
|
113
112
|
/**
|
|
114
113
|
* Returns a generator that drops elements from the iterable as long as the predicate is `true`; afterwards, returns every remaining element. Note, the generator does not produce any output until the predicate first becomes `false`.
|
|
115
114
|
* @param iterable The iterable to inspect.
|
|
@@ -142,13 +141,12 @@ export function iforEach(iterable, fun) {
|
|
|
142
141
|
}
|
|
143
142
|
}
|
|
144
143
|
export function IterableIterator(next) {
|
|
145
|
-
|
|
144
|
+
return {
|
|
146
145
|
next,
|
|
147
146
|
[Symbol.iterator]() {
|
|
148
147
|
return this;
|
|
149
148
|
}
|
|
150
149
|
};
|
|
151
|
-
return it;
|
|
152
150
|
}
|
|
153
151
|
/**
|
|
154
152
|
* Yields elements like `[index, item]` from an iterable. Index starts at zero by default.
|
|
@@ -353,26 +351,11 @@ export function reduce(iterable, reducer, initial) {
|
|
|
353
351
|
export function reversed(iterable) {
|
|
354
352
|
return Array.from(iterable).reverse();
|
|
355
353
|
}
|
|
356
|
-
|
|
357
|
-
* Creates a new sorted list from the elements in the array. This can be called many ways:
|
|
358
|
-
* - sorted([...], true) => reverse order
|
|
359
|
-
* - sorted([...], fn = (x) => any) => using a key fn
|
|
360
|
-
* - sorted([...], fn = (x) => any, true) => reverse order using key
|
|
361
|
-
* - sorted([...], false, (x, y) => number) => using custom compare
|
|
362
|
-
* - sorted([...], fn = (x) => any, true, (x, y) => number) => custom key, reverse and compare
|
|
363
|
-
*
|
|
364
|
-
* If `args` is an Object, returns the sorted keys.
|
|
365
|
-
*
|
|
366
|
-
*
|
|
367
|
-
* @param {(Array | Object)} args
|
|
368
|
-
* @param {(boolean | Function)} [key]
|
|
369
|
-
* @param {(boolean | Comparer)} [reverse]
|
|
370
|
-
* @param {Comparer} [compareFn]
|
|
371
|
-
* @return
|
|
372
|
-
*/
|
|
354
|
+
const compKey = (compare, key) => (x, y) => compare(key(x), key(y));
|
|
373
355
|
export function sorted(args, key, reverse, compareFn) {
|
|
374
|
-
if (isObject(args))
|
|
356
|
+
if (isObject(args)) {
|
|
375
357
|
args = Object.keys(args);
|
|
358
|
+
}
|
|
376
359
|
if (typeof key === 'boolean') {
|
|
377
360
|
if (typeof reverse === 'function') {
|
|
378
361
|
compareFn = reverse;
|
|
@@ -390,17 +373,6 @@ export function sorted(args, key, reverse, compareFn) {
|
|
|
390
373
|
copy.reverse();
|
|
391
374
|
return copy;
|
|
392
375
|
}
|
|
393
|
-
/**
|
|
394
|
-
* Sort `args` in place. Can be called like this:
|
|
395
|
-
* - sort([...], true) => reverse order
|
|
396
|
-
* - sort([...], (x, y) => number) => using custom compare
|
|
397
|
-
* - sort([...], true, (x, y) => number) => reverse and using custom compare
|
|
398
|
-
*
|
|
399
|
-
* @param {any[]} args
|
|
400
|
-
* @param {(boolean | Comparer)} [reverse]
|
|
401
|
-
* @param {Comparer} [compareFn]
|
|
402
|
-
* @return
|
|
403
|
-
*/
|
|
404
376
|
export function sort(args, reverse, compareFn) {
|
|
405
377
|
if (typeof reverse === 'function') {
|
|
406
378
|
compareFn = reverse;
|
package/dist/math/index.d.ts
CHANGED
|
@@ -43,7 +43,7 @@ export declare const ceil: (x: number) => number;
|
|
|
43
43
|
* @param y
|
|
44
44
|
* @returns
|
|
45
45
|
*/
|
|
46
|
-
export declare function divmod(x: number, y: number): number
|
|
46
|
+
export declare function divmod(x: number, y: number): [number, number];
|
|
47
47
|
export declare function log2(x: any): number;
|
|
48
48
|
export declare function logBase(x: any, y: any): number;
|
|
49
49
|
/**
|
|
@@ -66,7 +66,7 @@ export declare function max<T>(iterable: Iterable<T>, key?: Predicate<T>): T;
|
|
|
66
66
|
* Computes the mean of the values in `iterable` and accepts an optional `key` function which is invoked for each element to generate the values to be averaged.
|
|
67
67
|
* @param {Array<number>|Iterable<T>} iterable
|
|
68
68
|
* @param {Function} [key] Optional iteratee invoked per element.
|
|
69
|
-
* @returns Returns the mean value or `
|
|
69
|
+
* @returns Returns the mean value or `NaN` if no elements.
|
|
70
70
|
* @template T
|
|
71
71
|
* @example
|
|
72
72
|
```js
|
|
@@ -76,8 +76,8 @@ mean(objects, (o) => o.n)
|
|
|
76
76
|
// 5
|
|
77
77
|
```
|
|
78
78
|
*/
|
|
79
|
-
export declare function mean(iterable: number[]):
|
|
80
|
-
export declare function mean<T>(iterable: Iterable<T>, key?: Predicate<T>):
|
|
79
|
+
export declare function mean(iterable: number[]): number;
|
|
80
|
+
export declare function mean<T>(iterable: Iterable<T>, key?: Predicate<T>): number;
|
|
81
81
|
/**
|
|
82
82
|
* Sums `initial` and the items of an iterable and returns the total.
|
|
83
83
|
* @param args The elements to add to `initial`.
|
|
@@ -92,6 +92,5 @@ sum([1, 2, 3, 4], 5)
|
|
|
92
92
|
// 15
|
|
93
93
|
```
|
|
94
94
|
*/
|
|
95
|
-
export declare function sum(
|
|
96
|
-
export declare function sum<T>(
|
|
97
|
-
export declare function sum<T>(iterable: Iterable<T>, key?: Predicate<T>): T;
|
|
95
|
+
export declare function sum(args: number[]): number;
|
|
96
|
+
export declare function sum<T>(args: Iterable<T>, key?: Predicate<T>): number;
|
package/dist/math/index.js
CHANGED
|
@@ -81,7 +81,9 @@ export function mean(iterable, key = id) {
|
|
|
81
81
|
total += key(value);
|
|
82
82
|
count++;
|
|
83
83
|
}
|
|
84
|
-
|
|
84
|
+
if (count !== 0)
|
|
85
|
+
return total / count;
|
|
86
|
+
return Number.NaN;
|
|
85
87
|
}
|
|
86
88
|
export function sum(args, key = id) {
|
|
87
89
|
let initial = 0;
|
|
@@ -72,7 +72,7 @@ export declare function lte(x: any, y: any): boolean;
|
|
|
72
72
|
* @param {*} y
|
|
73
73
|
* @returns {boolean} `true` if `x` is strictly greater than `y` or `false` otherwise.
|
|
74
74
|
*/
|
|
75
|
-
export declare function gt(x: any, y: any):
|
|
75
|
+
export declare function gt(x: any, y: any): boolean;
|
|
76
76
|
/**
|
|
77
77
|
* Compares two values to check if `x >= y`. If `x` is an object with a `gte` method, it returns `x.gte(y)`, also checks `x.eq(y)` and `x.gt(y)`.
|
|
78
78
|
* Otherwise it returns the result of `x >= y`.
|
|
@@ -145,4 +145,4 @@ export declare function shallowEqual(obj: any, other: any): boolean;
|
|
|
145
145
|
* @param other
|
|
146
146
|
* @returns `true` if the objects are considered equal.
|
|
147
147
|
*/
|
|
148
|
-
export declare function deepEqual(obj: any, other: any, checker?:
|
|
148
|
+
export declare function deepEqual(obj: any, other: any, checker?: Function, seen?: any): boolean;
|
package/dist/operators/index.js
CHANGED
|
@@ -231,12 +231,6 @@ export function shallowEqual(obj, other) {
|
|
|
231
231
|
}
|
|
232
232
|
return false;
|
|
233
233
|
}
|
|
234
|
-
/**
|
|
235
|
-
* Performs a recursive comparison of two objects or arrays to check if they have the same keys, length and values. Unlike {@link shallowEqual} this method compares nested values also.
|
|
236
|
-
* @param obj
|
|
237
|
-
* @param other
|
|
238
|
-
* @returns `true` if the objects are considered equal.
|
|
239
|
-
*/
|
|
240
234
|
export function deepEqual(obj, other, checker = eq, seen = new WeakSet()) {
|
|
241
235
|
if (checker(obj, other))
|
|
242
236
|
return true;
|
package/dist/random/index.d.ts
CHANGED
|
@@ -22,7 +22,7 @@ export declare const randomInt: (min?: number, max?: number) => number;
|
|
|
22
22
|
* @returns {T}
|
|
23
23
|
* @template T
|
|
24
24
|
*/
|
|
25
|
-
export declare
|
|
25
|
+
export declare function choice<T>(arr: T[]): T;
|
|
26
26
|
/**
|
|
27
27
|
* Returns a random sample of size k from a list of items.
|
|
28
28
|
* @param {Array} arr
|