@@ -7,9 +7,15 @@ define([
7
7
'jquery' ,
8
8
'underscore'
9
9
] , function ( $ , _ ) {
10
+ 'use strict' ;
11
+
10
12
var ConditionsDataNormalizer = new Class . create ( ) ;
11
13
12
14
ConditionsDataNormalizer . prototype = {
15
+
16
+ /**
17
+ * Initializes component.
18
+ */
13
19
initialize : function ( ) {
14
20
this . patterns = {
15
21
validate : / ^ [ a - z 0 - 9 _ - ] [ a - z 0 - 9 _ - ] * (?: \[ (?: \d * | [ a - z 0 - 9 _ - ] + ) \] ) * $ / i,
@@ -46,13 +52,13 @@ define([
46
52
*
47
53
*/
48
54
normalize : function normalize ( value ) {
49
- var _this = this ;
55
+ var el , _this = this ;
50
56
51
57
this . pushes = { } ;
52
58
this . data = { } ;
53
59
54
60
_ . each ( value , function ( e , i ) {
55
- var el = { } ;
61
+ el = { } ;
56
62
el [ i ] = e ;
57
63
58
64
_this . _addPair ( {
@@ -64,20 +70,33 @@ define([
64
70
return this . data ;
65
71
} ,
66
72
73
+ /**
74
+ * @param {Object } base
75
+ * @param {String } key
76
+ * @param {String } value
77
+ * @return {Object }
78
+ * @private
79
+ */
67
80
_build : function build ( base , key , value ) {
68
81
base [ key ] = value ;
69
82
70
83
return base ;
71
84
} ,
72
85
86
+ /**
87
+ * @param {Object } root
88
+ * @param {String } value
89
+ * @return {* }
90
+ * @private
91
+ */
73
92
_makeObject : function makeObject ( root , value ) {
74
93
var keys = root . match ( this . patterns . key ) ,
75
- k ; // nest, nest, ..., nest
94
+ k , idx ; // nest, nest, ..., nest
76
95
77
96
while ( ( k = keys . pop ( ) ) !== undefined ) {
78
97
// foo[]
79
98
if ( this . patterns . push . test ( k ) ) {
80
- var idx = this . _incrementPush ( root . replace ( / \[ \] $ / , '' ) ) ;
99
+ idx = this . _incrementPush ( root . replace ( / \[ \] $ / , '' ) ) ;
81
100
value = this . _build ( [ ] , idx , value ) ;
82
101
} // foo[n]
83
102
else if ( this . patterns . fixed . test ( k ) ) {
@@ -91,6 +110,11 @@ define([
91
110
return value ;
92
111
} ,
93
112
113
+ /**
114
+ * @param {String } key
115
+ * @return {Number }
116
+ * @private
117
+ */
94
118
_incrementPush : function incrementPush ( key ) {
95
119
if ( this . pushes [ key ] === undefined ) {
96
120
this . pushes [ key ] = 0 ;
@@ -99,10 +123,20 @@ define([
99
123
return this . pushes [ key ] ++ ;
100
124
} ,
101
125
126
+ /**
127
+ * @param {Object } pair
128
+ * @return {Object }
129
+ * @private
130
+ */
102
131
_addPair : function addPair ( pair ) {
103
- if ( ! this . patterns . validate . test ( pair . name ) ) return this ;
104
132
var obj = this . _makeObject ( pair . name , pair . value ) ;
133
+
134
+ if ( ! this . patterns . validate . test ( pair . name ) ) {
135
+ return this ;
136
+ }
137
+
105
138
this . data = $ . extend ( true , this . data , obj ) ;
139
+
106
140
return this ;
107
141
}
108
142
} ;
0 commit comments