SassyStrings 1.0.1 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +1 -0
- data/README.md +5 -0
- data/lib/SassyStrings.rb +2 -2
- data/stylesheets/_SassyStrings.scss +2 -20
- data/stylesheets/private/_all.scss +24 -0
- data/stylesheets/private/_char-at.scss +16 -0
- data/stylesheets/private/_levenshtein.scss +105 -0
- data/stylesheets/private/_str-count.scss +27 -0
- data/stylesheets/private/_str-ends-with.scss +16 -0
- data/stylesheets/private/_str-explode.scss +41 -0
- data/stylesheets/private/_str-implode.scss +21 -0
- data/stylesheets/private/_str-last-index.scss +27 -0
- data/stylesheets/private/_str-lcfirst.scss +15 -0
- data/stylesheets/private/_str-pad.scss +36 -0
- data/stylesheets/private/_str-printf.scss +29 -0
- data/stylesheets/private/_str-repeat.scss +22 -0
- data/stylesheets/private/_str-replace.scss +33 -0
- data/stylesheets/private/_str-reverse.scss +21 -0
- data/stylesheets/private/_str-rot.scss +39 -0
- data/stylesheets/private/_str-shuffle.scss +36 -0
- data/stylesheets/private/_str-starts-with.scss +16 -0
- data/stylesheets/private/_str-trim.scss +31 -0
- data/stylesheets/private/_str-ucfirst.scss +15 -0
- data/stylesheets/{functions → private}/_str-word-count.scss +5 -6
- data/stylesheets/private/_stringify.scss +26 -0
- data/stylesheets/public/_all.scss +23 -0
- data/stylesheets/public/_char-at.scss +31 -0
- data/stylesheets/public/_levenshtein.scss +26 -0
- data/stylesheets/public/_str-count.scss +26 -0
- data/stylesheets/public/_str-ends-with.scss +26 -0
- data/stylesheets/public/_str-explode.scss +26 -0
- data/stylesheets/public/_str-implode.scss +19 -0
- data/stylesheets/{functions → public}/_str-last-index.scss +5 -12
- data/stylesheets/public/_str-lcfirst.scss +20 -0
- data/stylesheets/public/_str-pad.scss +33 -0
- data/stylesheets/public/_str-printf.scss +21 -0
- data/stylesheets/public/_str-repeat.scss +26 -0
- data/stylesheets/public/_str-replace.scss +39 -0
- data/stylesheets/public/_str-reverse.scss +20 -0
- data/stylesheets/public/_str-rot.scss +26 -0
- data/stylesheets/public/_str-shuffle.scss +18 -0
- data/stylesheets/public/_str-starts-with.scss +26 -0
- data/stylesheets/public/_str-trim.scss +20 -0
- data/stylesheets/{functions → public}/_str-ucfirst.scss +6 -2
- data/stylesheets/public/_str-word-count.scss +20 -0
- data/stylesheets/public/_stringify.scss +15 -0
- metadata +44 -22
- data/stylesheets/functions/_char-at.scss +0 -25
- data/stylesheets/functions/_levenshtein.scss +0 -99
- data/stylesheets/functions/_str-count.scss +0 -31
- data/stylesheets/functions/_str-ends-with.scss +0 -20
- data/stylesheets/functions/_str-explode.scss +0 -45
- data/stylesheets/functions/_str-implode.scss +0 -15
- data/stylesheets/functions/_str-lcfirst.scss +0 -14
- data/stylesheets/functions/_str-pad.scss +0 -45
- data/stylesheets/functions/_str-printf.scss +0 -28
- data/stylesheets/functions/_str-repeat.scss +0 -26
- data/stylesheets/functions/_str-replace.scss +0 -47
- data/stylesheets/functions/_str-reverse.scss +0 -20
- data/stylesheets/functions/_str-rot.scss +0 -43
- data/stylesheets/functions/_str-shuffle.scss +0 -26
- data/stylesheets/functions/_str-starts-with.scss +0 -20
- data/stylesheets/functions/_str-trim.scss +0 -30
- data/stylesheets/functions/_stringify.scss +0 -21
@@ -0,0 +1,22 @@
|
|
1
|
+
/*
|
2
|
+
* Repeat $string $times times
|
3
|
+
* ---
|
4
|
+
* @access private
|
5
|
+
* ---
|
6
|
+
* @since 1.2.0
|
7
|
+
* ---
|
8
|
+
* @param {string} $string - string to repeat
|
9
|
+
* @param {number} $times - number of times to repeat $string
|
10
|
+
* ---
|
11
|
+
* @return {string|false}
|
12
|
+
*/
|
13
|
+
|
14
|
+
@function _ss-str-repeat($string, $times) {
|
15
|
+
$result: "";
|
16
|
+
|
17
|
+
@for $i from 1 through $times {
|
18
|
+
$result: $result + $string;
|
19
|
+
}
|
20
|
+
|
21
|
+
@return $result;
|
22
|
+
}
|
@@ -0,0 +1,33 @@
|
|
1
|
+
/*
|
2
|
+
* Replace $old occurrences by $new in $string respecting $case-sensitive
|
3
|
+
* ---
|
4
|
+
* @access private
|
5
|
+
* ---
|
6
|
+
* @since 1.2.0
|
7
|
+
* ---
|
8
|
+
* @param {string} $string - string
|
9
|
+
* @param {string} $old - old substring to replace by $new
|
10
|
+
* @param {string} $new - new substring to replace $old
|
11
|
+
* @param {bool} $case-sensitive - case-sensitivity
|
12
|
+
* ---
|
13
|
+
* @return {string}
|
14
|
+
*/
|
15
|
+
|
16
|
+
@function _ss-str-replace($string, $old, $new: '', $case-sensitive: true) {
|
17
|
+
$index: if(not $case-sensitive, str-index(to-lower-case($string), to-lower-case($old)), str-index($string, $old));
|
18
|
+
|
19
|
+
@if $index and $new != $old {
|
20
|
+
$result: if($index != 1, quote(str-slice($string, 1, $index - 1)), '');
|
21
|
+
|
22
|
+
@for $i from $index through str-length($string) {
|
23
|
+
@if $i < $index or $i >= $index + str-length($old) {
|
24
|
+
$result: $result + str-slice($string, $i, $i);
|
25
|
+
}
|
26
|
+
}
|
27
|
+
|
28
|
+
@return quote(str-replace(str-insert($result, $new, $index), $old, $new, $case-sensitive));
|
29
|
+
}
|
30
|
+
|
31
|
+
@return $string;
|
32
|
+
}
|
33
|
+
|
@@ -0,0 +1,21 @@
|
|
1
|
+
/*
|
2
|
+
* Reverse $string
|
3
|
+
* ---
|
4
|
+
* @access private
|
5
|
+
* ---
|
6
|
+
* @since 1.2.0
|
7
|
+
* ---
|
8
|
+
* @param {string} $string - string to reverse
|
9
|
+
* ---
|
10
|
+
* @return {string}
|
11
|
+
*/
|
12
|
+
|
13
|
+
@function _ss-str-reverse($string) {
|
14
|
+
$result: "";
|
15
|
+
|
16
|
+
@for $i from str-length($string) * -1 through -1 {
|
17
|
+
$result: $result + str-slice($string, abs($i), abs($i));
|
18
|
+
}
|
19
|
+
|
20
|
+
@return $result;
|
21
|
+
}
|
@@ -0,0 +1,39 @@
|
|
1
|
+
/*
|
2
|
+
* Rotate all characters from the alphabet in $string by $rot positions
|
3
|
+
* ---
|
4
|
+
* @access private
|
5
|
+
* ---
|
6
|
+
* @since 1.2.0
|
7
|
+
* ---
|
8
|
+
* @param {string} $string - string to rotate
|
9
|
+
* @param {number} $rot - number of positions to switch in alphabet
|
10
|
+
* ---
|
11
|
+
* @return {string}
|
12
|
+
*/
|
13
|
+
|
14
|
+
@function _ss-str-rot($string, $rot: 13) {
|
15
|
+
$alphabet: a b c d e f g h i j k l m n o p q r s t u v w x y z;
|
16
|
+
$result: "";
|
17
|
+
$rot: if(type-of($rot) == "number", floor($rot), 13);
|
18
|
+
|
19
|
+
@for $i from 1 through str-length($string) {
|
20
|
+
$char: str-slice($string, $i, $i);
|
21
|
+
$index: index($alphabet, to-lower-case($char));
|
22
|
+
$is-caps: $index and (index($alphabet, to-lower-case($char)) != index($alphabet, $char));
|
23
|
+
$new-char: if($index,
|
24
|
+
if($index + $rot > length($alphabet),
|
25
|
+
nth($alphabet, $index + $rot - length($alphabet)),
|
26
|
+
nth($alphabet, $index + $rot)
|
27
|
+
),
|
28
|
+
$char
|
29
|
+
);
|
30
|
+
|
31
|
+
@if $is-caps {
|
32
|
+
$new-char: to-upper-case($new-char);
|
33
|
+
}
|
34
|
+
|
35
|
+
$result: $result + $new-char;
|
36
|
+
}
|
37
|
+
|
38
|
+
@return $result;
|
39
|
+
}
|
@@ -0,0 +1,36 @@
|
|
1
|
+
/*
|
2
|
+
* Shuffle characters from $string
|
3
|
+
* ---
|
4
|
+
* @access private
|
5
|
+
* ---
|
6
|
+
* @since 1.2.0
|
7
|
+
* ---
|
8
|
+
* @param {string} $string - string to shuffle
|
9
|
+
* ---
|
10
|
+
* @return {string}
|
11
|
+
*/
|
12
|
+
|
13
|
+
@function _ss-str-shuffle($string) {
|
14
|
+
@return str-implode(_ss-shuffle(str-explode($string)));
|
15
|
+
}
|
16
|
+
|
17
|
+
/*
|
18
|
+
* Shuffle a list
|
19
|
+
* ---
|
20
|
+
* @access private
|
21
|
+
* ---
|
22
|
+
* @param {list} $list - shuffle a list
|
23
|
+
* ---
|
24
|
+
* @return {list}
|
25
|
+
*/
|
26
|
+
|
27
|
+
@function _ss-shuffle($list) {
|
28
|
+
@for $i from -1 * length($list) through -1 {
|
29
|
+
$i: abs($i);
|
30
|
+
$j: random(length($list) - 1) + 1;
|
31
|
+
$tmp: nth($list, $i);
|
32
|
+
$list: set-nth($list, $i, nth($list, $j));
|
33
|
+
$list: set-nth($list, $j, $tmp);
|
34
|
+
}
|
35
|
+
@return $list;
|
36
|
+
}
|
@@ -0,0 +1,16 @@
|
|
1
|
+
/*
|
2
|
+
* Check whether $string stars with $needle
|
3
|
+
* ---
|
4
|
+
* @access private
|
5
|
+
* ---
|
6
|
+
* @since 1.2.0
|
7
|
+
* ---
|
8
|
+
* @param {string} $string - string to check
|
9
|
+
* @param {string} $needle - substring to check
|
10
|
+
* ---
|
11
|
+
* @return {bool}
|
12
|
+
*/
|
13
|
+
|
14
|
+
@function _ss-str-starts-with($string, $needle) {
|
15
|
+
@return str-slice($string, 1, str-length($needle)) == $needle;
|
16
|
+
}
|
@@ -0,0 +1,31 @@
|
|
1
|
+
/*
|
2
|
+
* Remove all trailing and leading whitespaces from $string
|
3
|
+
* ---
|
4
|
+
* @access private
|
5
|
+
* ---
|
6
|
+
* @since 1.2.0
|
7
|
+
* ---
|
8
|
+
* @param {string} $string - string
|
9
|
+
* ---
|
10
|
+
* @return {string}
|
11
|
+
*/
|
12
|
+
|
13
|
+
@function _ss-str-trim($string) {
|
14
|
+
$start: 1;
|
15
|
+
$end: str-length($string);
|
16
|
+
|
17
|
+
@for $i from 1 through str-length($string) {
|
18
|
+
$first: str-slice($string, $i, $i);
|
19
|
+
$last: str-slice($string, -$i, -$i);
|
20
|
+
|
21
|
+
@if $first == " " and $i + 1 == $start + 1 {
|
22
|
+
$start: $i + 1;
|
23
|
+
}
|
24
|
+
|
25
|
+
@if $last == " " and str-length($string) - $i == $end - 1 {
|
26
|
+
$end: str-length($string) - $i;
|
27
|
+
}
|
28
|
+
}
|
29
|
+
|
30
|
+
@return str-slice($string, $start, $end);
|
31
|
+
}
|
@@ -0,0 +1,15 @@
|
|
1
|
+
/*
|
2
|
+
* Capitalize first letter from $string
|
3
|
+
* ---
|
4
|
+
* @access private
|
5
|
+
* ---
|
6
|
+
* @since 1.2.0
|
7
|
+
* ---
|
8
|
+
* @param {string} $string - string for capitalization
|
9
|
+
* ---
|
10
|
+
* @return {string}
|
11
|
+
*/
|
12
|
+
|
13
|
+
@function _ss-str-ucfirst($string) {
|
14
|
+
@return to-upper-case(str-slice($string, 1, 1)) + str-slice($string, 2);
|
15
|
+
}
|
@@ -1,17 +1,16 @@
|
|
1
1
|
/*
|
2
2
|
* Count number of words in $string
|
3
3
|
* ---
|
4
|
+
* @access private
|
5
|
+
* ---
|
6
|
+
* @since 1.2.0
|
7
|
+
* ---
|
4
8
|
* @param {string} $string - string to check
|
5
9
|
* ---
|
6
10
|
* @return {string|false}
|
7
11
|
*/
|
8
12
|
|
9
|
-
@function str-word-count($string) {
|
10
|
-
@if type-of($string) != "string" {
|
11
|
-
@warn "`str-word-count` function expecting a string for $string; #{type-of($string)} given.";
|
12
|
-
@return false;
|
13
|
-
}
|
14
|
-
|
13
|
+
@function _ss-str-word-count($string) {
|
15
14
|
@if $string == '' {
|
16
15
|
@return 0;
|
17
16
|
}
|
@@ -0,0 +1,26 @@
|
|
1
|
+
/*
|
2
|
+
* Cast anything to string
|
3
|
+
* ---
|
4
|
+
* @access private
|
5
|
+
* ---
|
6
|
+
* @since 1.2.0
|
7
|
+
* ---
|
8
|
+
* @param {literal} $literal: number to cast to string
|
9
|
+
* ---
|
10
|
+
* @return {string}
|
11
|
+
*/
|
12
|
+
|
13
|
+
@function _ss-stringify($literal) {
|
14
|
+
$result: "";
|
15
|
+
|
16
|
+
@if length($literal) == 1 {
|
17
|
+
$result: $literal + unquote("");
|
18
|
+
} @else {
|
19
|
+
@each $item in $literal {
|
20
|
+
$result: $result + stringify($item);
|
21
|
+
}
|
22
|
+
}
|
23
|
+
|
24
|
+
@return quote($result);
|
25
|
+
|
26
|
+
}
|
@@ -0,0 +1,23 @@
|
|
1
|
+
//* ----------------------------------------------------- */
|
2
|
+
// Public files for use in your project
|
3
|
+
//* ----------------------------------------------------- */
|
4
|
+
@import "char-at";
|
5
|
+
@import "levenshtein";
|
6
|
+
@import "str-count";
|
7
|
+
@import "str-ends-with";
|
8
|
+
@import "str-explode";
|
9
|
+
@import "str-implode";
|
10
|
+
@import "str-last-index";
|
11
|
+
@import "str-lcfirst";
|
12
|
+
@import "str-pad";
|
13
|
+
@import "str-printf";
|
14
|
+
@import "str-repeat";
|
15
|
+
@import "str-replace";
|
16
|
+
@import "str-reverse";
|
17
|
+
@import "str-rot";
|
18
|
+
@import "str-shuffle";
|
19
|
+
@import "str-starts-with";
|
20
|
+
@import "str-trim";
|
21
|
+
@import "str-ucfirst";
|
22
|
+
@import "str-word-count";
|
23
|
+
@import "stringify";
|
@@ -0,0 +1,31 @@
|
|
1
|
+
/*
|
2
|
+
* Return character from $string at $index
|
3
|
+
* ---
|
4
|
+
* @access public
|
5
|
+
* ---
|
6
|
+
* @since 1.0.0
|
7
|
+
* ---
|
8
|
+
* @param {string} $string - string to check
|
9
|
+
* @param {string} $index - index to inspect
|
10
|
+
* ---
|
11
|
+
* @return {string}
|
12
|
+
*/
|
13
|
+
|
14
|
+
@function char-at($string, $index) {
|
15
|
+
@if type-of($string) != "string" {
|
16
|
+
@warn "`char-at` function expecting a string for $string; #{type-of($string)} given.";
|
17
|
+
@return false;
|
18
|
+
}
|
19
|
+
|
20
|
+
@if type-of($index) != "number" {
|
21
|
+
@warn "`char-at` function expecting a number for $index; #{type-of($index)} given.";
|
22
|
+
@return false;
|
23
|
+
}
|
24
|
+
|
25
|
+
@if $index < 1 or $index > str-length($string) {
|
26
|
+
@warn "Out of bounds $index for `char-at`.";
|
27
|
+
@return false;
|
28
|
+
}
|
29
|
+
|
30
|
+
@return _ss-char-at($string, $index);
|
31
|
+
}
|
@@ -0,0 +1,26 @@
|
|
1
|
+
/*
|
2
|
+
* Calculating Levenshtein distance between two strings
|
3
|
+
* ---
|
4
|
+
* @access public
|
5
|
+
* ---
|
6
|
+
* @since 1.0.0
|
7
|
+
* ---
|
8
|
+
* @param {string} $a - first string
|
9
|
+
* @param {string} $b - second string
|
10
|
+
* ---
|
11
|
+
* @return {number}
|
12
|
+
*/
|
13
|
+
|
14
|
+
@function levenshtein($a, $b) {
|
15
|
+
@if type-of($a) != "string" {
|
16
|
+
@warn "`str-count` function expecting a string for $a; #{type-of($a)} given.";
|
17
|
+
@return false;
|
18
|
+
}
|
19
|
+
|
20
|
+
@if type-of($b) != "string" {
|
21
|
+
@warn "`str-count` function expecting a string for $b; #{type-of($b)} given.";
|
22
|
+
@return false;
|
23
|
+
}
|
24
|
+
|
25
|
+
@return _ss-levenshtein($a, $b);
|
26
|
+
}
|
@@ -0,0 +1,26 @@
|
|
1
|
+
/*
|
2
|
+
* Count the number of occurrences of $needle in $string
|
3
|
+
* ---
|
4
|
+
* @access public
|
5
|
+
* ---
|
6
|
+
* @since 1.0.0
|
7
|
+
* ---
|
8
|
+
* @param {string} $string - string
|
9
|
+
* @param {string} $needle - substring to count in $string
|
10
|
+
* ---
|
11
|
+
* @return {number|false}
|
12
|
+
*/
|
13
|
+
|
14
|
+
@function str-count($string, $needle) {
|
15
|
+
@if type-of($string) != "string" {
|
16
|
+
@warn "`str-count` function expecting a string for $string; #{type-of($string)} given.";
|
17
|
+
@return false;
|
18
|
+
}
|
19
|
+
|
20
|
+
@if type-of($needle) != "string" {
|
21
|
+
@warn "`str-count` function expecting a string for $needle; #{type-of($needle)} given.";
|
22
|
+
@return false;
|
23
|
+
}
|
24
|
+
|
25
|
+
@return _ss-str-count($string, $needle);
|
26
|
+
}
|
@@ -0,0 +1,26 @@
|
|
1
|
+
/*
|
2
|
+
* Check whether $string ends with $needle
|
3
|
+
* ---
|
4
|
+
* @access public
|
5
|
+
* ---
|
6
|
+
* @since 1.0.0
|
7
|
+
* ---
|
8
|
+
* @param {string} $string - string to check
|
9
|
+
* @param {string} $needle - substring to check
|
10
|
+
* ---
|
11
|
+
* @return {bool}
|
12
|
+
*/
|
13
|
+
|
14
|
+
@function str-ends-with($string, $needle) {
|
15
|
+
@if type-of($string) != "string" {
|
16
|
+
@warn "`str-starts-with` function expecting a string for $string; #{type-of($string)} given.";
|
17
|
+
@return false;
|
18
|
+
}
|
19
|
+
|
20
|
+
@if type-of($needle) != "string" {
|
21
|
+
@warn "`str-starts-with` function expecting a string for $needle; #{type-of($needle)} given.";
|
22
|
+
@return false;
|
23
|
+
}
|
24
|
+
|
25
|
+
@return _ss-str-ends-with($string, $needle);
|
26
|
+
}
|
@@ -0,0 +1,26 @@
|
|
1
|
+
/*
|
2
|
+
* Split $string into several parts using $delimiter
|
3
|
+
* ---
|
4
|
+
* @access public
|
5
|
+
* ---
|
6
|
+
* @since 1.0.0
|
7
|
+
* ---
|
8
|
+
* @param {string} $string - string to split
|
9
|
+
* @param {string} $delimiter - string to use as a delimiter to split $string
|
10
|
+
* ---
|
11
|
+
* @return {list|false}
|
12
|
+
*/
|
13
|
+
|
14
|
+
@function str-explode($string, $delimiter: '') {
|
15
|
+
@if type-of($string) != "string" {
|
16
|
+
@warn "`explode` function expecting a string; #{type-of($string)} given.";
|
17
|
+
@return false;
|
18
|
+
}
|
19
|
+
|
20
|
+
@if type-of($delimiter) != "string" {
|
21
|
+
@warn "`explode` function expecting a string; #{type-of($delimiter)} given.";
|
22
|
+
@return false;
|
23
|
+
}
|
24
|
+
|
25
|
+
@return _ss-str-explode($string, $delimiter);
|
26
|
+
}
|