cafe-utility 9.6.0 → 9.8.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/index.d.ts +4 -0
- package/index.js +30 -2
- package/package.json +1 -1
package/index.d.ts
CHANGED
|
@@ -160,6 +160,7 @@ declare function resolveVariableWithDefaultSyntax(string: string, key: string, v
|
|
|
160
160
|
declare function resolveRemainingVariablesWithDefaults(string: string, prefix?: string, separator?: string): string;
|
|
161
161
|
declare function resolveMarkdownLinks(string: string, transformer: (label: string, link: string) => string): string;
|
|
162
162
|
declare function toQueryString(object: Record<string, any>, questionMark?: boolean): string;
|
|
163
|
+
declare function buildUrl(baseUrl?: string | null, path?: string | null, query?: Record<string, any> | null): string;
|
|
163
164
|
declare function parseCsv(string: string, delimiter?: string, quote?: string): string[];
|
|
164
165
|
declare function humanizeProgress(state: Progress): string;
|
|
165
166
|
declare function waitFor(predicate: () => Promise<boolean>, waitLength: number, maxWaits: number): Promise<boolean>;
|
|
@@ -224,6 +225,7 @@ declare function createOscillator<T>(values: T[]): {
|
|
|
224
225
|
next: () => T;
|
|
225
226
|
};
|
|
226
227
|
declare function createStatefulToggle(desiredValue: unknown): (value: unknown) => boolean;
|
|
228
|
+
declare function organiseWithLimits<T>(items: T[], limits: Record<string, number>, property: keyof T, defaultValue: string, sortFn?: (a: T, b: T) => number): Record<string, T[]>;
|
|
227
229
|
declare function diffKeys(objectA: CafeObject, objectB: CafeObject): {
|
|
228
230
|
uniqueToA: string[];
|
|
229
231
|
uniqueToB: string[];
|
|
@@ -354,6 +356,7 @@ export declare const Arrays: {
|
|
|
354
356
|
atRolling: typeof atRolling;
|
|
355
357
|
group: typeof group;
|
|
356
358
|
createOscillator: typeof createOscillator;
|
|
359
|
+
organiseWithLimits: typeof organiseWithLimits;
|
|
357
360
|
};
|
|
358
361
|
export declare const System: {
|
|
359
362
|
sleepMillis: typeof sleepMillis;
|
|
@@ -543,6 +546,7 @@ export declare const Strings: {
|
|
|
543
546
|
linesMatchInOrder: typeof linesMatchInOrder;
|
|
544
547
|
represent: typeof represent;
|
|
545
548
|
resolveMarkdownLinks: typeof resolveMarkdownLinks;
|
|
549
|
+
buildUrl: typeof buildUrl;
|
|
546
550
|
};
|
|
547
551
|
export declare const Assertions: {
|
|
548
552
|
asEqual: typeof asEqual;
|
package/index.js
CHANGED
|
@@ -1140,6 +1140,10 @@ function toQueryString(object, questionMark = true) {
|
|
|
1140
1140
|
return queryString ? (questionMark ? '?' : '') + queryString : ''
|
|
1141
1141
|
}
|
|
1142
1142
|
|
|
1143
|
+
function buildUrl(baseUrl, path, query) {
|
|
1144
|
+
return joinUrl(baseUrl, path) + toQueryString(query || {})
|
|
1145
|
+
}
|
|
1146
|
+
|
|
1143
1147
|
function parseCsv(string, delimiter = ',', quote = '"') {
|
|
1144
1148
|
const items = []
|
|
1145
1149
|
let buffer = ''
|
|
@@ -1465,6 +1469,28 @@ function createStatefulToggle(desiredValue) {
|
|
|
1465
1469
|
}
|
|
1466
1470
|
}
|
|
1467
1471
|
|
|
1472
|
+
function organiseWithLimits(items, limits, property, defaultValue, sortFn) {
|
|
1473
|
+
const result = {}
|
|
1474
|
+
for (const key of Object.keys(limits)) {
|
|
1475
|
+
result[key] = []
|
|
1476
|
+
}
|
|
1477
|
+
result[defaultValue] = []
|
|
1478
|
+
if (sortFn) {
|
|
1479
|
+
items = items.sort(sortFn)
|
|
1480
|
+
}
|
|
1481
|
+
for (const item of items) {
|
|
1482
|
+
const value = item[property]
|
|
1483
|
+
const key = limits[value] ? value : defaultValue
|
|
1484
|
+
const isFull = result[key].length >= limits[key]
|
|
1485
|
+
if (isFull) {
|
|
1486
|
+
result[defaultValue].push(item)
|
|
1487
|
+
} else {
|
|
1488
|
+
result[key].push(item)
|
|
1489
|
+
}
|
|
1490
|
+
}
|
|
1491
|
+
return result
|
|
1492
|
+
}
|
|
1493
|
+
|
|
1468
1494
|
function diffKeys(objectA, objectB) {
|
|
1469
1495
|
const keysA = Object.keys(objectA)
|
|
1470
1496
|
const keysB = Object.keys(objectB)
|
|
@@ -2293,7 +2319,8 @@ exports.Arrays = {
|
|
|
2293
2319
|
unshiftAndLimit,
|
|
2294
2320
|
atRolling,
|
|
2295
2321
|
group,
|
|
2296
|
-
createOscillator
|
|
2322
|
+
createOscillator,
|
|
2323
|
+
organiseWithLimits
|
|
2297
2324
|
}
|
|
2298
2325
|
|
|
2299
2326
|
exports.System = {
|
|
@@ -2490,7 +2517,8 @@ exports.Strings = {
|
|
|
2490
2517
|
lineMatches,
|
|
2491
2518
|
linesMatchInOrder,
|
|
2492
2519
|
represent,
|
|
2493
|
-
resolveMarkdownLinks
|
|
2520
|
+
resolveMarkdownLinks,
|
|
2521
|
+
buildUrl
|
|
2494
2522
|
}
|
|
2495
2523
|
|
|
2496
2524
|
exports.Assertions = {
|