@mll-lab/js-utils 2.9.0 → 2.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/array.d.ts +6 -0
- package/dist/index.common.js +11 -0
- package/dist/index.common.js.map +1 -1
- package/dist/index.js +11 -0
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/array.d.ts
CHANGED
|
@@ -23,3 +23,9 @@ export declare const EMPTY_ARRAY: never[];
|
|
|
23
23
|
*/
|
|
24
24
|
export declare function insertIf<T>(condition: boolean, ...elements: Array<T>): Array<T>;
|
|
25
25
|
export declare function last<T, A extends Array<T>>(array: A): A extends NonEmptyArray<T> ? T : T | undefined;
|
|
26
|
+
/**
|
|
27
|
+
* Appends element to array if not included or removes it.
|
|
28
|
+
*
|
|
29
|
+
* Never mutates the given array, always returns a new array.
|
|
30
|
+
*/
|
|
31
|
+
export declare function toggleElement<T>(array: Array<T>, element: T): Array<T>;
|
package/dist/index.common.js
CHANGED
|
@@ -9466,6 +9466,16 @@ function last(array) {
|
|
|
9466
9466
|
// @ts-expect-error too magical
|
|
9467
9467
|
return array[array.length - 1];
|
|
9468
9468
|
}
|
|
9469
|
+
/**
|
|
9470
|
+
* Appends element to array if not included or removes it.
|
|
9471
|
+
*
|
|
9472
|
+
* Never mutates the given array, always returns a new array.
|
|
9473
|
+
*/
|
|
9474
|
+
function toggleElement(array, element) {
|
|
9475
|
+
return array.includes(element)
|
|
9476
|
+
? array.filter((e) => e !== element)
|
|
9477
|
+
: array.concat(element);
|
|
9478
|
+
}
|
|
9469
9479
|
|
|
9470
9480
|
function toInteger(dirtyNumber) {
|
|
9471
9481
|
if (dirtyNumber === null || dirtyNumber === true || dirtyNumber === false) {
|
|
@@ -15271,5 +15281,6 @@ exports.parseSecondlessDateTime = parseSecondlessDateTime;
|
|
|
15271
15281
|
exports.pluralize = pluralize;
|
|
15272
15282
|
exports.pxToNumber = pxToNumber;
|
|
15273
15283
|
exports.round = round;
|
|
15284
|
+
exports.toggleElement = toggleElement;
|
|
15274
15285
|
exports.withoutIndex = withoutIndex;
|
|
15275
15286
|
//# sourceMappingURL=index.common.js.map
|