@use 'sass:list';
@use 'sass:math';
@use 'sass:meta';

/// Check if its a number value
/// @param {Void} $value - Value to check
/// @group Type-Checking
/// @author Hugo Giraudel
/// @link https://css-tricks.com/snippets/sass/advanced-type-checking/
/// @since v1.0.0
@function is-number($value) {
	@return meta.type-of($value) == 'number';
}

/// Check if its a time value
/// @param {Void} $value - Value to check
/// @group Type-Checking
/// @author Hugo Giraudel
/// @link https://css-tricks.com/snippets/sass/advanced-type-checking/
/// @since v1.0.0
@function is-time($value) {
	@return is-number($value) and list.index('ms' 's', math.unit($value)) != null;
}

/// Check if its a duration value
/// @param {Void} $value - Value to check
/// @group Type-Checking
/// @author Hugo Giraudel
/// @link https://css-tricks.com/snippets/sass/advanced-type-checking/
/// @since v1.0.0
@function is-duration($value) {
	@return is-time($value);
}

/// Check if its a angle value
/// @param {Void} $value - Value to check
/// @group Type-Checking
/// @author Hugo Giraudel
/// @link https://css-tricks.com/snippets/sass/advanced-type-checking/
/// @since v1.0.0
@function is-angle($value) {
	@return is-number($value) and
		list.index('deg' 'rad' 'grad' 'turn', math.unit($value)) != null;
}

/// Check if its a frequency value
/// @param {Void} $value - Value to check
/// @group Type-Checking
/// @author Hugo Giraudel
/// @link https://css-tricks.com/snippets/sass/advanced-type-checking/
/// @since v1.0.0
@function is-frequency($value) {
	@return is-number($value) and list.index('Hz' 'kHz', math.unit($value)) != null;
}

/// Check if its a integer value
/// @param {Void} $value - Value to check
/// @group Type-Checking
/// @author Hugo Giraudel
/// @link https://css-tricks.com/snippets/sass/advanced-type-checking/
/// @since v1.0.0
@function is-integer($value) {
	@return is-number($value) and math.round($value) == $value;
}

/// Check if its a relative-length value
/// @param {Void} $value - Value to check
/// @group Type-Checking
/// @author Hugo Giraudel
/// @link https://css-tricks.com/snippets/sass/advanced-type-checking/
/// @since v1.0.0
@function is-relative-length($value) {
	@return is-number($value) and
		list.index('em' 'ex' 'ch' 'rem' 'vw' 'vh' 'vmin' 'vmax', math.unit($value)) != null;
}

/// Check if its a absolute-length value
/// @param {Void} $value - Value to check
/// @group Type-Checking
/// @author Hugo Giraudel
/// @link https://css-tricks.com/snippets/sass/advanced-type-checking/
/// @since v1.0.0
@function is-absolute-length($value) {
	@return is-number($value) and
		list.index('cm' 'mm' 'in' 'px' 'pt' 'pc', math.unit($value)) != null;
}

/// Check if its a percentage value
/// @param {Void} $value - Value to check
/// @group Type-Checking
/// @author Hugo Giraudel
/// @link https://css-tricks.com/snippets/sass/advanced-type-checking/
/// @since v1.0.0
@function is-percentage($value) {
	@return is-number($value) and math.unit($value) == '%';
}

/// Check if its a length value
/// @param {Void} $value - Value to check
/// @group Type-Checking
/// @author Hugo Giraudel
/// @link https://css-tricks.com/snippets/sass/advanced-type-checking/
/// @since v1.0.0
@function is-length($value) {
	@return is-relative-length($value) or is-absolute-length($value);
}

/// Check if its a resolution value
/// @param {Void} $value - Value to check
/// @group Type-Checking
/// @author Hugo Giraudel
/// @link https://css-tricks.com/snippets/sass/advanced-type-checking/
/// @since v1.0.0
@function is-resolution($value) {
	@return is-number($value) and
		list.index('dpi' 'dpcm' 'dppx', math.unit($value)) != null;
}

/// Check if its a position value
/// @param {Void} $value - Value to check
/// @group Type-Checking
/// @author Hugo Giraudel
/// @link https://css-tricks.com/snippets/sass/advanced-type-checking/
/// @since v1.0.0
@function is-position($value) {
	@return is-length($value) or is-percentage($value) or
		list.index('top' 'right' 'bottom' 'left' 'center', $value) != null;
}

/// Check if its a color value
/// @param {Void} $value - Value to check
/// @group Type-Checking
/// @author https://github.com/red-freak
/// @since v2.5.0
@function is-color($value) {
	@return meta.type-of($value) == 'color';
}
