Utils
Basic utility functions/mixins used throughout system
Variables
Module Settings
$config: (
"debug-maps": true,
"file-header-comments": true,
"responsive-change": 0.5vw,
"pixel-em-base" : 16px,
);
File Information
- File: _utils.scss
- Group: utils
- Type: variable
- Lines (comments): 12-17
- Lines (code): 19-24
Map Properties
| Name |
Type |
Default |
Description |
| debug-maps |
Boolean |
true |
Enable or disable debug map output |
| file-header-comments |
Boolean |
true |
Enable or disable module/file header comments |
| responsive-change |
Number |
0.5vw |
Default responsive amount to modify items using responsive-property mixin |
| pixel-em-base |
Number |
16px |
Default base pixel font size for pixel-to-em |
Mixins
Change modules $config
File Information
- File: _utils.scss
- Group: utils
- Type: mixin
- Lines (comments): 26-29
- Lines (code): 31-33
Examples
General example
@include ulu.utils-set(( "property" : value ));
Parameters
| Name |
Type |
Description |
| $changes |
Map |
Map of changes |
Require
Ensure a value is present in the list, throw an error if not found
File Information
- File: _utils.scss
- Group: utils
- Type: mixin
- Lines (comments): 71-75
- Lines (code): 77-87
Parameters
| Name |
Type |
Description |
| $list |
List |
The map to get the value from |
| $value |
String |
The value to search for in the list |
| $context |
String |
The context of using this function for debugging help |
| $warn |
String |
Display warning instead of throwing error |
Require that the list only is only made up of allowed items
File Information
- File: _utils.scss
- Group: utils
- Type: mixin
- Lines (comments): 89-93
- Lines (code): 95-99
Parameters
| Name |
Type |
Description |
| $allowed |
List |
The list of allowed items |
| $list |
String |
The list to test allowed against |
| $context |
String |
The context of using this function for debugging help |
| $warn |
String |
Display warning instead of throwing error |
Require
Returns true if we should include something (used for output checking)
File Information
- File: _utils.scss
- Group: utils
- Type: mixin
- Lines (comments): 125-127
- Lines (code): 129-137
Parameters
| Name |
Type |
Description |
| $context |
List |
The root area of the framework this file comes from |
| $name |
List |
The name of the specific area/file (optional) |
Provides user with a fallback for a calc that's just an enhancement
File Information
- File: _utils.scss
- Group: utils
- Type: mixin
- Lines (comments): 695-698
- Lines (code): 700-707
Parameters
| Name |
Type |
Description |
| $property |
String |
The CSS property to set |
| $value |
* |
The value to set on the property |
| $responsive-change |
Css |
The amount to change (vw or vh units) (combined with unit past) |
Functions
Get a config option
File Information
- File: _utils.scss
- Group: utils
- Type: function
- Lines (comments): 35-41
- Lines (code): 43-45
Examples
Example usage
.test-em-to-pixel {
width: ulu.utils-get("pixel-em-base");
}
.test-em-to-pixel {
width: 16px;
}
Parameters
| Name |
Type |
Description |
| $name |
Map |
Name of property |
Returns
Require
Get a required value from a map, throw an error if not found
- Remember that that maps cannot intentionally use null (use false instead, if trying to avoid output if not configured)
File Information
- File: _utils.scss
- Group: utils
- Type: function
- Lines (comments): 47-57
- Lines (code): 59-69
Examples
Example usage
.test-require-map {
$test-map: ("test-font-size": 12px);
font-size: ulu.utils-require-map-get($test-map, "test-font-size");
}
.test-require-map {
font-size: 12px;
}
Parameters
| Name |
Type |
Description |
| $map |
Map |
The map to get the value from |
| $key |
String |
The key in the map to get value from |
| $context |
String |
The context of using this function for debugging help |
Returns
| Type |
Description |
| * |
The value from the map |
Throw
Require
Returns true if we should include something (map of booleans)
File Information
- File: _utils.scss
- Group: utils
- Type: function
- Lines (comments): 101-118
- Lines (code): 120-123
Examples
Example usage
$include-styles : (
"h2" : true,
"h3" : false
);
@if (ulu.utils-included("h2", $include-styles)) {
h2 {
font-size: 24px;
}
}
@if (ulu.utils-included("h3", $include-styles)) {
h3 {
font-size: 18px;
}
}
h2 {
font-size: 24px;
}
Parameters
| Name |
Type |
Description |
| $name |
String |
Name of item to see if it's included |
| $includes |
Map |
Map of includes |
Require
Selects a value based on a condition (Ternary Function)
- To replace SASS if() which is deprecated see
- Eagerly evaluates arguments (use native @if or if(sass()... if you need lazy evaluation).
File Information
- File: _utils.scss
- Group: utils
- Type: function
- Lines (comments): 139-150
- Lines (code): 152-157
Examples
Example usage
.test {
color: ulu.utils-when(true, red, blue)
}
.test {
color: red;
}
Parameters
| Name |
Type |
Description |
| $condition |
* |
The condition/value to test for truthiness |
| $true |
* |
Value if true |
| $false |
* |
Value if false |
Returns
| Type |
Description |
| * |
Either true or false value based on conditions truthiness |
Provide a default when value type is not correct
File Information
- File: _utils.scss
- Group: utils
- Type: function
- Lines (comments): 159-173
- Lines (code): 175-181
Examples
Example usage
$user-accent-color: #FE5F55;
$user-error-color: "##C6ECAE";
$default-color: #777DA7;
.accent-color {
background-color: ulu.utils-if-type("color", $user-accent-color, $default-color);
}
.error-color {
background-color: ulu.utils-if-type("color", $user-error-color, $default-color);
}
.accent-color {
background-color: #FE5F55;
}
.error-color {
background-color: #777DA7;
}
Parameters
| Name |
Type |
Description |
| $type |
String |
type of value it should be |
| $value |
String |
the value to provide if it is that type |
| $fallback |
String |
the fallback value |
Returns
| Type |
Description |
| CssValue |
Returns the value or the fallback. |
Returns number unit info, and strips the unit
File Information
- File: _utils.scss
- Group: utils
- Type: function
- Lines (comments): 183-195
- Lines (code): 197-223
Examples
Example usage
$size-info: ulu.utils-number-info(24px);
$size-info-invalid: ulu.utils-number-info("Twenty Four Pixels");
.number-info-result {
content: meta.inspect($size-info);
}
.number-info-invalid-result {
content: meta.inspect($size-info-invalid);
}
.number-info-result {
content: ("unit": "px", "value": 24, "invalid": false);
}
.number-info-invalid-result {
content: ("unit": null, "value": "Twenty Four Pixels", "invalid": true);
}
Parameters
| Name |
Type |
Description |
| $number |
String |
Number to get meta info for |
Returns
| Type |
Description |
| Map |
With properties (unit, value, invalid [true/false if not number]) |
Throw
- Expected Number, got #{ meta.type-of($number) } for #
Require
Adds unit to unitless number
File Information
- File: _utils.scss
- Group: utils
- Type: function
- Lines (comments): 225-236
- Lines (code): 238-240
Examples
Example usage
$number: 12;
$unit: "px";
$number-with-unit: ulu.utils-add-unit($number, $unit);
.add-unit-result {
content: $number-with-unit;
}
.add-unit-result {
content: 12px;
}
Parameters
| Name |
Type |
Description |
| $number |
Number |
The unitless number to add unit to |
| $unit |
String |
The unit to add to number |
Returns
| Type |
Description |
| String |
Number with unit attached (can't be used in maths) |
Checks if two numbers are the same unit
File Information
- File: _utils.scss
- Group: utils
- Type: function
- Lines (comments): 242-257
- Lines (code): 259-261
Examples
Example usage
$number-1: 12px;
$number-2: 12px;
$number-3: 12rem;
.positive-result {
content: ulu.utils-units-match($number-1, $number-2);
}
.negative-result {
content: ulu.utils-units-match($number-1, $number-3);
}
.positive-result {
content: true;
}
.negative-result {
content: false;
}
Parameters
| Name |
Type |
| $number |
Number |
| $other-number |
String |
Returns
| Type |
Description |
| Boolean |
Whether they have the same unit type |
| Could be made into multiple arguments in future if needed |
|
Reusable merge method
File Information
- File: _utils.scss
- Group: utils
- Type: function
- Lines (comments): 263-294
- Lines (code): 296-304
Examples
Example usage
$map-1: (
"inner-map" : (
"color" : "green",
"secondary-color" : "green"
),
"color" : "green",
"secondary-color" : "green"
);
$map-2: (
"inner-map" : (
"color" : "red"
),
"color" : "red",
);
.result-default {
$merged-map: ulu.utils-map-merge($map-1, $map-2);
content: meta.inspect($merged-map);
}
.result-deep {
$merged-map-deep: ulu.utils-map-merge($map-1, $map-2, "deep");
content: meta.inspect($merged-map-deep);
}
.result-overwrite {
$merged-map-overwrite: ulu.utils-map-merge($map-1, $map-2, "overwrite");
content: meta.inspect($merged-map-overwrite);
}
.result-default {
content: ("inner-map": ("color": "red"), "color": "red", "secondary-color": "green");
}
.result-deep {
content: ("inner-map": ("color": "red", "secondary-color": "green"), "color": "red", "secondary-color": "green");
}
.result-overwrite {
content: ("inner-map": ("color": "red"), "color": "red");
}
Parameters
| Name |
Type |
Description |
| $original |
Map |
Source map |
| $changes |
Map |
Changes to merge into source map |
| $mode |
String |
How to merge changes (merge [defualt], deep, or overwrite) |
Returns true/false if map has property
File Information
- File: _utils.scss
- Group: utils
- Type: function
- Lines (comments): 306-323
- Lines (code): 325-330
Examples
Example usage
$map-1 : (
"has-key" : true
);
$map-2 : (
"missing-key" : true
);
.map-1 {
content: ulu.utils-map-has($map-1, "has-key");
}
.map-2 {
content: ulu.utils-map-has($map-2, "has-key");
}
.map-1 {
content: true;
}
.map-2 {
content: false;
}
Parameters
| Name |
Type |
Description |
| $map |
Map |
Source map |
| $key |
String |
Property to check for |
Returns
Throw
- map-has(): Incorrect type for $map (should be map)
Require
Repeatable pattern in core
Deprecated
Left in for compatibility, will be removed, use map-merge with mode
File Information
- File: _utils.scss
- Group: utils
- Type: function
- Lines (comments): 332-333
- Lines (code): 335-343
Require
Utility for providing fallbacks, the first truthy value (non false or null) will be returned
File Information
- File: _utils.scss
- Group: utils
- Type: function
- Lines (comments): 345-357
- Lines (code): 359-366
Examples
Example usage
$fallback-text: "No input received";
.user-name:after {
$user-name: "Johnny";
content: ulu.utils-fallback($user-name, $fallback-text);
}
.user-birthdate:after {
$user-birthdate: null;
content: ulu.utils-fallback($user-birthdate, $fallback-text);
}
.user-name:after {
content: "Johnny";
}
.user-birthdate:after {
content: "No input received";
}
Returns
| Type |
Description |
| * |
The first truthy value |
Provides fallback values from the same map
File Information
- File: _utils.scss
- Group: utils
- Type: function
- Lines (comments): 368-380
- Lines (code): 382-390
Examples
Example usage
$map: (
"name": doug,
"gpa": "3",
"grade": "B",
);
.fallback-map {
content: ulu.utils-map-fallback($map, "gpa", "grade", "average");
}
.fallback-map {
content: "3";
}
Returns
Require
Checks if a map contains one or more of the keys
File Information
- File: _utils.scss
- Group: utils
- Type: function
- Lines (comments): 393-409
- Lines (code): 410-429
Examples
Example usage
$map : (
"has-key" : true
);
$keys : (
"has-key",
"needs-key",
);
.map-contains-any-result {
content: ulu.utils-map-contains-any($map, $keys);
}
.map-contains-any-result {
content: true;
}
Parameters
| Name |
Type |
Description |
| $map |
Map |
The map to check |
| $keys |
List |
The list of keys to check for |
| $options |
List |
Options for how this behaves |
| $options.with-value |
List |
Requires that at least one of the map entries from the list has a value other than null |
Throw
- map-contains-any(): Incorrect type for $map (should be map)
- map-contains-any(): Incorrect type for $keys (should be list)
Require
Helps in providing a dynamic fallback for modules whose defaults should come from another
File Information
- File: _utils.scss
- Group: utils
- Type: function
- Lines (comments): 431-437
- Lines (code): 439-465
Examples
Example usage
Parameters
| Name |
Type |
Description |
| $prop |
String |
Property trying to get fallback for |
| $value |
* |
The value that may need the fallback |
| $lookup |
Map |
Map of properties to functions (use sass:meta > meta.get-function to populate) |
Returns
| Type |
Description |
| * |
The user's original value, or if the value is true get the default value from the provided function |
Throw
- Arguments must be a list, use single list for single argument ie
Require
If the value passed is equal to true use the default, else return the value
File Information
- File: _utils.scss
- Group: utils
- Type: function
- Lines (comments): 467-469
- Lines (code): 470-472
Parameters
| Name |
Type |
Description |
| $value |
* |
The value to check |
| $default |
* |
The value to return when true |
Require
Replaces all or one occurrence of a string within a string
File Information
- File: _utils.scss
- Group: utils
- Type: function
- Lines (comments): 474-478
- Lines (code): 480-496
Parameters
| Name |
Type |
Description |
| $string |
String |
String to operate on |
| $find |
String |
String to find within string |
| $replace |
String |
String to replace found strings |
| $all |
Boolean |
Default true replace all matches, if false replace only first |
Require
Remove an item from a list (not map)
- Used for excluding things or as general utility
File Information
- File: _utils.scss
- Group: utils
- Type: function
- Lines (comments): 498-502
- Lines (code): 504-512
Parameters
| Name |
Type |
Description |
| $list |
List |
String to operate on |
| $remove |
* |
Element in the list to remove |
Returns
| Type |
Description |
| List |
New list with item removed |
Remove an item from a list (not map)
- Used for excluding things or as general utility
File Information
- File: _utils.scss
- Group: utils
- Type: function
- Lines (comments): 514-518
- Lines (code): 520-528
Parameters
| Name |
Type |
Description |
| $list |
List |
String to operate on |
| $remove |
List |
List elements that should each be removed |
Returns
| Type |
Description |
| List |
New list with item removed |
Join a list with a separator
File Information
- File: _utils.scss
- Group: utils
- Type: function
- Lines (comments): 530-534
- Lines (code): 536-551
Parameters
| Name |
Type |
Description |
Default |
| $list |
List |
List to join |
|
| $separator |
String |
Separator to use |
", " |
| $to-string |
Boolean |
The resulting list with join separator will be converted to a string (false will return new list with separators added between original items |
true |
Returns
| Type |
Description |
| String |
List |
Resolve spacing info (ie. margin/padding like arguments)
- Will normalize the argument that may be shorthand or single value
- Used for programmatic things with single value config options for padding/margin
File Information
- File: _utils.scss
- Group: utils
- Type: function
- Lines (comments): 553-568
- Lines (code): 570-593
Examples
Example of getting left value
$user-padding: (1em, 2em, 4em);
$spacing: get-spacing($user-padding);
.example {
left: map.get($spacing, "left");
}
Parameters
| Name |
Type |
Description |
| $value |
`Number |
List` |
Returns
| Type |
Description |
| Map |
Map with spacing info for each side (top, right, bottom, left) |
Throw
- Spacing has more than 4 arguments (not correct shorthand)
Require
Resolve the top spacing value for margin/padding like arguments
File Information
- File: _utils.scss
- Group: utils
- Type: function
- Lines (comments): 595-604
- Lines (code): 606-608
Examples
Example of getting top value
$user-padding: (1em, 2em, 4em);
.example {
top: get-spacing-top($user-padding);
}
Parameters
| Name |
Type |
Description |
| $value |
`Number |
List` |
Returns
Require
Resolve the right spacing value for margin/padding like arguments
File Information
- File: _utils.scss
- Group: utils
- Type: function
- Lines (comments): 610-619
- Lines (code): 621-623
Examples
Example of getting right value
$user-padding: (1em, 2em, 4em);
.example {
right: get-spacing-right($user-padding);
}
Parameters
| Name |
Type |
Description |
| $value |
`Number |
List` |
Returns
Require
Resolve the bottom spacing value for margin/padding like arguments
File Information
- File: _utils.scss
- Group: utils
- Type: function
- Lines (comments): 625-634
- Lines (code): 636-638
Examples
Example of getting bottom value
$user-padding: (1em, 2em, 4em);
.example {
bottom: get-spacing-bottom($user-padding);
}
Parameters
| Name |
Type |
Description |
| $value |
`Number |
List` |
Returns
Require
Resolve the left spacing value for margin/padding like arguments
File Information
- File: _utils.scss
- Group: utils
- Type: function
- Lines (comments): 640-649
- Lines (code): 651-653
Examples
Example of getting left value
$user-padding: (1em, 2em, 4em);
.example {
left: get-spacing-left($user-padding);
}
Parameters
| Name |
Type |
Description |
| $value |
`Number |
List` |
Returns
Require
Strips the unit from the number
- Normally this shouldn't be needed
File Information
- File: _utils.scss
- Group: utils
- Type: function
- Lines (comments): 655-661
- Lines (code): 663-673
Examples
Example usage
.test {
line-height: ulu.utils-strip-unit(4rem);
}
.test {
line-height: 4;
}
Throw
- Expected number, got #{ $value }
Require
Calculate the size of something at a given scale (percentage/exponential)
File Information
- File: _utils.scss
- Group: utils
- Type: function
- Lines (comments): 675-680
- Lines (code): 682-684
Parameters
| Name |
Type |
Description |
| $base |
Number |
The number the scale starts at |
| $ratio |
Number |
The amount the scale changes over one set |
| $sizes |
Number |
The number of steps in the scale |
| $size |
Number |
The step you are trying to calculate |
Returns
Require
Convert from pixel to em
File Information
- File: _utils.scss
- Group: utils
- Type: function
- Lines (comments): 686-689
- Lines (code): 691-693
Parameters
| Name |
Type |
Description |
| $pixels |
Number |
The number the scale starts at |
| $base |
Number |
How many pixels equal 1em |
Returns
| Type |
Description |
| Number |
Em Conversion |
Calculates the hypotenuse of a triangle
- Can be used to get length between two corners of a rectangle
File Information
- File: _utils.scss
- Group: utils
- Type: function
- Lines (comments): 709-713
- Lines (code): 715-717
Parameters
| Name |
Type |
Description |
| $width |
Number |
The width of the triangle |
| $height |
Number |
The height of the triangle |
Returns
| Type |
Description |
| Number |
Hypotenuse of a triangle |
Get's the info about a box shadow
File Information
- File: _utils.scss
- Group: utils
- Type: function
- Lines (comments): 719-722
- Lines (code): 724-755
Parameters
| Name |
Type |
Description |
| $shadow |
List |
The box shadow property (ie. 0 0 4px red) |
Returns
| Type |
Description |
| Map |
Map with info about the shadow with the following keys (inset, offset-x, offset-y, blur, spread, color) |
Throw
- Box shadow passed is not correct type (list)
Get's the extent (how far the shadow extends past the box's edge)
- This will only work on box-shadows that have matching units for the numbers
File Information
- File: _utils.scss
- Group: utils
- Type: function
- Lines (comments): 757-761
- Lines (code): 763-781
Parameters
| Name |
Type |
Description |
| $shadow |
List |
The box shadow property (ie. 0 0 4px red) |
| $side |
String |
Optionally pass the side of box to get extend for, if not specified offsets are ignored and just the extent of the shadow is passed |
Returns
| Type |
Description |
| Number |
The size the shadow extends past it's box |
Require
Determines if value passed is a list
File Information
- File: _utils.scss
- Group: utils
- Type: function
- Lines (comments): 783-785
- Lines (code): 787-789
Parameters
| Name |
Type |
Description |
| $value |
* |
Value to check |
Returns
| Type |
Description |
| Boolean |
Whether the item was type list |
Determines if value passed is a map
File Information
- File: _utils.scss
- Group: utils
- Type: function
- Lines (comments): 791-793
- Lines (code): 795-797
Parameters
| Name |
Type |
Description |
| $value |
* |
Value to check |
Returns
| Type |
Description |
| Boolean |
Whether the item was type map |
Determines if value passed is a number
File Information
- File: _utils.scss
- Group: utils
- Type: function
- Lines (comments): 799-801
- Lines (code): 803-805
Parameters
| Name |
Type |
Description |
| $value |
* |
Value to check |
Returns
| Type |
Description |
| Boolean |
Whether the item was type number |
Determines if value passed is a string
File Information
- File: _utils.scss
- Group: utils
- Type: function
- Lines (comments): 807-809
- Lines (code): 811-813
Parameters
| Name |
Type |
Description |
| $value |
* |
Value to check |
Returns
| Type |
Description |
| Boolean |
Whether the item was type string |
Determines if value passed is a color
File Information
- File: _utils.scss
- Group: utils
- Type: function
- Lines (comments): 815-817
- Lines (code): 819-821
Parameters
| Name |
Type |
Description |
| $value |
* |
Value to check |
Returns
| Type |
Description |
| Boolean |
Whether the item was type color |
Returns true if number passed is even
- Allows unit and unitless numbers
File Information
- File: _utils.scss
- Group: utils
- Type: function
- Lines (comments): 841-844
- Lines (code): 846-852
Parameters
| Name |
Type |
Description |
| $number |
Number |
The number to check |
Returns
| Type |
Description |
| Boolean |
Whether or not it is an even number |
Throw
- Expected Number, got #{ $number }
Require
Returns true if number passed is odd
File Information
- File: _utils.scss
- Group: utils
- Type: function
- Lines (comments): 854-856
- Lines (code): 858-860
Parameters
| Name |
Type |
Description |
| $number |
Number |
The number to check |
Returns
| Type |
Description |
| Boolean |
Whether or not it is an odd number |
Require
Always returns a map
File Information
- File: _utils.scss
- Group: utils
- Type: function
- Lines (comments): 862-864
- Lines (code): 866-868
Parameters
| Name |
Type |
Description |
| $value |
* |
The value to check if is map |
Returns
| Type |
Description |
| Map |
The $value if it was a map, else empty map |
Require
Returns true if edge passed is an end (top/bottom)
File Information
- File: _utils.scss
- Group: utils
- Type: function
- Lines (comments): 870-873
- Lines (code): 875-883
Parameters
| Name |
Type |
Description |
| $edge |
String |
The edge string to test |
Returns
| Type |
Description |
| Boolean |
Whether the edge was an end (versus side/x-axis) |
Throw
- Expected side to be top/bottom/left/right, got #{ $edge }
Returns true if edge passed is an side (left/right)
File Information
- File: _utils.scss
- Group: utils
- Type: function
- Lines (comments): 885-888
- Lines (code): 890-892
Parameters
| Name |
Type |
Description |
| $edge |
String |
The edge string to test |
Returns
| Type |
Description |
| Boolean |
Whether the edge was an side (versus end/y-axis) |
Throw
- If $edge is not a valid value (not top/bottom/left/right)
Require
For legacy aspect ratio conversion
- For a given value if it's a percentage number convert to css aspect ratio like 16/9
File Information
- File: _utils.scss
- Group: utils
- Type: function
- Lines (comments): 894-897
- Lines (code): 899-914
Parameters
| Name |
Type |
Description |
| $value |
`String |
Number` |
Returns
| Type |
Description |
| String |
Either the original value or a converted value depending on if it was a percentage number |
Require