mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-07-17 16:38:18 +00:00
fix: client: modules: config: input: quote
This commit is contained in:
parent
ec66ba78a7
commit
6e5318faa7
2 changed files with 32 additions and 8 deletions
|
|
@ -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;
|
||||
|
|
|
|||
16
client/modules/config/input.spec.js
Normal file
16
client/modules/config/input.spec.js
Normal 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 <world>',
|
||||
};
|
||||
|
||||
t.deepEqual(result, expected);
|
||||
t.end();
|
||||
});
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue