shelving 1.148.0 → 1.149.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/package.json +1 -1
- package/util/array.d.ts +3 -0
- package/util/array.js +6 -1
- package/util/iterate.d.ts +3 -0
- package/util/iterate.js +9 -0
package/package.json
CHANGED
package/util/array.d.ts
CHANGED
|
@@ -95,6 +95,9 @@ export declare function getUniqueArray<T>(list: PossibleArray<T>): ImmutableArra
|
|
|
95
95
|
export declare function limitArray<T>(list: PossibleArray<T>, limit: number): ImmutableArray<T>;
|
|
96
96
|
/** Count the items in an array. */
|
|
97
97
|
export declare function countArray<T>(arr: ImmutableArray<T>): number;
|
|
98
|
+
/** Interleave array items with a separator */
|
|
99
|
+
export declare function interleaveArray<T>(items: PossibleArray<T>, separator: T): ImmutableArray<T>;
|
|
100
|
+
export declare function interleaveArray<A, B>(items: PossibleArray<A>, separator: B): ImmutableArray<A | B>;
|
|
98
101
|
/** Get the first item from an array or iterable, or `undefined` if it didn't exist. */
|
|
99
102
|
export declare function getFirst<T>(items: PossibleArray<T>): T | undefined;
|
|
100
103
|
/** Get the first item from an array or iterable. */
|
package/util/array.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { RequiredError } from "../error/RequiredError.js";
|
|
2
|
-
import { omitItems, pickItems } from "./iterate.js";
|
|
2
|
+
import { interleaveItems, omitItems, pickItems } from "./iterate.js";
|
|
3
3
|
export function isArray(value, min = 0, max = Number.POSITIVE_INFINITY) {
|
|
4
4
|
return Array.isArray(value) && value.length >= min && value.length <= max;
|
|
5
5
|
}
|
|
@@ -112,6 +112,11 @@ export function limitArray(list, limit) {
|
|
|
112
112
|
export function countArray(arr) {
|
|
113
113
|
return arr.length;
|
|
114
114
|
}
|
|
115
|
+
export function interleaveArray(items, separator) {
|
|
116
|
+
if (isArray(items) && items.length < 2)
|
|
117
|
+
return items; // Return same empty array if empty or only one item.
|
|
118
|
+
return Array.from(interleaveItems(items, separator));
|
|
119
|
+
}
|
|
115
120
|
/** Get the first item from an array or iterable, or `undefined` if it didn't exist. */
|
|
116
121
|
export function getFirst(items) {
|
|
117
122
|
if (isArray(items))
|
package/util/iterate.d.ts
CHANGED
|
@@ -34,3 +34,6 @@ export declare function reduceItems<I, O>(items: Iterable<I>, reducer: (previous
|
|
|
34
34
|
export declare function getChunks<T>(items: Iterable<T>, size: number): Iterable<readonly T[]>;
|
|
35
35
|
/** Merge two or more iterables into a single iterable set. */
|
|
36
36
|
export declare function mergeItems<T>(...inputs: [Iterable<T>, Iterable<T>, ...Iterable<T>[]]): Iterable<T>;
|
|
37
|
+
/** Intersperse items with a separator */
|
|
38
|
+
export declare function interleaveItems<T>(items: Iterable<T>, separator: T): Iterable<T>;
|
|
39
|
+
export declare function interleaveItems<A, B>(items: Iterable<A>, separator: B): Iterable<A | B>;
|
package/util/iterate.js
CHANGED
|
@@ -87,3 +87,12 @@ export function* mergeItems(...inputs) {
|
|
|
87
87
|
for (const input of inputs)
|
|
88
88
|
yield* input;
|
|
89
89
|
}
|
|
90
|
+
export function* interleaveItems(items, separator) {
|
|
91
|
+
let first = true;
|
|
92
|
+
for (const item of items) {
|
|
93
|
+
if (!first)
|
|
94
|
+
yield separator;
|
|
95
|
+
yield item;
|
|
96
|
+
first = false;
|
|
97
|
+
}
|
|
98
|
+
}
|