@travetto/runtime 5.1.0 → 6.0.0-rc.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/package.json +3 -3
- package/src/util.ts +31 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@travetto/runtime",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "6.0.0-rc.0",
|
|
4
4
|
"description": "Runtime for travetto applications.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"console-manager",
|
|
@@ -25,12 +25,12 @@
|
|
|
25
25
|
"directory": "module/runtime"
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@travetto/manifest": "^
|
|
28
|
+
"@travetto/manifest": "^6.0.0-rc.0",
|
|
29
29
|
"@types/debug": "^4.1.12",
|
|
30
30
|
"debug": "^4.4.0"
|
|
31
31
|
},
|
|
32
32
|
"peerDependencies": {
|
|
33
|
-
"@travetto/transformer": "^
|
|
33
|
+
"@travetto/transformer": "^6.0.0-rc.0"
|
|
34
34
|
},
|
|
35
35
|
"peerDependenciesMeta": {
|
|
36
36
|
"@travetto/transformer": {
|
package/src/util.ts
CHANGED
|
@@ -133,4 +133,35 @@ export class Util {
|
|
|
133
133
|
return () => true;
|
|
134
134
|
}
|
|
135
135
|
}
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* Encode JSON value as base64 encoded string
|
|
139
|
+
*/
|
|
140
|
+
static encodeSafeJSON<T>(value: T | undefined): string | undefined {
|
|
141
|
+
if (value === undefined) {
|
|
142
|
+
return;
|
|
143
|
+
}
|
|
144
|
+
const res = JSON.stringify(value);
|
|
145
|
+
return Buffer.from(res, 'utf8').toString('base64');
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* Decode JSON value from base64 encoded string
|
|
150
|
+
*/
|
|
151
|
+
static decodeSafeJSON<T>(input: string): T;
|
|
152
|
+
static decodeSafeJSON<T>(input?: string | undefined): T | undefined;
|
|
153
|
+
static decodeSafeJSON<T>(input?: string | undefined): T | undefined {
|
|
154
|
+
if (!input) {
|
|
155
|
+
return undefined;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
let decoded = Buffer.from(input, 'base64').toString('utf8');
|
|
159
|
+
|
|
160
|
+
// Read from encoded if it happens
|
|
161
|
+
if (decoded.startsWith('%')) {
|
|
162
|
+
decoded = decodeURIComponent(decoded);
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
return JSON.parse(decoded, undefined);
|
|
166
|
+
}
|
|
136
167
|
}
|