chore(cloudwatch): vendor jsurl stringify function

This commit is contained in:
Jack Westbrook
2025-03-03 09:52:51 +01:00
parent d830e2085d
commit 846afe2e68
3 changed files with 59 additions and 11 deletions
-1
View File
@@ -325,7 +325,6 @@
"js-yaml": "^4.1.0",
"json-markup": "^1.1.0",
"json-source-map": "0.6.1",
"jsurl2": "^2.2.0",
"kbar": "0.1.0-beta.45",
"leven": "^4.0.0",
"lodash": "4.17.21",
@@ -1,5 +1,3 @@
import { stringify } from 'jsurl2';
export interface AwsUrl {
end: string;
start: string;
@@ -31,3 +29,62 @@ export function encodeUrl(obj: AwsUrl, region: string): string {
region
)}/cloudwatch/home?region=${region}#logs-insights:queryDetail=${stringify(obj)}`;
}
// Lifted from https://github.com/Sage/jsurl
function stringify<T>(v: T): string {
function encode(s: string): string {
return !/[^\w-.]/.test(s)
? s
: s.replace(/[^\w-.]/g, (ch: string): string => {
if (ch === '$') {
return '!';
}
const charCode = ch.charCodeAt(0);
// Thanks to Douglas Crockford for the negative slice trick
return charCode < 0x100
? '*' + ('00' + charCode.toString(16)).slice(-2)
: '**' + ('0000' + charCode.toString(16)).slice(-4);
});
}
let tmpAry;
switch (typeof v) {
case 'number':
return isFinite(v) ? '~' + v : '~null';
case 'boolean':
return '~' + v;
case 'string':
return "~'" + encode(v);
case 'object':
if (!v) {
return '~null';
}
tmpAry = [];
if (Array.isArray(v)) {
for (let i = 0; i < v.length; i++) {
tmpAry[i] = stringify(v[i]) || '~null';
}
return '~(' + (tmpAry.join('') || '~') + ')';
} else {
for (const key in v) {
if (v.hasOwnProperty(key)) {
const val = stringify(v[key]);
// skip undefined and functions
if (val) {
tmpAry.push(encode(key) + val);
}
}
}
return '~(' + tmpAry.join('~') + ')';
}
default:
// function, undefined
return '';
}
}
-8
View File
@@ -18362,7 +18362,6 @@ __metadata:
jsdom-testing-mocks: "npm:^1.13.1"
json-markup: "npm:^1.1.0"
json-source-map: "npm:0.6.1"
jsurl2: "npm:^2.2.0"
kbar: "npm:0.1.0-beta.45"
lerna: "npm:8.1.8"
leven: "npm:^4.0.0"
@@ -21136,13 +21135,6 @@ __metadata:
languageName: node
linkType: hard
"jsurl2@npm:^2.2.0":
version: 2.2.0
resolution: "jsurl2@npm:2.2.0"
checksum: 10/eb54376c7af6881b2110eb5b71314f17f7165fb450d82b67cc5f28f66a8999439b140b7533354ed9d522236e08d2bd94730186464c1fc9b502e8977027fbc43c
languageName: node
linkType: hard
"jsx-ast-utils@npm:^2.4.1 || ^3.0.0, jsx-ast-utils@npm:^3.3.5":
version: 3.3.5
resolution: "jsx-ast-utils@npm:3.3.5"