str.scss
str.scss - set of functions that helps to manipulate strings.
Important updates in v. 1.2
str-to-uppercase
alias function is renamed to str-to-upper-case
srt-to-lowercase
alias function is renamed to str-to-lower-case
Please update your code
Install
NPM
npm install str.scss
Gist
Github Gist with all str.scss functions in one file.
Usage
@import "~node_modules/str.scss/str";
$section-name: 'Hello World';
.#{str-to-lowercase(str-replace($section-name, ' ', '-'))} {
&__title {
&::after {
content: str-to-uppercase($section-name)
}
}
}
Compiled to
.hello-world__title:after {
content: "HELLO WORLD";
}
Functions
- str-chars Returns SCSS list with all string characters.
- str-char-at Returns character from input string at provided index
- str-split Returns an array of strings by separating the string into substrings
- str-join Returns input list converted to a string
- str-to-swapcase Returns a copy of the string in which all the case-based characters have had their case swapped.
- str-replace Returns copy of input string where defined substring replaced by $replace argument
- str-bulk-replace Returns copy of input string where defined substrings replaced by $replace argument
- str-include Returns boolean result of check if string contains a substring.
- str-count Returns number of occurrences of substring in string.
- str-first-index Returns first index of substring in provided string
- str-last-index Returns last index of substring in provided string
- str-capitalize Returns string with capitalized first letter
- str-decapitalize Returns string with decapitalized first letter
- str-reverse Returns reversed string.
- str-trim Returns trimmed string
- str-ltrim Returns string with removed leading characters.
- str-rtrim Returns string with removed trailing characters.
- str-clean Returns trimmed string with multiply spaces replaced with single space
- str-is-blank Returns true if string is empty or contains whitespaces only
- str-starts-with Returns true if string starts with provided substring
- str-ends-with Returns true if string ends with provided substring
- str-repeat Returns input string repeated provided number of times
Aliases
Global settings
$str-scss-strong-type-check: boolean
Dafault: false
Required: false
Use $str-scss-strong-type-check: true;
to crash compilation each time when any str.scss
function is provided with argument with wrong type.
Example
$str-scss-strong-type-check: false;
@debug str-capitalize('hello wold');
@debug str-capitalize(123);
$str-scss-strong-type-check: true;
@debug str-capitalize('hello wold');
@debug str-capitalize(123);
Functions
str-chars($input-string) => list
Returns SCSS list with all string characters.
Argument | Type | Required | Default |
---|
input-string | string | + | - |
return list
Example
@debug str-chars('Hello world');
Errors handling
Arguments to be checked: $input-string
.
In case of error and $str-scss-strong-type-check
is set to false
function returns ()
.
str-char-at($input-string, $index) => string
Returns character from input string at provided index
Argument | Type | Required | Default |
---|
input-string | string | + | - |
index | number | + | - |
return string
Example
@debug str-char-at('Hello World', 2);
@debug str-char-at('Hello World', -4);
Errors handling
Arguments to be checked: $input-string, $index
.
In case of error and $str-scss-strong-type-check
is set to false
function returns ''
.
str-split($input-string[, $separator]) => list
Returns an array of strings by separating the string into substrings
Argument | Type | Required | Default |
---|
input-string | string | + | - |
separator | string | - | ' ' |
return list
Example
@debug str-split('Hello World');
@debug str-split('Hello World, Hello World', ', ');
Errors handling
Arguments to be checked: $input-string, $separator
.
In case of error and $str-scss-strong-type-check
is set to false
function returns ()
.
str-join($input-list[, $separator]) => string
Returns input list converted to a string
Argument | Type | Required | Default |
---|
input-list | list | + | - |
separator | string | - | '' |
return string
Example
@debug str-join((1, '. ', 'H', 'e', 'l', 'l', 'o', ' ', 'W', 'o', 'r', 'l', 'd'));
@debug str-join(('a', 'b', 'c'), '*');
Errors handling
Arguments to be checked: $input-list, $separator
.
In case of error and $str-scss-strong-type-check
is set to false
function returns ''
.
str-to-swapcase($input-string) => string
Returns a copy of the string in which all the case-based characters have had their case swapped.
Argument | Type | Required | Default |
---|
input-string | string | + | - |
return string
Example
@debug str-to-swapcase('hELLO wORLD');
Errors handling
Arguments to be checked: $input-string
.
In case of error and $str-scss-strong-type-check
is set to false
function returns $input-string
.
str-replace($input-string, $substring[, $replace, $g]) => string
Returns copy of input string where defined substring replaced by $replace argument
Argument | Type | Required | Default |
---|
input-string | string | + | - |
substring | string | + | - |
replace | string | - | '' |
g | boolean | - | true |
return string
Example
@debug str-replace('Hello world', 'l');
@debug str-replace('Hello world', 'l', $g: false);
@debug str-replace('Hello world', 'Hello', 'Privet');
Errors handling
Arguments to be checked: $input-string, $substring, $replace
.
In case of error and $str-scss-strong-type-check
is set to false
function returns $input-string
.
str-bulk-replace($input-string, $substrings[, $replace, $g]) => string
Returns copy of input string where defined substrings replaced by $replace argument
Argument | Type | Required | Default |
---|
input-string | string | + | - |
substrings | list | + | - |
replace | string | - | '' |
g | boolean | - | true |
return string
Example
@debug str-bulk-replace('Hello world', ('l', 'o'), '*');
@debug str-bulk-replace('Hello world', ('l', 'o'), $g: false);
@debug str-bulk-replace('Hello To The mir', ('Hello', 'To The'), 'Privet');
Errors handling
Arguments to be checked: $input-string, $substrings, $replace
.
In case of error and $str-scss-strong-type-check
is set to false
function returns $input-string
.
str-include($input-string, $substring) => boolean
Returns boolean result of check if string contains a substring.
Argument | Type | Required | Default |
---|
input-string | string | + | - |
substring | string | + | - |
return boolean
Example
@debug str-include('Hello World', 'lo');
Errors handling
Arguments to be checked: $input-string, $substring
.
In case of error and $str-scss-strong-type-check
is set to false
function returns null
.
str-count($input-string, $substring) => number
Returns number of occurrences of substring in string.
Argument | Type | Required | Default |
---|
input-string | string | + | - |
substring | string | + | - |
return number
Example
@debug str-count('Hello World', 'z');
@debug str-count('Hello World', 'l');
@debug str-count('Hello World', 'ello');
Errors handling
Arguments to be checked: $input-string, $substring
.
In case of error and $str-scss-strong-type-check
is set to false
function returns 0
.
str-first-index($input-string, $substring) => number
Returns first index of substring in provided string
Argument | Type | Required | Default |
---|
input-string | string | + | - |
substring | string | + | - |
return number
Example
@debug str-first-index('Hello World', 'l');
@debug str-first-index('Hello World', 'z');
Errors handling
Arguments to be checked: $input-string, $substring
.
In case of error and $str-scss-strong-type-check
is set to false
function returns null
.
str-last-index($input-string, $substring) => number
Returns last index of substring in provided string
Argument | Type | Required | Default |
---|
input-string | string | + | - |
substring | string | + | - |
return number
Example
@debug str-last-index('Hello World', 'l');
@debug str-last-index('Hello World', 'z');
Errors handling
Arguments to be checked: $input-string, $substring
.
In case of error and $str-scss-strong-type-check
is set to false
function returns null
.
str-capitalize($input-string[, $lowercase-rest]) => string
Returns string with capitalized first letter
Argument | Type | Required | Default |
---|
input-string | string | + | - |
lowercase-rest | boolean | - | false |
return string
Example
@debug str-capitalize('hello Wold');
@debug str-capitalize('hELLO WORLD', true);
Errors handling
Arguments to be checked: $input-string
.
In case of error and $str-scss-strong-type-check
is set to false
function returns $input-string
.
str-decapitalize($input-string) => string
Returns string with decapitalized first letter
Argument | Type | Required | Default |
---|
input-string | string | + | - |
return string
Example
@debug str-decapitalize('Hello World');
Errors handling
Arguments to be checked: $input-string
.
In case of error and $str-scss-strong-type-check
is set to false
function returns $input-string
.
str-reverse($input-string) => string
Returns reversed string.
Argument | Type | Required | Default |
---|
input-string | string | + | - |
return string
Example
@debug str-reverse('Hello World');
Errors handling
Arguments to be checked: $input-string
.
In case of error and $str-scss-strong-type-check
is set to false
function returns $input-string
.
str-trim($input-string[, $trim-chars]) => string
Returns trimmed string
Argument | Type | Required | Default |
---|
input-string | string | + | - |
trim-chars | string | - | ' ' |
return string
Example
@debug str-trim(' Hello World ');
@debug str-trim(' -_ Helllo World _- ', '- _');
Errors handling
Arguments to be checked: $input-string, $trim-chars
.
In case of error and $str-scss-strong-type-check
is set to false
function returns $input-string
.
str-ltrim($input-string[, $trim-chars]) => string
Returns string with removed leading characters.
Argument | Type | Required | Default |
---|
input-string | string | + | - |
trim-chars | string | - | ' ' |
return string
Example
@debug str-ltrim(' Hello World ');
@debug str-ltrim(' -_ Helllo World _- ', '- _');
Errors handling
Arguments to be checked: $input-string, $trim-chars
.
In case of error and $str-scss-strong-type-check
is set to false
function returns $input-string
.
str-rtrim($input-string[, $trim-chars]) => string
Returns string with removed trailing characters.
Argument | Type | Required | Default |
---|
input-string | string | + | - |
trim-chars | string | - | ' ' |
return string
Example
@debug str-rtrim(' Hello World ');
@debug str-rtrim(' -_ Helllo World _- ', '- _');
Errors handling
Arguments to be checked: $input-string, $trim-chars
.
In case of error and $str-scss-strong-type-check
is set to false
function returns $input-string
.
str-clean($input-string) => string
Returns trimmed string with multiply spaces replaced with single space
Argument | Type | Required | Default |
---|
input-string | string | + | - |
return string
Example
@debug str-clean(' Hello World ');
Errors handling
Arguments to be checked: $input-string
.
In case of error and $str-scss-strong-type-check
is set to false
function returns $input-string
.
str-is-blank($input-string) => boolean
Returns true if string is empty or contains whitespaces only
Argument | Type | Required | Default |
---|
input-string | string | + | - |
return boolean
Example
@debug str-is-blank('');
@debug str-is-blank(' ');
@debug str-is-blank('Hello World');
Errors handling
Arguments to be checked: $input-string
.
In case of error and $str-scss-strong-type-check
is set to false
function returns null
.
str-starts-with($input-string, $substring[, $ignore-case]) => boolean
Returns true if string starts with provided substring
Argument | Type | Required | Default |
---|
input-string | string | + | - |
substring | string | + | - |
ignore-case | boolean | + | - |
return boolean
Example
@debug str-starts-with('Hello World', 'Hel');
@debug str-starts-with('Hello World', 'hel');
@debug str-starts-with('Hello World', 'hel', true);
Errors handling
Arguments to be checked: $input-string, $substring
.
In case of error and $str-scss-strong-type-check
is set to false
function returns null
.
str-ends-with($input-string, $substring[, $ignore-case]) => boolean
Returns true if string ends with provided substring
Argument | Type | Required | Default |
---|
input-string | string | + | - |
substring | string | + | - |
ignore-case | boolean | - | false |
return boolean
Example
@debug str-ends-with('Hello World', 'rld');
@debug str-ends-with('Hello World', 'RLD');
@debug str-ends-with('Hello World', 'RLD', true);
Errors handling
Arguments to be checked: $input-string, $substring
.
In case of error and $str-scss-strong-type-check
is set to false
function returns null
.
str-repeat($input-string[, $times, $separator]) => string
Returns input string repeated provided number of times
Argument | Type | Required | Default |
---|
input-string | string | + | - |
times | number | - | 1 |
separate-with | string | - | '' |
return string
Example
@debug str-repeat('Hello');
@debug str-repeat('Hello', 2);
@debug str-repeat('Hello', 2, ', ');
Errors handling
Arguments to be checked: $input-string, $times, $separator
.
In case of error and $str-scss-strong-type-check
is set to false
function returns $input-string
.
Aliases
str-to-upper-case($input-string) => string
Returns the calling string value converted to uppercase
Alias for to-upper-case String SASS built-in function
Argument | Type | Required | Default |
---|
input-string | string | + | - |
return string
Example
@debug str-to-upper-case('hello world');
Errors handling
Arguments to be checked: $input-string
.
In case of error and $str-scss-strong-type-check
is set to false
function returns $input-string
.
str-to-lower-case($input-string) => string
Returns the calling string value converted to lowercase
Alias for to-lower-case String SASS built-in function
Argument | Type | Required | Default |
---|
input-string | string | + | - |
return string
Example
@debug str-to-lower-case('Hello World');
Errors handling
Arguments to be checked: $input-string
.
In case of error and $str-scss-strong-type-check
is set to false
function returns $input-string
.
str-quote($input-string) => string
Returns $input-string as quoted string
Alias for quote String SASS built-in function
Argument | Type | Required | Default |
---|
input-string | string | + | - |
return string
Example
@debug str-quote(Hello);
Errors handling
Arguments to be checked: $input-string
.
In case of error and $str-scss-strong-type-check
is set to false
function returns $input-string
.
str-unique-id() => string
Returns a randomly-generated unquoted string
Alias for unique-id String SASS built-in function
return string
Example
@debug str-unique-id();
str-unquote($input-string) => string
Returns $input-string as unquoted string
Alias for unquote String SASS built-in function
Argument | Type | Required | Default |
---|
input-string | string | + | - |
return string
Example
@debug str-unquote('.link:hover');
Errors handling
Arguments to be checked: $input-string
.
In case of error and $str-scss-strong-type-check
is set to false
function returns $input-string
.