cafe-utility 10.19.0 → 10.20.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 +2 -0
- package/index.js +20 -1
- package/package.json +1 -1
package/index.d.ts
CHANGED
|
@@ -169,6 +169,7 @@ 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 route(pattern: string, actual: string): Record<string, unknown> | null;
|
|
172
173
|
declare function parseHtmlAttributes(string: string): Record<string, string>;
|
|
173
174
|
declare function readNextWord(string: string, index: number, allowedCharacters?: string[]): string;
|
|
174
175
|
declare function resolveVariables(string: string, variables: Record<string, string>, prefix?: string, separator?: string): string;
|
|
@@ -621,6 +622,7 @@ export declare const Strings: {
|
|
|
621
622
|
segmentize: typeof segmentizeString;
|
|
622
623
|
hexToUint8Array: typeof hexToUint8Array;
|
|
623
624
|
base64ToUint8Array: typeof base64ToUint8Array;
|
|
625
|
+
route: typeof route;
|
|
624
626
|
};
|
|
625
627
|
export declare const Assertions: {
|
|
626
628
|
asEqual: typeof asEqual;
|
package/index.js
CHANGED
|
@@ -1193,6 +1193,24 @@ function hexToUint8Array(hex) {
|
|
|
1193
1193
|
return result
|
|
1194
1194
|
}
|
|
1195
1195
|
|
|
1196
|
+
function route(pattern, actual) {
|
|
1197
|
+
const patternPieces = pattern.split('/').filter(x => x)
|
|
1198
|
+
const actualPieces = actual.split('/').filter(x => x)
|
|
1199
|
+
if (patternPieces.length !== actualPieces.length) {
|
|
1200
|
+
return null
|
|
1201
|
+
}
|
|
1202
|
+
const parameters = {}
|
|
1203
|
+
for (let i = 0; i < patternPieces.length; i++) {
|
|
1204
|
+
const patternPiece = patternPieces[i]
|
|
1205
|
+
if (patternPiece.startsWith(':')) {
|
|
1206
|
+
parameters[patternPiece.slice(1)] = actualPieces[i]
|
|
1207
|
+
} else if (patternPiece !== actualPieces[i]) {
|
|
1208
|
+
return null
|
|
1209
|
+
}
|
|
1210
|
+
}
|
|
1211
|
+
return parameters
|
|
1212
|
+
}
|
|
1213
|
+
|
|
1196
1214
|
function parseHtmlAttributes(string) {
|
|
1197
1215
|
const attributes = {}
|
|
1198
1216
|
const matches = string.match(/([a-z\-]+)="([^"]+)"/g)
|
|
@@ -2924,7 +2942,8 @@ exports.Strings = {
|
|
|
2924
2942
|
textToFormat,
|
|
2925
2943
|
segmentize: segmentizeString,
|
|
2926
2944
|
hexToUint8Array,
|
|
2927
|
-
base64ToUint8Array
|
|
2945
|
+
base64ToUint8Array,
|
|
2946
|
+
route
|
|
2928
2947
|
}
|
|
2929
2948
|
|
|
2930
2949
|
exports.Assertions = {
|