You can not select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
		
			
		
			
				
					44 lines
				
				1.2 KiB
			
		
		
			
		
	
	
					44 lines
				
				1.2 KiB
			| 
											3 years ago
										 | "use strict"; | ||
|  | 
 | ||
|  | exports.__esModule = true; | ||
|  | exports["default"] = stripUnit; | ||
|  | var cssRegex = /^([+-]?(?:\d+|\d*\.\d+))([a-z]*|%)$/; | ||
|  | /** | ||
|  |  * Returns a given CSS value minus its unit of measure. | ||
|  |  * | ||
|  |  * @deprecated - stripUnit's unitReturn functionality has been marked for deprecation in polished 4.0. It's functionality has been been moved to getValueAndUnit. | ||
|  |  * | ||
|  |  * @example | ||
|  |  * // Styles as object usage
 | ||
|  |  * const styles = { | ||
|  |  *   '--dimension': stripUnit('100px') | ||
|  |  * } | ||
|  |  * | ||
|  |  * // styled-components usage
 | ||
|  |  * const div = styled.div`
 | ||
|  |  *   --dimension: ${stripUnit('100px')}; | ||
|  |  * `
 | ||
|  |  * | ||
|  |  * // CSS in JS Output
 | ||
|  |  * | ||
|  |  * element { | ||
|  |  *   '--dimension': 100 | ||
|  |  * } | ||
|  |  */ | ||
|  | 
 | ||
|  | function stripUnit(value, unitReturn) { | ||
|  |   if (typeof value !== 'string') return unitReturn ? [value, undefined] : value; | ||
|  |   var matchedValue = value.match(cssRegex); | ||
|  | 
 | ||
|  |   if (unitReturn) { | ||
|  |     // eslint-disable-next-line no-console
 | ||
|  |     console.warn("stripUnit's unitReturn functionality has been marked for deprecation in polished 4.0. It's functionality has been been moved to getValueAndUnit."); | ||
|  |     if (matchedValue) return [parseFloat(value), matchedValue[2]]; | ||
|  |     return [value, undefined]; | ||
|  |   } | ||
|  | 
 | ||
|  |   if (matchedValue) return parseFloat(value); | ||
|  |   return value; | ||
|  | } | ||
|  | 
 | ||
|  | module.exports = exports.default; |