cafe-utility 6.6.0 → 6.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 +6 -0
- package/index.js +28 -0
- package/package.json +1 -1
package/index.d.ts
CHANGED
|
@@ -128,6 +128,7 @@ declare function decapitalize(string: string): string;
|
|
|
128
128
|
declare function isLetter(character: string): boolean;
|
|
129
129
|
declare function isDigit(character: string): boolean;
|
|
130
130
|
declare function isLetterOrDigit(character: string): boolean;
|
|
131
|
+
declare function isValidObjectPathCharacter(character: string): boolean;
|
|
131
132
|
declare function insertString(string: string, index: number, length: number, before: string, after: string): string;
|
|
132
133
|
declare function linesMatchOrdered(lines: string[], expectedLines: string[]): boolean;
|
|
133
134
|
declare function csvEscape(string: string): string;
|
|
@@ -143,6 +144,8 @@ interface BlockExtractionOptions {
|
|
|
143
144
|
declare function extractBlock(string: string, options: BlockExtractionOptions): string | null;
|
|
144
145
|
declare function extractAllBlocks(string: string, options: BlockExtractionOptions): string[];
|
|
145
146
|
declare function parseHtmlAttributes(string: string): Record<string, string>;
|
|
147
|
+
declare function resolveHtmlAttribute(string: string, key: string, value: string, prefix?: string): string;
|
|
148
|
+
declare function replaceUnresolvedHtmlAttributesWithDefaults(string: string, prefix?: string, separator?: string): string;
|
|
146
149
|
declare function parseCsv(string: string, delimiter?: string, quote?: string): string[];
|
|
147
150
|
declare function humanizeProgress(state: Progress): string;
|
|
148
151
|
declare function waitFor(predicate: () => Promise<boolean>, waitLength: number, maxWaits: number): Promise<boolean>;
|
|
@@ -489,9 +492,12 @@ export declare const Strings: {
|
|
|
489
492
|
extractAllBlocks: typeof extractAllBlocks;
|
|
490
493
|
indexOfEarliest: typeof indexOfEarliest;
|
|
491
494
|
parseHtmlAttributes: typeof parseHtmlAttributes;
|
|
495
|
+
resolveHtmlAttribute: typeof resolveHtmlAttribute;
|
|
496
|
+
replaceUnresolvedHtmlAttributesWithDefaults: typeof replaceUnresolvedHtmlAttributesWithDefaults;
|
|
492
497
|
isLetter: typeof isLetter;
|
|
493
498
|
isDigit: typeof isDigit;
|
|
494
499
|
isLetterOrDigit: typeof isLetterOrDigit;
|
|
500
|
+
isValidObjectPathCharacter: typeof isValidObjectPathCharacter;
|
|
495
501
|
insert: typeof insertString;
|
|
496
502
|
linesMatchOrdered: typeof linesMatchOrdered;
|
|
497
503
|
represent: typeof represent;
|
package/index.js
CHANGED
|
@@ -872,6 +872,12 @@ function isLetterOrDigit(character) {
|
|
|
872
872
|
return isLetter(character) || isDigit(character)
|
|
873
873
|
}
|
|
874
874
|
|
|
875
|
+
function isValidObjectPathCharacter(character) {
|
|
876
|
+
return (
|
|
877
|
+
isLetterOrDigit(character) || character === '.' || character === '[' || character === ']' || character === '_'
|
|
878
|
+
)
|
|
879
|
+
}
|
|
880
|
+
|
|
875
881
|
function insertString(string, index, length, before, after) {
|
|
876
882
|
return string.slice(0, index) + before + string.slice(index, index + length) + after + string.slice(index + length)
|
|
877
883
|
}
|
|
@@ -970,6 +976,25 @@ function parseHtmlAttributes(string) {
|
|
|
970
976
|
return attributes
|
|
971
977
|
}
|
|
972
978
|
|
|
979
|
+
function resolveHtmlAttribute(string, key, value, prefix = '$') {
|
|
980
|
+
const blocks = extractAllBlocks(string, { opening: `="${prefix}${key}`, closing: '"' })
|
|
981
|
+
const set = new Set(blocks)
|
|
982
|
+
for (const block of set) {
|
|
983
|
+
string = string.replace(block, `="${value}"`)
|
|
984
|
+
}
|
|
985
|
+
return string
|
|
986
|
+
}
|
|
987
|
+
|
|
988
|
+
function replaceUnresolvedHtmlAttributesWithDefaults(string, prefix = '$', separator = ':') {
|
|
989
|
+
const blocks = extractAllBlocks(string, { opening: `="${prefix}`, closing: '"' }).filter(x => x.includes(separator))
|
|
990
|
+
for (const block of blocks) {
|
|
991
|
+
let [_, value] = block.split(separator)
|
|
992
|
+
value = value.slice(0, value.length - 1)
|
|
993
|
+
string = string.replace(block, `="${value}"`)
|
|
994
|
+
}
|
|
995
|
+
return string
|
|
996
|
+
}
|
|
997
|
+
|
|
973
998
|
function parseCsv(string, delimiter = ',', quote = '"') {
|
|
974
999
|
const items = []
|
|
975
1000
|
let buffer = ''
|
|
@@ -2190,9 +2215,12 @@ exports.Strings = {
|
|
|
2190
2215
|
extractAllBlocks,
|
|
2191
2216
|
indexOfEarliest,
|
|
2192
2217
|
parseHtmlAttributes,
|
|
2218
|
+
resolveHtmlAttribute,
|
|
2219
|
+
replaceUnresolvedHtmlAttributesWithDefaults,
|
|
2193
2220
|
isLetter,
|
|
2194
2221
|
isDigit,
|
|
2195
2222
|
isLetterOrDigit,
|
|
2223
|
+
isValidObjectPathCharacter,
|
|
2196
2224
|
insert: insertString,
|
|
2197
2225
|
linesMatchOrdered,
|
|
2198
2226
|
represent
|