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 install str.scss
Github Gist with all str.scss functions in one file.
Usage
; ; .#{str-to-lowercase(str-replace($section-name, ' ', '-'))}
Compiled to
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
- str-to-upper-case Returns the calling string value converted to uppercase
- str-to-lower-case Returns the calling string value converted to lowercase
- str-quote Returns $input-string as quoted string
- str-unique-id Returns a randomly-generated unquoted string
- str-unquote Returns $input-string as unquoted string
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
; ;// => Hello wold ;// => 123
; ;// => Hello wold ;// => Error: "[str.scss] [str-capitalize] `123` must be of type `string`, got `number`."
Functions
str-chars($input-string) => list
Returns SCSS list with all string characters.
Argument | Type | Required | Default |
---|---|---|---|
input-string | string | + |
- |
return list
Example
;// => ("H" "e" "l" "l" "o" " " "w" "o" "r" "l" "d")
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
;// => "e" ;// => "o"
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
;// => ("Hello" "World") ;// => ("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
;// => "1. Hello World" ;// => "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
;// => "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
;// => "Heo word" ;// => "Helo world" ;// => "Privet world"
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
;// => "He*** w*r*d" ;// => "Hel world" ;// => "Privet Privet mir"
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
;// => 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-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
;// => 0 ;// => 3 ;// => 1
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
;// => 3 ;// => null
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
;// => 10 ;// => null
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
;// => "Hello Wold" ;// => "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-decapitalize($input-string) => string
Returns string with decapitalized first letter
Argument | Type | Required | Default |
---|---|---|---|
input-string | string | + |
- |
return string
Example
;// => "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
;// => "dlroW olleH"
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
;// => "Hello World" ;// => "Hello 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
;// => "Hello World " ;// => "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
;// => " Hello World" ;// => " -_ 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
;// => "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
;// => true ;// => true ;// => false
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
;// => true ;// => false ;// => 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
;// => true ;// => false ;// => 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
;// => "Hello" ;// => "HelloHello" ;// => "Hello, Hello"
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
;// => "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
;// => "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
;// => "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
;// => e.g. "ufl6i52"
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
;// => .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
.