fix: client: modules: config: input: quote

This commit is contained in:
coderiaser 2026-03-23 23:47:24 +02:00
parent ec66ba78a7
commit 6e5318faa7
2 changed files with 32 additions and 8 deletions

View file

@ -1,7 +1,9 @@
import currify from 'currify';
import {encode} from '#common/entity';
const isType = currify((type, object, name) => type === typeof object[name]);
const isBool = isType('boolean');
const isBool = (a) => typeof a === 'boolean';
const isString = (a) => typeof a === 'string';
const {keys} = Object;
export function getElementByName(selector, element) {
const str = `[data-name="js-${selector}"]`;
@ -19,13 +21,19 @@ export const getName = (element) => {
export const convert = (config) => {
const result = config;
const array = Object.keys(config);
const filtered = array.filter(isBool(config));
for (const name of filtered) {
for (const name of keys(config)) {
const item = config[name];
result[name] = setState(item);
if (isBool(item)) {
result[name] = setState(item);
continue;
}
if (isString(item)) {
result[name] = encode(item);
continue;
}
}
return result;

View file

@ -0,0 +1,16 @@
import {test} from 'supertape';
import {convert} from './input.js';
test('cloudcmd: client: config: input: convert', (t) => {
const result = convert({
name: 'hello <world>',
});
const expected = {
name: 'hello &lt;world&gt;',
};
t.deepEqual(result, expected);
t.end();
});