cafe-utility 10.13.0 → 10.14.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 +7 -1
- package/index.js +29 -3
- package/package.json +1 -1
package/index.d.ts
CHANGED
|
@@ -33,7 +33,7 @@ declare function ensureDeep(object: CafeObject, path: string, value: unknown): u
|
|
|
33
33
|
declare function deleteDeep(object: CafeObject, path: string): void;
|
|
34
34
|
declare function replaceDeep(object: CafeObject, path: string, value: unknown): unknown;
|
|
35
35
|
declare function getFirstDeep(object: CafeObject, paths: string[], fallbackToAnyKey?: boolean): unknown;
|
|
36
|
-
declare function forever(callable: (() => Promise<void>) | (() => void), millis: number): Promise<never>;
|
|
36
|
+
declare function forever(callable: (() => Promise<void>) | (() => void), millis: number, log?: (message: string, metadata: object) => void): Promise<never>;
|
|
37
37
|
declare function asMegabytes(number: number): number;
|
|
38
38
|
declare function convertBytes(bytes: number): string;
|
|
39
39
|
declare function hexToRgb(hex: string): [number, number, number];
|
|
@@ -157,6 +157,11 @@ interface BlockExtractionOptions {
|
|
|
157
157
|
}
|
|
158
158
|
declare function extractBlock(string: string, options: BlockExtractionOptions): string | null;
|
|
159
159
|
declare function extractAllBlocks(string: string, options: BlockExtractionOptions): string[];
|
|
160
|
+
declare type StringSegment = {
|
|
161
|
+
symbol: string | null;
|
|
162
|
+
string: string;
|
|
163
|
+
};
|
|
164
|
+
declare function segmentizeString(string: string, symbol: string): StringSegment[];
|
|
160
165
|
declare function parseHtmlAttributes(string: string): Record<string, string>;
|
|
161
166
|
declare function readNextWord(string: string, index: number, allowedCharacters?: string[]): string;
|
|
162
167
|
declare function resolveVariables(string: string, variables: Record<string, string>, prefix?: string, separator?: string): string;
|
|
@@ -604,6 +609,7 @@ export declare const Strings: {
|
|
|
604
609
|
describeMarkdown: typeof describeMarkdown;
|
|
605
610
|
isBalanced: typeof isBalanced;
|
|
606
611
|
textToFormat: typeof textToFormat;
|
|
612
|
+
segmentize: typeof segmentizeString;
|
|
607
613
|
};
|
|
608
614
|
export declare const Assertions: {
|
|
609
615
|
asEqual: typeof asEqual;
|
package/index.js
CHANGED
|
@@ -282,12 +282,14 @@ function getFirstDeep(object, paths, fallbackToAnyKey) {
|
|
|
282
282
|
return null
|
|
283
283
|
}
|
|
284
284
|
|
|
285
|
-
async function forever(callable, millis) {
|
|
285
|
+
async function forever(callable, millis, log) {
|
|
286
286
|
while (true) {
|
|
287
287
|
try {
|
|
288
288
|
await callable()
|
|
289
289
|
} catch (error) {
|
|
290
|
-
|
|
290
|
+
if (log) {
|
|
291
|
+
log('Error in forever', error)
|
|
292
|
+
}
|
|
291
293
|
}
|
|
292
294
|
await sleepMillis(millis)
|
|
293
295
|
}
|
|
@@ -1104,6 +1106,29 @@ function extractAllBlocks(string, options) {
|
|
|
1104
1106
|
}
|
|
1105
1107
|
}
|
|
1106
1108
|
|
|
1109
|
+
function segmentizeString(string, symbol) {
|
|
1110
|
+
const segments = []
|
|
1111
|
+
let index = 0
|
|
1112
|
+
while (index < string.length) {
|
|
1113
|
+
const start = string.indexOf(symbol, index)
|
|
1114
|
+
if (start === -1) {
|
|
1115
|
+
segments.push({ string: string.slice(index), symbol: null })
|
|
1116
|
+
break
|
|
1117
|
+
}
|
|
1118
|
+
const end = string.indexOf(symbol, start + symbol.length)
|
|
1119
|
+
if (start > index && end !== -1) {
|
|
1120
|
+
segments.push({ string: string.slice(index, start), symbol: null })
|
|
1121
|
+
}
|
|
1122
|
+
if (end === -1) {
|
|
1123
|
+
segments.push({ string: string.slice(index), symbol: null })
|
|
1124
|
+
break
|
|
1125
|
+
}
|
|
1126
|
+
segments.push({ string: string.slice(start + symbol.length, end), symbol })
|
|
1127
|
+
index = end + symbol.length
|
|
1128
|
+
}
|
|
1129
|
+
return segments
|
|
1130
|
+
}
|
|
1131
|
+
|
|
1107
1132
|
function parseHtmlAttributes(string) {
|
|
1108
1133
|
const attributes = {}
|
|
1109
1134
|
const matches = string.match(/([a-z\-]+)="([^"]+)"/g)
|
|
@@ -2828,7 +2853,8 @@ exports.Strings = {
|
|
|
2828
2853
|
replaceBetweenStrings,
|
|
2829
2854
|
describeMarkdown,
|
|
2830
2855
|
isBalanced,
|
|
2831
|
-
textToFormat
|
|
2856
|
+
textToFormat,
|
|
2857
|
+
segmentize: segmentizeString
|
|
2832
2858
|
}
|
|
2833
2859
|
|
|
2834
2860
|
exports.Assertions = {
|