File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1- import currify from 'currify ' ;
1+ import { encode } from '#common/entity ' ;
22
3- const isType = currify ( ( type , object , name ) => type === typeof object [ name ] ) ;
4- const isBool = isType ( 'boolean' ) ;
3+ const isBool = ( a ) => typeof a === 'boolean' ;
4+ const isString = ( a ) => typeof a === 'string' ;
5+
6+ const { keys} = Object ;
57
68export function getElementByName ( selector , element ) {
79 const str = `[data-name="js-${ selector } "]` ;
@@ -19,13 +21,19 @@ export const getName = (element) => {
1921
2022export const convert = ( config ) => {
2123 const result = config ;
22- const array = Object . keys ( config ) ;
23-
24- const filtered = array . filter ( isBool ( config ) ) ;
2524
26- for ( const name of filtered ) {
25+ for ( const name of keys ( config ) ) {
2726 const item = config [ name ] ;
28- result [ name ] = setState ( item ) ;
27+
28+ if ( isBool ( item ) ) {
29+ result [ name ] = setState ( item ) ;
30+ continue ;
31+ }
32+
33+ if ( isString ( item ) ) {
34+ result [ name ] = encode ( item ) ;
35+ continue ;
36+ }
2937 }
3038
3139 return result ;
Original file line number Diff line number Diff line change 1+ import { test } from 'supertape' ;
2+ import { convert } from './input.js' ;
3+
4+ test ( 'cloudcmd: client: config: input: convert' , ( t ) => {
5+ const result = convert ( {
6+ name : 'hello <world>' ,
7+ } ) ;
8+
9+ const expected = {
10+ name : 'hello <world>' ,
11+ } ;
12+
13+ t . deepEqual ( result , expected ) ;
14+ t . end ( ) ;
15+ } ) ;
16+
You can’t perform that action at this time.
0 commit comments