@@ -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,27 @@ 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+ val = exports . toDOMString ( val ) ;
55+
56+ if ( val === '' ) {
57+ return exports . TYPES . EMPTY ;
58+ }
5159 if ( integerRegEx . test ( val ) ) {
5260 return exports . TYPES . INTEGER ;
5361 }
@@ -157,7 +165,7 @@ exports.valueType = function valueType(val) {
157165
158166exports . parseInteger = function parseInteger ( val ) {
159167 var type = exports . valueType ( val ) ;
160- if ( type === exports . TYPES . NULL_OR_EMPTY_STR ) {
168+ if ( type === exports . TYPES . EMPTY ) {
161169 return val ;
162170 }
163171 if ( type !== exports . TYPES . INTEGER ) {
@@ -168,7 +176,7 @@ exports.parseInteger = function parseInteger(val) {
168176
169177exports . parseNumber = function parseNumber ( val ) {
170178 var type = exports . valueType ( val ) ;
171- if ( type === exports . TYPES . NULL_OR_EMPTY_STR ) {
179+ if ( type === exports . TYPES . EMPTY ) {
172180 return val ;
173181 }
174182 if ( type !== exports . TYPES . NUMBER && type !== exports . TYPES . INTEGER ) {
@@ -182,7 +190,7 @@ exports.parseLength = function parseLength(val) {
182190 return '0px' ;
183191 }
184192 var type = exports . valueType ( val ) ;
185- if ( type === exports . TYPES . NULL_OR_EMPTY_STR ) {
193+ if ( type === exports . TYPES . EMPTY ) {
186194 return val ;
187195 }
188196 if ( type !== exports . TYPES . LENGTH ) {
@@ -196,7 +204,7 @@ exports.parsePercent = function parsePercent(val) {
196204 return '0%' ;
197205 }
198206 var type = exports . valueType ( val ) ;
199- if ( type === exports . TYPES . NULL_OR_EMPTY_STR ) {
207+ if ( type === exports . TYPES . EMPTY ) {
200208 return val ;
201209 }
202210 if ( type !== exports . TYPES . PERCENT ) {
@@ -221,7 +229,7 @@ exports.parseMeasurement = function parseMeasurement(val) {
221229
222230exports . parseUrl = function parseUrl ( val ) {
223231 var type = exports . valueType ( val ) ;
224- if ( type === exports . TYPES . NULL_OR_EMPTY_STR ) {
232+ if ( type === exports . TYPES . EMPTY ) {
225233 return val ;
226234 }
227235 var res = urlRegEx . exec ( val ) ;
@@ -260,7 +268,7 @@ exports.parseUrl = function parseUrl(val) {
260268
261269exports . parseString = function parseString ( val ) {
262270 var type = exports . valueType ( val ) ;
263- if ( type === exports . TYPES . NULL_OR_EMPTY_STR ) {
271+ if ( type === exports . TYPES . EMPTY ) {
264272 return val ;
265273 }
266274 if ( type !== exports . TYPES . STRING ) {
@@ -287,7 +295,7 @@ exports.parseString = function parseString(val) {
287295
288296exports . parseColor = function parseColor ( val ) {
289297 var type = exports . valueType ( val ) ;
290- if ( type === exports . TYPES . NULL_OR_EMPTY_STR ) {
298+ if ( type === exports . TYPES . EMPTY ) {
291299 return val ;
292300 }
293301 var red ,
@@ -406,7 +414,7 @@ exports.parseColor = function parseColor(val) {
406414
407415exports . parseAngle = function parseAngle ( val ) {
408416 var type = exports . valueType ( val ) ;
409- if ( type === exports . TYPES . NULL_OR_EMPTY_STR ) {
417+ if ( type === exports . TYPES . EMPTY ) {
410418 return val ;
411419 }
412420 if ( type !== exports . TYPES . ANGLE ) {
@@ -431,7 +439,7 @@ exports.parseAngle = function parseAngle(val) {
431439
432440exports . parseKeyword = function parseKeyword ( val , valid_keywords ) {
433441 var type = exports . valueType ( val ) ;
434- if ( type === exports . TYPES . NULL_OR_EMPTY_STR ) {
442+ if ( type === exports . TYPES . EMPTY ) {
435443 return val ;
436444 }
437445 if ( type !== exports . TYPES . KEYWORD ) {
@@ -520,7 +528,7 @@ var getParts = function(str) {
520528exports . shorthandParser = function parse ( v , shorthand_for ) {
521529 var obj = { } ;
522530 var type = exports . valueType ( v ) ;
523- if ( type === exports . TYPES . NULL_OR_EMPTY_STR ) {
531+ if ( type === exports . TYPES . EMPTY ) {
524532 Object . keys ( shorthand_for ) . forEach ( function ( property ) {
525533 obj [ property ] = '' ;
526534 } ) ;
0 commit comments