@glissandoo/lib 1.17.4 → 1.17.6
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/helpers/audios.js +3 -3
- package/helpers/auth.d.ts +3 -3
- package/helpers/badges.d.ts +1 -1
- package/helpers/badges.js +2 -2
- package/helpers/fileSections/orders.js +2 -2
- package/helpers/musicStyles/index.d.ts +1 -1
- package/helpers/musicStyles/orders.js +2 -2
- package/helpers/notifications.d.ts +2 -2
- package/helpers/objects.d.ts +4 -4
- package/helpers/objects.js +10 -10
- package/helpers/ts-extras/array-includes.d.ts +21 -0
- package/helpers/ts-extras/array-includes.js +27 -0
- package/helpers/ts-extras/as-mutable.d.ts +16 -0
- package/helpers/ts-extras/as-mutable.js +21 -0
- package/helpers/ts-extras/assert-error.d.ts +30 -0
- package/helpers/ts-extras/assert-error.js +38 -0
- package/helpers/ts-extras/index.d.ts +15 -0
- package/helpers/ts-extras/index.js +33 -0
- package/helpers/ts-extras/is-defined.d.ts +16 -0
- package/helpers/ts-extras/is-defined.js +22 -0
- package/helpers/ts-extras/is-empty.d.ts +20 -0
- package/helpers/ts-extras/is-empty.js +7 -0
- package/helpers/ts-extras/is-finite.d.ts +8 -0
- package/helpers/ts-extras/is-finite.js +10 -0
- package/helpers/ts-extras/is-infinite.d.ts +7 -0
- package/helpers/ts-extras/is-infinite.js +12 -0
- package/helpers/ts-extras/is-integer.d.ts +8 -0
- package/helpers/ts-extras/is-integer.js +10 -0
- package/helpers/ts-extras/is-present.d.ts +16 -0
- package/helpers/ts-extras/is-present.js +22 -0
- package/helpers/ts-extras/is-safe-integer.d.ts +8 -0
- package/helpers/ts-extras/is-safe-integer.js +10 -0
- package/helpers/ts-extras/object-entries.d.ts +23 -0
- package/helpers/ts-extras/object-entries.js +25 -0
- package/helpers/ts-extras/object-from-entries.d.ts +26 -0
- package/helpers/ts-extras/object-from-entries.js +29 -0
- package/helpers/ts-extras/object-has-own.d.ts +20 -0
- package/helpers/ts-extras/object-has-own.js +26 -0
- package/helpers/ts-extras/object-keys.d.ts +21 -0
- package/helpers/ts-extras/object-keys.js +24 -0
- package/helpers/ts-extras/set-has.d.ts +22 -0
- package/helpers/ts-extras/set-has.js +28 -0
- package/helpers/types.d.ts +1 -1
- package/helpers/utils.js +15 -15
- package/lang/index.d.ts +1 -1
- package/lang/index.js +1 -1
- package/models/Communication/Comment/index.js +1 -1
- package/models/Communication/index.js +3 -3
- package/models/Counters/Group/Analytics/index.js +2 -2
- package/models/Evento/Player/index.js +1 -1
- package/models/Evento/Repertory/index.js +1 -1
- package/models/Evento/basic.js +3 -3
- package/models/Evento/index.js +5 -5
- package/models/Evento/tiny.js +1 -1
- package/models/Evento/types.d.ts +1 -1
- package/models/Federation/Partnership/index.js +1 -1
- package/models/Federation/index.js +1 -1
- package/models/Group/Analytics/index.js +2 -2
- package/models/Group/Event/index.js +1 -1
- package/models/Group/Player/Event/index.js +2 -2
- package/models/Group/Player/Log/types.d.ts +2 -2
- package/models/Group/Player/index.js +5 -5
- package/models/Group/Player/types.d.ts +1 -1
- package/models/Group/Repertory/File/Section/index.js +2 -2
- package/models/Group/Repertory/File/Section/types.d.ts +1 -1
- package/models/Group/Repertory/File/index.js +1 -1
- package/models/Group/Repertory/index.js +6 -6
- package/models/Group/Repertory/types.d.ts +2 -2
- package/models/Group/basic.js +1 -1
- package/models/Group/index.js +7 -7
- package/models/Instrument/index.js +1 -1
- package/models/Metrics/types.d.ts +1 -1
- package/models/MusicStyle/index.js +2 -2
- package/models/Partner/index.js +1 -1
- package/models/Partnership/Group/index.js +1 -1
- package/models/Partnership/Partner/Subscription/index.js +2 -2
- package/models/Partnership/Partner/index.js +1 -1
- package/models/Partnership/Plan/basic.js +6 -6
- package/models/Partnership/Plan/index.js +1 -1
- package/models/Partnership/basic.js +1 -1
- package/models/Payment/basic.js +1 -1
- package/models/Player/basic.js +1 -1
- package/models/Repertory/types.d.ts +1 -1
- package/models/User/Group/index.js +2 -2
- package/models/User/Notification/index.js +4 -4
- package/models/User/Notification/types.d.ts +1 -1
- package/models/User/index.d.ts +2 -1
- package/models/User/index.js +2 -2
- package/package.json +6 -6
- package/functions/auth.d.ts.map +0 -1
- package/functions/communication.d.ts.map +0 -1
- package/functions/communicationComment.d.ts.map +0 -1
- package/functions/event.d.ts.map +0 -1
- package/functions/eventPlayer.d.ts.map +0 -1
- package/functions/eventRepertory.d.ts.map +0 -1
- package/functions/federation.d.ts.map +0 -1
- package/functions/federationPartnership.d.ts.map +0 -1
- package/functions/group.d.ts.map +0 -1
- package/functions/groupPlayer.d.ts.map +0 -1
- package/functions/groupRepertory.d.ts.map +0 -1
- package/functions/index.d.ts.map +0 -1
- package/functions/jwt.d.ts.map +0 -1
- package/functions/misc.d.ts.map +0 -1
- package/functions/notification.d.ts.map +0 -1
- package/functions/partner.d.ts.map +0 -1
- package/functions/partnership.d.ts.map +0 -1
- package/functions/partnershipGroup.d.ts.map +0 -1
- package/functions/partnershipPlan.d.ts.map +0 -1
- package/functions/regions.d.ts.map +0 -1
- package/functions/subscription.d.ts.map +0 -1
- package/functions/user.d.ts.map +0 -1
- package/helpers/appScenes.d.ts.map +0 -1
- package/helpers/auth.d.ts.map +0 -1
- package/helpers/badges.d.ts.map +0 -1
- package/helpers/collections.d.ts.map +0 -1
- package/helpers/dlinks.d.ts.map +0 -1
- package/helpers/errors.d.ts.map +0 -1
- package/helpers/fileSections/index.d.ts.map +0 -1
- package/helpers/fileSections/orders.d.ts.map +0 -1
- package/helpers/instruments/index.d.ts.map +0 -1
- package/helpers/musicStyles/index.d.ts.map +0 -1
- package/helpers/musicStyles/orders.d.ts.map +0 -1
- package/helpers/notifications.d.ts.map +0 -1
- package/helpers/payments.d.ts.map +0 -1
- package/helpers/plans.d.ts.map +0 -1
- package/helpers/rates.d.ts.map +0 -1
- package/helpers/reasons.d.ts.map +0 -1
- package/helpers/slate.d.ts.map +0 -1
- package/helpers/styles.d.ts.map +0 -1
- package/helpers/types.d.ts.map +0 -1
- package/helpers/utils.d.ts.map +0 -1
- package/index.d.ts.map +0 -1
- package/lang/index.d.ts.map +0 -1
- package/models/Communication/Comment/index.d.ts.map +0 -1
- package/models/Communication/Comment/types.d.ts.map +0 -1
- package/models/Communication/index.d.ts.map +0 -1
- package/models/Communication/types.d.ts.map +0 -1
- package/models/Counters/Group/Analytics/index.d.ts.map +0 -1
- package/models/Counters/Group/Analytics/types.d.ts.map +0 -1
- package/models/Counters/Group/index.d.ts.map +0 -1
- package/models/Counters/Group/types.d.ts.map +0 -1
- package/models/Counters/event.d.ts.map +0 -1
- package/models/Counters/index.d.ts.map +0 -1
- package/models/Counters/types.d.ts.map +0 -1
- package/models/Evento/Player/index.d.ts.map +0 -1
- package/models/Evento/Player/types.d.ts.map +0 -1
- package/models/Evento/Repertory/index.d.ts.map +0 -1
- package/models/Evento/Repertory/types.d.ts.map +0 -1
- package/models/Evento/basic.d.ts.map +0 -1
- package/models/Evento/index.d.ts.map +0 -1
- package/models/Evento/promoter.d.ts.map +0 -1
- package/models/Evento/tiny.d.ts.map +0 -1
- package/models/Evento/types.d.ts.map +0 -1
- package/models/Federation/Partnership/index.d.ts.map +0 -1
- package/models/Federation/Partnership/types.d.ts.map +0 -1
- package/models/Federation/index.d.ts.map +0 -1
- package/models/Federation/types.d.ts.map +0 -1
- package/models/Group/Analytics/index.d.ts.map +0 -1
- package/models/Group/Analytics/types.d.ts.map +0 -1
- package/models/Group/Event/index.d.ts.map +0 -1
- package/models/Group/Event/types.d.ts.map +0 -1
- package/models/Group/Player/Event/index.d.ts.map +0 -1
- package/models/Group/Player/Event/types.d.ts.map +0 -1
- package/models/Group/Player/Log/index.d.ts.map +0 -1
- package/models/Group/Player/Log/types.d.ts.map +0 -1
- package/models/Group/Player/index.d.ts.map +0 -1
- package/models/Group/Player/types.d.ts.map +0 -1
- package/models/Group/Repertory/File/Section/index.d.ts.map +0 -1
- package/models/Group/Repertory/File/Section/types.d.ts.map +0 -1
- package/models/Group/Repertory/File/index.d.ts.map +0 -1
- package/models/Group/Repertory/File/types.d.ts.map +0 -1
- package/models/Group/Repertory/index.d.ts.map +0 -1
- package/models/Group/Repertory/types.d.ts.map +0 -1
- package/models/Group/basic.d.ts.map +0 -1
- package/models/Group/index.d.ts.map +0 -1
- package/models/Group/types.d.ts.map +0 -1
- package/models/Instrument/index.d.ts.map +0 -1
- package/models/Metrics/index.d.ts.map +0 -1
- package/models/Metrics/types.d.ts.map +0 -1
- package/models/Model.d.ts.map +0 -1
- package/models/MusicStyle/index.d.ts.map +0 -1
- package/models/Notification/index.d.ts.map +0 -1
- package/models/Notification/types.d.ts.map +0 -1
- package/models/Partner/basic.d.ts.map +0 -1
- package/models/Partner/index.d.ts.map +0 -1
- package/models/Partner/tiny.d.ts.map +0 -1
- package/models/Partner/types.d.ts.map +0 -1
- package/models/Partnership/Group/index.d.ts.map +0 -1
- package/models/Partnership/Group/types.d.ts.map +0 -1
- package/models/Partnership/Partner/Subscription/index.d.ts.map +0 -1
- package/models/Partnership/Partner/Subscription/types.d.ts.map +0 -1
- package/models/Partnership/Partner/index.d.ts.map +0 -1
- package/models/Partnership/Partner/types.d.ts.map +0 -1
- package/models/Partnership/Payment/index.d.ts.map +0 -1
- package/models/Partnership/Payment/types.d.ts.map +0 -1
- package/models/Partnership/Plan/basic.d.ts.map +0 -1
- package/models/Partnership/Plan/index.d.ts.map +0 -1
- package/models/Partnership/Plan/types.d.ts.map +0 -1
- package/models/Partnership/basic.d.ts.map +0 -1
- package/models/Partnership/index.d.ts.map +0 -1
- package/models/Partnership/types.d.ts.map +0 -1
- package/models/Payment/basic.d.ts.map +0 -1
- package/models/Payment/index.d.ts.map +0 -1
- package/models/Payment/types.d.ts.map +0 -1
- package/models/Player/basic.d.ts.map +0 -1
- package/models/Player/types.d.ts.map +0 -1
- package/models/Repertory/basic.d.ts.map +0 -1
- package/models/Repertory/types.d.ts.map +0 -1
- package/models/User/Group/index.d.ts.map +0 -1
- package/models/User/Group/types.d.ts.map +0 -1
- package/models/User/Notification/index.d.ts.map +0 -1
- package/models/User/Notification/types.d.ts.map +0 -1
- package/models/User/basic.d.ts.map +0 -1
- package/models/User/index.d.ts.map +0 -1
- package/models/User/types.d.ts.map +0 -1
package/helpers/audios.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.audioExtensionToMimeType = exports.audioMimeTypes = exports.audioExtensions = void 0;
|
|
4
4
|
const lodash_1 = require("lodash");
|
|
5
|
-
const ts_extras_1 = require("ts-extras");
|
|
5
|
+
const ts_extras_1 = require("./ts-extras");
|
|
6
6
|
const extensionToMimetype = {
|
|
7
7
|
'.abs': 'audio/x-mpeg',
|
|
8
8
|
'.aif': 'audio/x-aiff',
|
|
@@ -28,7 +28,7 @@ const extensionToMimetype = {
|
|
|
28
28
|
'.ulw': 'audio/basic',
|
|
29
29
|
'.wav': 'audio/x-wav',
|
|
30
30
|
};
|
|
31
|
-
exports.audioExtensions = ts_extras_1.objectKeys(extensionToMimetype);
|
|
32
|
-
exports.audioMimeTypes = lodash_1.uniq(Object.values(extensionToMimetype));
|
|
31
|
+
exports.audioExtensions = (0, ts_extras_1.objectKeys)(extensionToMimetype);
|
|
32
|
+
exports.audioMimeTypes = (0, lodash_1.uniq)(Object.values(extensionToMimetype));
|
|
33
33
|
const audioExtensionToMimeType = (ext) => extensionToMimetype[ext];
|
|
34
34
|
exports.audioExtensionToMimeType = audioExtensionToMimeType;
|
package/helpers/auth.d.ts
CHANGED
|
@@ -17,10 +17,10 @@ export declare enum AuthErrors {
|
|
|
17
17
|
NoPartnerhispAdmin = "error.auth.noPartnershipAdmin",
|
|
18
18
|
Unauthenticated = "error.auth.unauthenticated"
|
|
19
19
|
}
|
|
20
|
-
export
|
|
20
|
+
export type AuthURLParams = {
|
|
21
21
|
error?: string;
|
|
22
22
|
return_to?: string;
|
|
23
23
|
callbackFbName?: FbFunctionName;
|
|
24
24
|
callbackFbParam?: string;
|
|
25
|
-
}
|
|
26
|
-
export declare const getAuthURL: (path: string, lang: LanguagesTypes, params?: AuthURLParams
|
|
25
|
+
};
|
|
26
|
+
export declare const getAuthURL: (path: string, lang: LanguagesTypes, params?: AuthURLParams) => string;
|
package/helpers/badges.d.ts
CHANGED
|
@@ -18,4 +18,4 @@ export declare const getLevelsDataBadge: (field: BadgesTypes) => {
|
|
|
18
18
|
[level: number]: BadgeDataLevel;
|
|
19
19
|
};
|
|
20
20
|
export declare const getLevelsCountBadge: (field: BadgesTypes) => number[];
|
|
21
|
-
export declare const getImageLevelBadge: (field: BadgesTypes, level: number, disabled?: boolean
|
|
21
|
+
export declare const getImageLevelBadge: (field: BadgesTypes, level: number, disabled?: boolean) => string;
|
package/helpers/badges.js
CHANGED
|
@@ -147,12 +147,12 @@ const getLevelsDataBadge = (field) => {
|
|
|
147
147
|
};
|
|
148
148
|
exports.getLevelsDataBadge = getLevelsDataBadge;
|
|
149
149
|
const getLevelsCountBadge = (field) => {
|
|
150
|
-
const data = exports.getLevelsDataBadge(field);
|
|
150
|
+
const data = (0, exports.getLevelsDataBadge)(field);
|
|
151
151
|
return Object.values(data).map((item) => item.count);
|
|
152
152
|
};
|
|
153
153
|
exports.getLevelsCountBadge = getLevelsCountBadge;
|
|
154
154
|
const getImageLevelBadge = (field, level, disabled) => {
|
|
155
|
-
const imagePath = get_1.default(exports.badgesLevels, [
|
|
155
|
+
const imagePath = (0, get_1.default)(exports.badgesLevels, [
|
|
156
156
|
field,
|
|
157
157
|
level,
|
|
158
158
|
disabled ? 'imagePathDisabled' : 'imagePath',
|
|
@@ -14,7 +14,7 @@ const getOrderByMusicStyle = (musicStyle) => {
|
|
|
14
14
|
};
|
|
15
15
|
exports.getOrderByMusicStyle = getOrderByMusicStyle;
|
|
16
16
|
const orderByMusicStyle = (list, field, musicStyle) => {
|
|
17
|
-
const order = exports.getOrderByMusicStyle(musicStyle);
|
|
18
|
-
return utils_1.orderByMatch(list, field, order);
|
|
17
|
+
const order = (0, exports.getOrderByMusicStyle)(musicStyle);
|
|
18
|
+
return (0, utils_1.orderByMatch)(list, field, order);
|
|
19
19
|
};
|
|
20
20
|
exports.orderByMusicStyle = orderByMusicStyle;
|
|
@@ -13,6 +13,6 @@ export declare enum MusicStyleId {
|
|
|
13
13
|
Choir = "coro"
|
|
14
14
|
}
|
|
15
15
|
export declare const MusicStylesCover: Record<MusicStyleId, string>;
|
|
16
|
-
export
|
|
16
|
+
export type MusicStyleType = MusicStyleId | string;
|
|
17
17
|
export declare const musicStyleByCountry: Record<LanguagesTypes, MusicStyleId[]>;
|
|
18
18
|
export declare const list: (lang: LanguagesTypes, filteredByCountry?: boolean) => MusicStyle[];
|
|
@@ -187,7 +187,7 @@ const getInstrumentsOrderByMusicStyle = (musicStyle) => {
|
|
|
187
187
|
};
|
|
188
188
|
exports.getInstrumentsOrderByMusicStyle = getInstrumentsOrderByMusicStyle;
|
|
189
189
|
const orderByMusicStyle = (list, field, musicStyle) => {
|
|
190
|
-
const order = exports.getInstrumentsOrderByMusicStyle(musicStyle);
|
|
191
|
-
return utils_1.orderByMatch(list, field, order);
|
|
190
|
+
const order = (0, exports.getInstrumentsOrderByMusicStyle)(musicStyle);
|
|
191
|
+
return (0, utils_1.orderByMatch)(list, field, order);
|
|
192
192
|
};
|
|
193
193
|
exports.orderByMusicStyle = orderByMusicStyle;
|
|
@@ -27,9 +27,9 @@ export declare enum NotificationEventActions {
|
|
|
27
27
|
ReminderMorningPending = "reminderMorningPending",
|
|
28
28
|
ReminderRollcall = "reminderRollcall"
|
|
29
29
|
}
|
|
30
|
-
|
|
30
|
+
type RealtionScopeToNotification = Record<EventoFbFunctionsTypes.EditScope, NotificationEventActions>;
|
|
31
31
|
export declare const editScopeToAction: RealtionScopeToNotification;
|
|
32
|
-
|
|
32
|
+
type RelationActionNotification = Record<NotificationEventActions, NotificationActions>;
|
|
33
33
|
export declare const notificationPerformance: RelationActionNotification;
|
|
34
34
|
export declare const notificationSinglePractice: RelationActionNotification;
|
|
35
35
|
export declare const notificationMultiplePractice: RelationActionNotification;
|
package/helpers/objects.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export declare const
|
|
1
|
+
export declare const mapToArray: <V>(obj: Record<string, V>) => (V & {
|
|
2
2
|
id: string;
|
|
3
3
|
})[];
|
|
4
|
-
export declare const map: <KIn extends string, VIn, KOut extends string, VOut>(obj: Record<KIn, VIn>, fn: (key: `${KIn}`, value: VIn, index?: number
|
|
5
|
-
export declare const filter: <K extends string, V>(obj: Record<K, V>, fn: (key: `${Exclude<K, symbol>}`, value: V, index?: number
|
|
6
|
-
export declare const forEach: <K extends string, V>(obj: Record<K, V>, fn: (key: `${Exclude<K, symbol>}`, value: V, index?: number
|
|
4
|
+
export declare const map: <KIn extends string, VIn, KOut extends string, VOut>(obj: Record<KIn, VIn>, fn: (key: `${KIn}`, value: VIn, index?: number) => [KOut, VOut]) => Record<KOut, VOut>;
|
|
5
|
+
export declare const filter: <K extends string, V>(obj: Record<K, V>, fn: (key: `${Exclude<K, symbol>}`, value: V, index?: number) => unknown) => Record<`${Exclude<K, symbol>}`, V>;
|
|
6
|
+
export declare const forEach: <K extends string, V>(obj: Record<K, V>, fn: (key: `${Exclude<K, symbol>}`, value: V, index?: number) => unknown) => void;
|
package/helpers/objects.js
CHANGED
|
@@ -1,28 +1,28 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.forEach = exports.filter = exports.map = exports.
|
|
4
|
-
const ts_extras_1 = require("ts-extras");
|
|
5
|
-
const
|
|
6
|
-
return ts_extras_1.objectEntries(obj).map(([key, value]) => ({
|
|
3
|
+
exports.forEach = exports.filter = exports.map = exports.mapToArray = void 0;
|
|
4
|
+
const ts_extras_1 = require("./ts-extras");
|
|
5
|
+
const mapToArray = (obj) => {
|
|
6
|
+
return (0, ts_extras_1.objectEntries)(obj).map(([key, value]) => ({
|
|
7
7
|
...value,
|
|
8
8
|
id: key,
|
|
9
9
|
}));
|
|
10
10
|
};
|
|
11
|
-
exports.
|
|
11
|
+
exports.mapToArray = mapToArray;
|
|
12
12
|
const map = (obj, fn) => {
|
|
13
|
-
const entries = ts_extras_1.objectEntries(obj);
|
|
13
|
+
const entries = (0, ts_extras_1.objectEntries)(obj);
|
|
14
14
|
const mappedEntries = entries.map(([key, value], index) => fn(key, value, index));
|
|
15
|
-
return ts_extras_1.objectFromEntries(mappedEntries);
|
|
15
|
+
return (0, ts_extras_1.objectFromEntries)(mappedEntries);
|
|
16
16
|
};
|
|
17
17
|
exports.map = map;
|
|
18
18
|
const filter = (obj, fn) => {
|
|
19
|
-
const entries = ts_extras_1.objectEntries(obj);
|
|
19
|
+
const entries = (0, ts_extras_1.objectEntries)(obj);
|
|
20
20
|
const filteredEntries = entries.filter(([key, value], index) => fn(key, value, index));
|
|
21
|
-
return ts_extras_1.objectFromEntries(filteredEntries);
|
|
21
|
+
return (0, ts_extras_1.objectFromEntries)(filteredEntries);
|
|
22
22
|
};
|
|
23
23
|
exports.filter = filter;
|
|
24
24
|
const forEach = (obj, fn) => {
|
|
25
|
-
const entries = ts_extras_1.objectEntries(obj);
|
|
25
|
+
const entries = (0, ts_extras_1.objectEntries)(obj);
|
|
26
26
|
return entries.forEach(([key, value], index) => fn(key, value, index));
|
|
27
27
|
};
|
|
28
28
|
exports.forEach = forEach;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
An alternative to `Array#includes()` that properly acts as a type guard.
|
|
3
|
+
|
|
4
|
+
It was [rejected](https://github.com/microsoft/TypeScript/issues/26255#issuecomment-748211891) from being done in TypeScript itself.
|
|
5
|
+
|
|
6
|
+
@example
|
|
7
|
+
```
|
|
8
|
+
import {arrayIncludes} from 'ts-extras';
|
|
9
|
+
|
|
10
|
+
const values = ['a', 'b', 'c'] as const;
|
|
11
|
+
const valueToCheck: unknown = 'a';
|
|
12
|
+
|
|
13
|
+
if (arrayIncludes(values, valueToCheck)) {
|
|
14
|
+
// We now know that the value is of type `typeof values[number]`.
|
|
15
|
+
}
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
@category Improved builtin
|
|
19
|
+
@category Type guard
|
|
20
|
+
*/
|
|
21
|
+
export declare function arrayIncludes<Type extends SuperType, SuperType = unknown>(array: Type[] | readonly Type[], item: SuperType, fromIndex?: number): item is Type;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.arrayIncludes = void 0;
|
|
4
|
+
/**
|
|
5
|
+
An alternative to `Array#includes()` that properly acts as a type guard.
|
|
6
|
+
|
|
7
|
+
It was [rejected](https://github.com/microsoft/TypeScript/issues/26255#issuecomment-748211891) from being done in TypeScript itself.
|
|
8
|
+
|
|
9
|
+
@example
|
|
10
|
+
```
|
|
11
|
+
import {arrayIncludes} from 'ts-extras';
|
|
12
|
+
|
|
13
|
+
const values = ['a', 'b', 'c'] as const;
|
|
14
|
+
const valueToCheck: unknown = 'a';
|
|
15
|
+
|
|
16
|
+
if (arrayIncludes(values, valueToCheck)) {
|
|
17
|
+
// We now know that the value is of type `typeof values[number]`.
|
|
18
|
+
}
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
@category Improved builtin
|
|
22
|
+
@category Type guard
|
|
23
|
+
*/
|
|
24
|
+
function arrayIncludes(array, item, fromIndex) {
|
|
25
|
+
return array.includes(item, fromIndex);
|
|
26
|
+
}
|
|
27
|
+
exports.arrayIncludes = arrayIncludes;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Writable } from 'type-fest';
|
|
2
|
+
/**
|
|
3
|
+
Cast the given value to be [`Mutable`](https://github.com/sindresorhus/type-fest/blob/main/source/mutable.d.ts).
|
|
4
|
+
|
|
5
|
+
This is useful because of a TypeScript limitation: https://github.com/microsoft/TypeScript/issues/45618#issuecomment-908072756
|
|
6
|
+
|
|
7
|
+
@example
|
|
8
|
+
```
|
|
9
|
+
import {asMutable} from 'ts-extras';
|
|
10
|
+
|
|
11
|
+
const mutableContext = asMutable((await import('x')).context);
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
@category General
|
|
15
|
+
*/
|
|
16
|
+
export declare function asMutable<T>(value: T): Writable<T>;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.asMutable = void 0;
|
|
4
|
+
/**
|
|
5
|
+
Cast the given value to be [`Mutable`](https://github.com/sindresorhus/type-fest/blob/main/source/mutable.d.ts).
|
|
6
|
+
|
|
7
|
+
This is useful because of a TypeScript limitation: https://github.com/microsoft/TypeScript/issues/45618#issuecomment-908072756
|
|
8
|
+
|
|
9
|
+
@example
|
|
10
|
+
```
|
|
11
|
+
import {asMutable} from 'ts-extras';
|
|
12
|
+
|
|
13
|
+
const mutableContext = asMutable((await import('x')).context);
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
@category General
|
|
17
|
+
*/
|
|
18
|
+
function asMutable(value) {
|
|
19
|
+
return value; // eslint-disable-line @typescript-eslint/no-unsafe-return,@typescript-eslint/no-explicit-any
|
|
20
|
+
}
|
|
21
|
+
exports.asMutable = asMutable;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
Assert that the given value is an `Error`.
|
|
3
|
+
|
|
4
|
+
If the value is not an `Error`, a helpful `TypeError` will be thrown.
|
|
5
|
+
|
|
6
|
+
This can be useful as any value could potentially be thrown, but in practice, it's always an `Error`. However, because of this, TypeScript makes the caught error in a try/catch statement `unknown`, which is inconvenient to deal with.
|
|
7
|
+
|
|
8
|
+
@example
|
|
9
|
+
```
|
|
10
|
+
import {assertError} from 'ts-extras';
|
|
11
|
+
|
|
12
|
+
try {
|
|
13
|
+
fetchUnicorns();
|
|
14
|
+
} catch (error: unknown) {
|
|
15
|
+
assertError(error)
|
|
16
|
+
|
|
17
|
+
// `error` is now of type `Error`
|
|
18
|
+
|
|
19
|
+
if (error.message === 'Failed to fetch') {
|
|
20
|
+
retry();
|
|
21
|
+
returnl
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
throw error;
|
|
25
|
+
}
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
@category Type guard
|
|
29
|
+
*/
|
|
30
|
+
export declare function assertError(value: unknown): asserts value is Error;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.assertError = void 0;
|
|
4
|
+
/**
|
|
5
|
+
Assert that the given value is an `Error`.
|
|
6
|
+
|
|
7
|
+
If the value is not an `Error`, a helpful `TypeError` will be thrown.
|
|
8
|
+
|
|
9
|
+
This can be useful as any value could potentially be thrown, but in practice, it's always an `Error`. However, because of this, TypeScript makes the caught error in a try/catch statement `unknown`, which is inconvenient to deal with.
|
|
10
|
+
|
|
11
|
+
@example
|
|
12
|
+
```
|
|
13
|
+
import {assertError} from 'ts-extras';
|
|
14
|
+
|
|
15
|
+
try {
|
|
16
|
+
fetchUnicorns();
|
|
17
|
+
} catch (error: unknown) {
|
|
18
|
+
assertError(error)
|
|
19
|
+
|
|
20
|
+
// `error` is now of type `Error`
|
|
21
|
+
|
|
22
|
+
if (error.message === 'Failed to fetch') {
|
|
23
|
+
retry();
|
|
24
|
+
returnl
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
throw error;
|
|
28
|
+
}
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
@category Type guard
|
|
32
|
+
*/
|
|
33
|
+
function assertError(value) {
|
|
34
|
+
if (!(value instanceof Error || Object.prototype.toString.call(value) === '[object Error]')) {
|
|
35
|
+
throw new TypeError(`Expected an \`Error\`, got \`${JSON.stringify(value)}\` (${typeof value})`);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
exports.assertError = assertError;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export { arrayIncludes } from './array-includes';
|
|
2
|
+
export { asMutable } from './as-mutable';
|
|
3
|
+
export { assertError } from './assert-error';
|
|
4
|
+
export { isDefined } from './is-defined';
|
|
5
|
+
export { isPresent } from './is-present';
|
|
6
|
+
export { isEmpty } from './is-empty';
|
|
7
|
+
export { isFinite } from './is-finite';
|
|
8
|
+
export { isInfinite } from './is-infinite';
|
|
9
|
+
export { isInteger } from './is-integer';
|
|
10
|
+
export { isSafeInteger } from './is-safe-integer';
|
|
11
|
+
export { objectEntries } from './object-entries';
|
|
12
|
+
export { objectFromEntries } from './object-from-entries';
|
|
13
|
+
export { objectHasOwn } from './object-has-own';
|
|
14
|
+
export { objectKeys } from './object-keys';
|
|
15
|
+
export { setHas } from './set-has';
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.setHas = exports.objectKeys = exports.objectHasOwn = exports.objectFromEntries = exports.objectEntries = exports.isSafeInteger = exports.isInteger = exports.isInfinite = exports.isFinite = exports.isEmpty = exports.isPresent = exports.isDefined = exports.assertError = exports.asMutable = exports.arrayIncludes = void 0;
|
|
4
|
+
var array_includes_1 = require("./array-includes");
|
|
5
|
+
Object.defineProperty(exports, "arrayIncludes", { enumerable: true, get: function () { return array_includes_1.arrayIncludes; } });
|
|
6
|
+
var as_mutable_1 = require("./as-mutable");
|
|
7
|
+
Object.defineProperty(exports, "asMutable", { enumerable: true, get: function () { return as_mutable_1.asMutable; } });
|
|
8
|
+
var assert_error_1 = require("./assert-error");
|
|
9
|
+
Object.defineProperty(exports, "assertError", { enumerable: true, get: function () { return assert_error_1.assertError; } });
|
|
10
|
+
var is_defined_1 = require("./is-defined");
|
|
11
|
+
Object.defineProperty(exports, "isDefined", { enumerable: true, get: function () { return is_defined_1.isDefined; } });
|
|
12
|
+
var is_present_1 = require("./is-present");
|
|
13
|
+
Object.defineProperty(exports, "isPresent", { enumerable: true, get: function () { return is_present_1.isPresent; } });
|
|
14
|
+
var is_empty_1 = require("./is-empty");
|
|
15
|
+
Object.defineProperty(exports, "isEmpty", { enumerable: true, get: function () { return is_empty_1.isEmpty; } });
|
|
16
|
+
var is_finite_1 = require("./is-finite");
|
|
17
|
+
Object.defineProperty(exports, "isFinite", { enumerable: true, get: function () { return is_finite_1.isFinite; } });
|
|
18
|
+
var is_infinite_1 = require("./is-infinite");
|
|
19
|
+
Object.defineProperty(exports, "isInfinite", { enumerable: true, get: function () { return is_infinite_1.isInfinite; } });
|
|
20
|
+
var is_integer_1 = require("./is-integer");
|
|
21
|
+
Object.defineProperty(exports, "isInteger", { enumerable: true, get: function () { return is_integer_1.isInteger; } });
|
|
22
|
+
var is_safe_integer_1 = require("./is-safe-integer");
|
|
23
|
+
Object.defineProperty(exports, "isSafeInteger", { enumerable: true, get: function () { return is_safe_integer_1.isSafeInteger; } });
|
|
24
|
+
var object_entries_1 = require("./object-entries");
|
|
25
|
+
Object.defineProperty(exports, "objectEntries", { enumerable: true, get: function () { return object_entries_1.objectEntries; } });
|
|
26
|
+
var object_from_entries_1 = require("./object-from-entries");
|
|
27
|
+
Object.defineProperty(exports, "objectFromEntries", { enumerable: true, get: function () { return object_from_entries_1.objectFromEntries; } });
|
|
28
|
+
var object_has_own_1 = require("./object-has-own");
|
|
29
|
+
Object.defineProperty(exports, "objectHasOwn", { enumerable: true, get: function () { return object_has_own_1.objectHasOwn; } });
|
|
30
|
+
var object_keys_1 = require("./object-keys");
|
|
31
|
+
Object.defineProperty(exports, "objectKeys", { enumerable: true, get: function () { return object_keys_1.objectKeys; } });
|
|
32
|
+
var set_has_1 = require("./set-has");
|
|
33
|
+
Object.defineProperty(exports, "setHas", { enumerable: true, get: function () { return set_has_1.setHas; } });
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
Check whether a value is defined, meaning it is not `undefined`.
|
|
3
|
+
|
|
4
|
+
This can be useful as a type guard, as for example, `[1, undefined].filter(Boolean)` does not always type-guard correctly.
|
|
5
|
+
|
|
6
|
+
@example
|
|
7
|
+
```
|
|
8
|
+
import {isDefined} from 'ts-extras';
|
|
9
|
+
|
|
10
|
+
[1, undefined, 2].filter(isDefined);
|
|
11
|
+
//=> [1, 2]
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
@category Type guard
|
|
15
|
+
*/
|
|
16
|
+
export declare function isDefined<T>(value: T | undefined): value is T;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isDefined = void 0;
|
|
4
|
+
/**
|
|
5
|
+
Check whether a value is defined, meaning it is not `undefined`.
|
|
6
|
+
|
|
7
|
+
This can be useful as a type guard, as for example, `[1, undefined].filter(Boolean)` does not always type-guard correctly.
|
|
8
|
+
|
|
9
|
+
@example
|
|
10
|
+
```
|
|
11
|
+
import {isDefined} from 'ts-extras';
|
|
12
|
+
|
|
13
|
+
[1, undefined, 2].filter(isDefined);
|
|
14
|
+
//=> [1, 2]
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
@category Type guard
|
|
18
|
+
*/
|
|
19
|
+
function isDefined(value) {
|
|
20
|
+
return value !== undefined;
|
|
21
|
+
}
|
|
22
|
+
exports.isDefined = isDefined;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
Check whether an array is empty.
|
|
3
|
+
|
|
4
|
+
This is useful because doing `array.length === 0` on its own won't work as a type-guard.
|
|
5
|
+
|
|
6
|
+
@example
|
|
7
|
+
```
|
|
8
|
+
import {isEmpty} from 'ts-extras';
|
|
9
|
+
|
|
10
|
+
isEmpty([1, 2, 3]);
|
|
11
|
+
//=> false
|
|
12
|
+
|
|
13
|
+
isEmpty([]);
|
|
14
|
+
//=> true
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
@category Type guard
|
|
18
|
+
*/
|
|
19
|
+
export declare function isEmpty(array: readonly unknown[]): array is readonly [];
|
|
20
|
+
export declare function isEmpty(array: unknown[]): array is [];
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isFinite = void 0;
|
|
4
|
+
/**
|
|
5
|
+
An alternative to `Number.isFinite()` that properly acts as a type guard.
|
|
6
|
+
|
|
7
|
+
@category Improved builtin
|
|
8
|
+
@category Type guard
|
|
9
|
+
*/
|
|
10
|
+
exports.isFinite = Number.isFinite;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isInfinite = void 0;
|
|
4
|
+
/**
|
|
5
|
+
Check whether a value is infinite.
|
|
6
|
+
|
|
7
|
+
@category Type guard
|
|
8
|
+
*/
|
|
9
|
+
function isInfinite(value) {
|
|
10
|
+
return !Number.isNaN(value) && !Number.isFinite(value);
|
|
11
|
+
}
|
|
12
|
+
exports.isInfinite = isInfinite;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isInteger = void 0;
|
|
4
|
+
/**
|
|
5
|
+
An alternative to `Number.isInteger()` that properly acts as a type guard.
|
|
6
|
+
|
|
7
|
+
@category Improved builtin
|
|
8
|
+
@category Type guard
|
|
9
|
+
*/
|
|
10
|
+
exports.isInteger = Number.isInteger;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
Check whether a value is present (non-nullable), meaning it is neither `null` or `undefined`.
|
|
3
|
+
|
|
4
|
+
This can be useful as a type guard, as for example, `[1, null].filter(Boolean)` does not always type-guard correctly.
|
|
5
|
+
|
|
6
|
+
@example
|
|
7
|
+
```
|
|
8
|
+
import {isPresent} from 'ts-extras';
|
|
9
|
+
|
|
10
|
+
[1, null, 2, undefined].filter(isPresent);
|
|
11
|
+
//=> [1, 2]
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
@category Type guard
|
|
15
|
+
*/
|
|
16
|
+
export declare function isPresent<T>(value: T): value is NonNullable<T>;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isPresent = void 0;
|
|
4
|
+
/**
|
|
5
|
+
Check whether a value is present (non-nullable), meaning it is neither `null` or `undefined`.
|
|
6
|
+
|
|
7
|
+
This can be useful as a type guard, as for example, `[1, null].filter(Boolean)` does not always type-guard correctly.
|
|
8
|
+
|
|
9
|
+
@example
|
|
10
|
+
```
|
|
11
|
+
import {isPresent} from 'ts-extras';
|
|
12
|
+
|
|
13
|
+
[1, null, 2, undefined].filter(isPresent);
|
|
14
|
+
//=> [1, 2]
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
@category Type guard
|
|
18
|
+
*/
|
|
19
|
+
function isPresent(value) {
|
|
20
|
+
return value !== null && value !== undefined;
|
|
21
|
+
}
|
|
22
|
+
exports.isPresent = isPresent;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Integer } from 'type-fest';
|
|
2
|
+
/**
|
|
3
|
+
An alternative to `Number.isSafeInteger()` that properly acts as a type guard.
|
|
4
|
+
|
|
5
|
+
@category Improved builtin
|
|
6
|
+
@category Type guard
|
|
7
|
+
*/
|
|
8
|
+
export declare const isSafeInteger: <T extends number>(value: T) => value is Integer<T>;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isSafeInteger = void 0;
|
|
4
|
+
/**
|
|
5
|
+
An alternative to `Number.isSafeInteger()` that properly acts as a type guard.
|
|
6
|
+
|
|
7
|
+
@category Improved builtin
|
|
8
|
+
@category Type guard
|
|
9
|
+
*/
|
|
10
|
+
exports.isSafeInteger = Number.isSafeInteger;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { ObjectKeys } from './object-keys';
|
|
2
|
+
/**
|
|
3
|
+
A strongly-typed version of `Object.entries()`.
|
|
4
|
+
|
|
5
|
+
This is useful since `Object.entries()` always returns an array of `Array<[string, T]>`. This function returns a strongly-typed array of the entries of the given object.
|
|
6
|
+
|
|
7
|
+
- [TypeScript issues about this](https://github.com/microsoft/TypeScript/pull/12253)
|
|
8
|
+
|
|
9
|
+
@example
|
|
10
|
+
```
|
|
11
|
+
import {objectEntries} from 'ts-extras';
|
|
12
|
+
|
|
13
|
+
const stronglyTypedEntries = objectEntries({a: 1, b: 2, c: 3});
|
|
14
|
+
//=> Array<['a' | 'b' | 'c', number]>
|
|
15
|
+
|
|
16
|
+
const untypedEntries = Object.entries(items);
|
|
17
|
+
//=> Array<[string, number]>
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
@category Improved builtin
|
|
21
|
+
@category Type guard
|
|
22
|
+
*/
|
|
23
|
+
export declare const objectEntries: <Type extends Record<PropertyKey, unknown>>(value: Type) => [`${Exclude<keyof Type, symbol>}`, Type[`${Exclude<keyof Type, symbol>}`]][];
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.objectEntries = void 0;
|
|
4
|
+
/**
|
|
5
|
+
A strongly-typed version of `Object.entries()`.
|
|
6
|
+
|
|
7
|
+
This is useful since `Object.entries()` always returns an array of `Array<[string, T]>`. This function returns a strongly-typed array of the entries of the given object.
|
|
8
|
+
|
|
9
|
+
- [TypeScript issues about this](https://github.com/microsoft/TypeScript/pull/12253)
|
|
10
|
+
|
|
11
|
+
@example
|
|
12
|
+
```
|
|
13
|
+
import {objectEntries} from 'ts-extras';
|
|
14
|
+
|
|
15
|
+
const stronglyTypedEntries = objectEntries({a: 1, b: 2, c: 3});
|
|
16
|
+
//=> Array<['a' | 'b' | 'c', number]>
|
|
17
|
+
|
|
18
|
+
const untypedEntries = Object.entries(items);
|
|
19
|
+
//=> Array<[string, number]>
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
@category Improved builtin
|
|
23
|
+
@category Type guard
|
|
24
|
+
*/
|
|
25
|
+
exports.objectEntries = Object.entries;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
A strongly-typed version of `Object.fromEntries()`.
|
|
3
|
+
|
|
4
|
+
This is useful since `Object.fromEntries()` always returns `{[key: string]: T}`. This function returns a strongly-typed object from the given array of entries.
|
|
5
|
+
|
|
6
|
+
- [TypeScript issues about this](https://github.com/microsoft/TypeScript/issues/35745)
|
|
7
|
+
|
|
8
|
+
@example
|
|
9
|
+
```
|
|
10
|
+
import {objectFromEntries} from 'ts-extras';
|
|
11
|
+
|
|
12
|
+
const stronglyTypedObjectFromEntries = objectFromEntries([
|
|
13
|
+
['a', 123],
|
|
14
|
+
['b', 'someString'],
|
|
15
|
+
['c', true],
|
|
16
|
+
]);
|
|
17
|
+
//=> {a: number; b: string; c: boolean}
|
|
18
|
+
|
|
19
|
+
const untypedEntries = Object.fromEntries(entries);
|
|
20
|
+
//=> {[key: string]: string}
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
@category Improved builtin
|
|
24
|
+
@category Type guard
|
|
25
|
+
*/
|
|
26
|
+
export declare const objectFromEntries: <Key extends PropertyKey, Entries extends readonly (readonly [Key, unknown])[]>(values: Entries) => { [K in Extract<Entries[number], readonly [Key, unknown]>[0]]: Extract<Entries[number], readonly [K, unknown]>[1]; };
|