File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11
22import Tokenizer from './Tokenizer.js'
33import normalize from './Normalize.js'
4+ import parse from './Parse.js'
45
56
67const { log } = console ;
@@ -21,7 +22,7 @@ export default function decode(string){
2122
2223 object ( state ) ;
2324
24- return state . object ;
25+ return parse ( state . object ) ;
2526}
2627
2728
Original file line number Diff line number Diff line change 1+
2+
3+
4+ export default function parse ( object ) {
5+
6+ for ( const key in object ) {
7+
8+ const
9+ value = object [ key ] ,
10+ type = typeof value ;
11+
12+ switch ( type ) {
13+ case 'string' :
14+ object [ key ] = string ( value ) ;
15+ continue ;
16+ case 'array' :
17+ array ( value ) ;
18+ continue ;
19+ case 'object' :
20+ parse ( value ) ;
21+ continue ;
22+ default :
23+ throw `Unparsable Value : ${ type } ` ;
24+ }
25+ }
26+
27+ return object ;
28+ }
29+
30+
31+ const
32+ is_number = / ^ - ? ( ( [ 1 - 9 ] + [ 0 - 9 ] * ) | 0 ) ( \. [ 0 - 9 ] + ) ? ( E ( - | \+ ) [ 0 - 9 ] + ) ? $ / i ,
33+ is_bool = / ^ ( t r u e | f a l s e ) $ / ;
34+
35+ function string ( value ) {
36+
37+ switch ( true ) {
38+ case is_bool . test ( value ) :
39+ return Boolean ( value ) ;
40+ case is_number . test ( value ) :
41+ return parseFloat ( value ) ;
42+ default :
43+ if (
44+ value . startsWith ( '"' ) && value . endsWith ( '"' ) ||
45+ value . startsWith ( "'" ) && value . endsWith ( "'" )
46+ ) return value . slice ( 1 , - 1 ) ;
47+
48+ return value ;
49+ }
50+ }
51+
52+ function array ( value ) {
53+
54+
55+ }
You can’t perform that action at this time.
0 commit comments