@@ -17,7 +17,7 @@ exports.TYPES = {
1717 STRING : 7 ,
1818 ANGLE : 8 ,
1919 KEYWORD : 9 ,
20- NULL_OR_EMPTY_STR : 10 ,
20+ EMPTY : 10 ,
2121 CALC : 11 ,
2222} ;
2323
@@ -35,19 +35,25 @@ var calcRegEx = /^calc\(([^)]*)\)$/;
3535var colorRegEx4 = / ^ h s l a ? \( \s * ( - ? \d + | - ? \d * .\d + ) \s * , \s * ( - ? \d + | - ? \d * .\d + ) % \s * , \s * ( - ? \d + | - ? \d * .\d + ) % \s * ( , \s * ( - ? \d + | - ? \d * .\d + ) \s * ) ? \) / ;
3636var angleRegEx = / ^ ( [ - + ] ? [ 0 - 9 ] * \. ? [ 0 - 9 ] + ) ( d e g | g r a d | r a d ) $ / ;
3737
38- // This will return one of the above types based on the passed in string
39- exports . valueType = function valueType ( val ) {
40- if ( val === '' || val === null ) {
41- return exports . TYPES . NULL_OR_EMPTY_STR ;
38+ // https://heycam.github.io/webidl/#es-DOMString
39+ exports . toDOMString = function toDOMString ( val ) {
40+ if ( val === null ) {
41+ return '' ;
4242 }
43- if ( typeof val === 'number ' ) {
44- val = val . toString ( ) ;
43+ if ( typeof val === 'string ' ) {
44+ return val ;
4545 }
46-
47- if ( typeof val !== 'string' ) {
48- return undefined ;
46+ if ( typeof val === 'symbol' ) {
47+ throw Error ( 'Cannot convert symbol to string' ) ;
4948 }
49+ return String ( val ) ;
50+ } ;
5051
52+ // This will return one of the above types based on the passed in string
53+ exports . valueType = function valueType ( val ) {
54+ if ( val === '' ) {
55+ return exports . TYPES . EMPTY ;
56+ }
5157 if ( integerRegEx . test ( val ) ) {
5258 return exports . TYPES . INTEGER ;
5359 }
@@ -157,7 +163,7 @@ exports.valueType = function valueType(val) {
157163
158164exports . parseInteger = function parseInteger ( val ) {
159165 var type = exports . valueType ( val ) ;
160- if ( type === exports . TYPES . NULL_OR_EMPTY_STR ) {
166+ if ( type === exports . TYPES . EMPTY ) {
161167 return val ;
162168 }
163169 if ( type !== exports . TYPES . INTEGER ) {
@@ -168,7 +174,7 @@ exports.parseInteger = function parseInteger(val) {
168174
169175exports . parseNumber = function parseNumber ( val ) {
170176 var type = exports . valueType ( val ) ;
171- if ( type === exports . TYPES . NULL_OR_EMPTY_STR ) {
177+ if ( type === exports . TYPES . EMPTY ) {
172178 return val ;
173179 }
174180 if ( type !== exports . TYPES . NUMBER && type !== exports . TYPES . INTEGER ) {
@@ -182,7 +188,7 @@ exports.parseLength = function parseLength(val) {
182188 return '0px' ;
183189 }
184190 var type = exports . valueType ( val ) ;
185- if ( type === exports . TYPES . NULL_OR_EMPTY_STR ) {
191+ if ( type === exports . TYPES . EMPTY ) {
186192 return val ;
187193 }
188194 if ( type !== exports . TYPES . LENGTH ) {
@@ -196,7 +202,7 @@ exports.parsePercent = function parsePercent(val) {
196202 return '0%' ;
197203 }
198204 var type = exports . valueType ( val ) ;
199- if ( type === exports . TYPES . NULL_OR_EMPTY_STR ) {
205+ if ( type === exports . TYPES . EMPTY ) {
200206 return val ;
201207 }
202208 if ( type !== exports . TYPES . PERCENT ) {
@@ -221,7 +227,7 @@ exports.parseMeasurement = function parseMeasurement(val) {
221227
222228exports . parseUrl = function parseUrl ( val ) {
223229 var type = exports . valueType ( val ) ;
224- if ( type === exports . TYPES . NULL_OR_EMPTY_STR ) {
230+ if ( type === exports . TYPES . EMPTY ) {
225231 return val ;
226232 }
227233 var res = urlRegEx . exec ( val ) ;
@@ -260,7 +266,7 @@ exports.parseUrl = function parseUrl(val) {
260266
261267exports . parseString = function parseString ( val ) {
262268 var type = exports . valueType ( val ) ;
263- if ( type === exports . TYPES . NULL_OR_EMPTY_STR ) {
269+ if ( type === exports . TYPES . EMPTY ) {
264270 return val ;
265271 }
266272 if ( type !== exports . TYPES . STRING ) {
@@ -287,7 +293,7 @@ exports.parseString = function parseString(val) {
287293
288294exports . parseColor = function parseColor ( val ) {
289295 var type = exports . valueType ( val ) ;
290- if ( type === exports . TYPES . NULL_OR_EMPTY_STR ) {
296+ if ( type === exports . TYPES . EMPTY ) {
291297 return val ;
292298 }
293299 var red ,
@@ -406,7 +412,7 @@ exports.parseColor = function parseColor(val) {
406412
407413exports . parseAngle = function parseAngle ( val ) {
408414 var type = exports . valueType ( val ) ;
409- if ( type === exports . TYPES . NULL_OR_EMPTY_STR ) {
415+ if ( type === exports . TYPES . EMPTY ) {
410416 return val ;
411417 }
412418 if ( type !== exports . TYPES . ANGLE ) {
@@ -431,7 +437,7 @@ exports.parseAngle = function parseAngle(val) {
431437
432438exports . parseKeyword = function parseKeyword ( val , valid_keywords ) {
433439 var type = exports . valueType ( val ) ;
434- if ( type === exports . TYPES . NULL_OR_EMPTY_STR ) {
440+ if ( type === exports . TYPES . EMPTY ) {
435441 return val ;
436442 }
437443 if ( type !== exports . TYPES . KEYWORD ) {
@@ -520,7 +526,7 @@ var getParts = function(str) {
520526exports . shorthandParser = function parse ( v , shorthand_for ) {
521527 var obj = { } ;
522528 var type = exports . valueType ( v ) ;
523- if ( type === exports . TYPES . NULL_OR_EMPTY_STR ) {
529+ if ( type === exports . TYPES . EMPTY ) {
524530 Object . keys ( shorthand_for ) . forEach ( function ( property ) {
525531 obj [ property ] = '' ;
526532 } ) ;
0 commit comments