cafe-utility 10.19.0 → 10.21.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 +27 -1
- package/package.json +1 -1
package/index.d.ts
CHANGED
|
@@ -169,6 +169,8 @@ declare type StringSegment = {
|
|
|
169
169
|
declare function segmentizeString(string: string, symbol: string): StringSegment[];
|
|
170
170
|
declare function base64ToUint8Array(base64: string): Uint8Array;
|
|
171
171
|
declare function hexToUint8Array(hex: string): Uint8Array;
|
|
172
|
+
declare function uint8ArrayToHex(array: Uint8Array): string;
|
|
173
|
+
declare function route(pattern: string, actual: string): Record<string, unknown> | null;
|
|
172
174
|
declare function parseHtmlAttributes(string: string): Record<string, string>;
|
|
173
175
|
declare function readNextWord(string: string, index: number, allowedCharacters?: string[]): string;
|
|
174
176
|
declare function resolveVariables(string: string, variables: Record<string, string>, prefix?: string, separator?: string): string;
|
|
@@ -620,7 +622,9 @@ export declare const Strings: {
|
|
|
620
622
|
textToFormat: typeof textToFormat;
|
|
621
623
|
segmentize: typeof segmentizeString;
|
|
622
624
|
hexToUint8Array: typeof hexToUint8Array;
|
|
625
|
+
uint8ArrayToHex: typeof uint8ArrayToHex;
|
|
623
626
|
base64ToUint8Array: typeof base64ToUint8Array;
|
|
627
|
+
route: typeof route;
|
|
624
628
|
};
|
|
625
629
|
export declare const Assertions: {
|
|
626
630
|
asEqual: typeof asEqual;
|
package/index.js
CHANGED
|
@@ -1193,6 +1193,30 @@ function hexToUint8Array(hex) {
|
|
|
1193
1193
|
return result
|
|
1194
1194
|
}
|
|
1195
1195
|
|
|
1196
|
+
function uint8ArrayToHex(array) {
|
|
1197
|
+
return Array.from(array)
|
|
1198
|
+
.map(byte => byte.toString(16).padStart(2, '0'))
|
|
1199
|
+
.join('')
|
|
1200
|
+
}
|
|
1201
|
+
|
|
1202
|
+
function route(pattern, actual) {
|
|
1203
|
+
const patternPieces = pattern.split('/').filter(x => x)
|
|
1204
|
+
const actualPieces = actual.split('/').filter(x => x)
|
|
1205
|
+
if (patternPieces.length !== actualPieces.length) {
|
|
1206
|
+
return null
|
|
1207
|
+
}
|
|
1208
|
+
const parameters = {}
|
|
1209
|
+
for (let i = 0; i < patternPieces.length; i++) {
|
|
1210
|
+
const patternPiece = patternPieces[i]
|
|
1211
|
+
if (patternPiece.startsWith(':')) {
|
|
1212
|
+
parameters[patternPiece.slice(1)] = actualPieces[i]
|
|
1213
|
+
} else if (patternPiece !== actualPieces[i]) {
|
|
1214
|
+
return null
|
|
1215
|
+
}
|
|
1216
|
+
}
|
|
1217
|
+
return parameters
|
|
1218
|
+
}
|
|
1219
|
+
|
|
1196
1220
|
function parseHtmlAttributes(string) {
|
|
1197
1221
|
const attributes = {}
|
|
1198
1222
|
const matches = string.match(/([a-z\-]+)="([^"]+)"/g)
|
|
@@ -2924,7 +2948,9 @@ exports.Strings = {
|
|
|
2924
2948
|
textToFormat,
|
|
2925
2949
|
segmentize: segmentizeString,
|
|
2926
2950
|
hexToUint8Array,
|
|
2927
|
-
|
|
2951
|
+
uint8ArrayToHex,
|
|
2952
|
+
base64ToUint8Array,
|
|
2953
|
+
route
|
|
2928
2954
|
}
|
|
2929
2955
|
|
|
2930
2956
|
exports.Assertions = {
|