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.
Files changed (65) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +1 -0
  3. data/README.md +5 -0
  4. data/lib/SassyStrings.rb +2 -2
  5. data/stylesheets/_SassyStrings.scss +2 -20
  6. data/stylesheets/private/_all.scss +24 -0
  7. data/stylesheets/private/_char-at.scss +16 -0
  8. data/stylesheets/private/_levenshtein.scss +105 -0
  9. data/stylesheets/private/_str-count.scss +27 -0
  10. data/stylesheets/private/_str-ends-with.scss +16 -0
  11. data/stylesheets/private/_str-explode.scss +41 -0
  12. data/stylesheets/private/_str-implode.scss +21 -0
  13. data/stylesheets/private/_str-last-index.scss +27 -0
  14. data/stylesheets/private/_str-lcfirst.scss +15 -0
  15. data/stylesheets/private/_str-pad.scss +36 -0
  16. data/stylesheets/private/_str-printf.scss +29 -0
  17. data/stylesheets/private/_str-repeat.scss +22 -0
  18. data/stylesheets/private/_str-replace.scss +33 -0
  19. data/stylesheets/private/_str-reverse.scss +21 -0
  20. data/stylesheets/private/_str-rot.scss +39 -0
  21. data/stylesheets/private/_str-shuffle.scss +36 -0
  22. data/stylesheets/private/_str-starts-with.scss +16 -0
  23. data/stylesheets/private/_str-trim.scss +31 -0
  24. data/stylesheets/private/_str-ucfirst.scss +15 -0
  25. data/stylesheets/{functions → private}/_str-word-count.scss +5 -6
  26. data/stylesheets/private/_stringify.scss +26 -0
  27. data/stylesheets/public/_all.scss +23 -0
  28. data/stylesheets/public/_char-at.scss +31 -0
  29. data/stylesheets/public/_levenshtein.scss +26 -0
  30. data/stylesheets/public/_str-count.scss +26 -0
  31. data/stylesheets/public/_str-ends-with.scss +26 -0
  32. data/stylesheets/public/_str-explode.scss +26 -0
  33. data/stylesheets/public/_str-implode.scss +19 -0
  34. data/stylesheets/{functions → public}/_str-last-index.scss +5 -12
  35. data/stylesheets/public/_str-lcfirst.scss +20 -0
  36. data/stylesheets/public/_str-pad.scss +33 -0
  37. data/stylesheets/public/_str-printf.scss +21 -0
  38. data/stylesheets/public/_str-repeat.scss +26 -0
  39. data/stylesheets/public/_str-replace.scss +39 -0
  40. data/stylesheets/public/_str-reverse.scss +20 -0
  41. data/stylesheets/public/_str-rot.scss +26 -0
  42. data/stylesheets/public/_str-shuffle.scss +18 -0
  43. data/stylesheets/public/_str-starts-with.scss +26 -0
  44. data/stylesheets/public/_str-trim.scss +20 -0
  45. data/stylesheets/{functions → public}/_str-ucfirst.scss +6 -2
  46. data/stylesheets/public/_str-word-count.scss +20 -0
  47. data/stylesheets/public/_stringify.scss +15 -0
  48. metadata +44 -22
  49. data/stylesheets/functions/_char-at.scss +0 -25
  50. data/stylesheets/functions/_levenshtein.scss +0 -99
  51. data/stylesheets/functions/_str-count.scss +0 -31
  52. data/stylesheets/functions/_str-ends-with.scss +0 -20
  53. data/stylesheets/functions/_str-explode.scss +0 -45
  54. data/stylesheets/functions/_str-implode.scss +0 -15
  55. data/stylesheets/functions/_str-lcfirst.scss +0 -14
  56. data/stylesheets/functions/_str-pad.scss +0 -45
  57. data/stylesheets/functions/_str-printf.scss +0 -28
  58. data/stylesheets/functions/_str-repeat.scss +0 -26
  59. data/stylesheets/functions/_str-replace.scss +0 -47
  60. data/stylesheets/functions/_str-reverse.scss +0 -20
  61. data/stylesheets/functions/_str-rot.scss +0 -43
  62. data/stylesheets/functions/_str-shuffle.scss +0 -26
  63. data/stylesheets/functions/_str-starts-with.scss +0 -20
  64. data/stylesheets/functions/_str-trim.scss +0 -30
  65. data/stylesheets/functions/_stringify.scss +0 -21
@@ -1,25 +0,0 @@
1
- // Return character from $string at $index
2
- // ----------------------------------------------------------------------------------------------------
3
- // @param [string] $string: string
4
- // @param [string] $index: index to inspect
5
- // ----------------------------------------------------------------------------------------------------
6
- // @return [string]
7
-
8
- @function char-at($string, $index) {
9
- @if type-of($string) != "string" {
10
- @warn "`char-at` function expecting a string for $string; #{type-of($string)} given.";
11
- @return false;
12
- }
13
-
14
- @if type-of($index) != "number" {
15
- @warn "`char-at` function expecting a number for $index; #{type-of($index)} given.";
16
- @return false;
17
- }
18
-
19
- @if $index < 1 or $index > str-length($string) {
20
- @warn "Out of bounds $index for `char-at`.";
21
- @return false;
22
- }
23
-
24
- @return str-slice($string, $index, $index);
25
- }
@@ -1,99 +0,0 @@
1
- // Calculating Levenshtein distance between two strings
2
- // ----------------------------------------------------------------------------------------------------
3
- // @param $a: first string
4
- // @param $b: second string
5
- // ----------------------------------------------------------------------------------------------------
6
- // @return [number]
7
-
8
- @function levenshtein($a, $b) {
9
- @if type-of($a) != "string" {
10
- @warn "`str-count` function expecting a string for $a; #{type-of($a)} given.";
11
- @return false;
12
- }
13
-
14
- @if type-of($b) != "string" {
15
- @warn "`str-count` function expecting a string for $b; #{type-of($b)} given.";
16
- @return false;
17
- }
18
-
19
- $a: to-lower-case($a);
20
- $b: to-lower-case($b);
21
-
22
- $n: str-length($a);
23
- $m: str-length($b);
24
-
25
- $matrix: _matrix($n + 1, $m + 1);
26
- $cost: _matrix($n, $m);
27
-
28
- @if $a == $b { @return 0; }
29
- @if $n == 0 { @return $m; }
30
- @if $m == 0 { @return $n; }
31
-
32
- @for $i from 0 through $n {
33
- @for $j from 0 through $m {
34
- $v: if($i == 0, $j, if($j == 0, $i, 0));
35
- @if $v != 0 {
36
- $matrix: _set-matrix($matrix, $i + 1, $j + 1, $v);
37
- }
38
- @if $i != 0 and $j != 0 {
39
- $v: if(str-slice($a, $i, $i) == str-slice($b, $j, $j), 0, 1);
40
- @if $v != 0 {
41
- $cost: _set-matrix($cost, $i, $j, $v);
42
- }
43
- }
44
- }
45
- }
46
-
47
- @for $i from 2 through length($matrix) {
48
- @for $j from 2 through length(nth($matrix, $i)) {
49
- $matrix: _set-matrix($matrix, $i, $j, min(_e($matrix, $i - 1, $j) + 1, _e($matrix, $i, $j - 1) + 1, _e($matrix, $i - 1, $j - 1) + _e($cost, $i - 1, $j - 1)));
50
- }
51
- }
52
-
53
- @return _e($matrix, length($matrix), length(nth($matrix, 1)));
54
- }
55
-
56
-
57
- // Helper to target an element in a matrix
58
- // ----------------------------------------------------------------------------------------------------
59
- // @param $m: matrix
60
- // @param $x: x coord
61
- // @param $y: y coord
62
- // ----------------------------------------------------------------------------------------------------
63
- // @return [literal]
64
-
65
- @function _e($m, $x, $y) {
66
- @return nth(nth($m, $x), $y);
67
- }
68
-
69
- // Helper instanciation a matrix of $x by $y
70
- // ----------------------------------------------------------------------------------------------------
71
- // @param $x: number of cols
72
- // @param $y: number of lines
73
- // ----------------------------------------------------------------------------------------------------
74
- // @return [list]
75
-
76
- @function _matrix($x, $y) {
77
- $matrix: ();
78
- @for $i from 1 through $x {
79
- $tmp: ();
80
- @for $y from 1 through $y {
81
- $tmp: append($tmp, 0)
82
- }
83
- $matrix: append($matrix, $tmp);
84
- }
85
- @return $matrix;
86
- }
87
-
88
- // Helper assigning $value at $matrix[$x, $y]
89
- // ----------------------------------------------------------------------------------------------------
90
- // @param $matrix: matrix to update
91
- // @param $x: x coord
92
- // @param $y: y coord
93
- // @param $value: value to assign at $matrix[$x, $y]
94
- // ----------------------------------------------------------------------------------------------------
95
- // @return [list]
96
-
97
- @function _set-matrix($matrix, $x, $y, $value) {
98
- @return set-nth($matrix, $x, set-nth(nth($matrix, $x), $y, $value));
99
- }
@@ -1,31 +0,0 @@
1
- // Count the number of occurrences of $needle in $string
2
- // ----------------------------------------------------------------------------------------------------
3
- // @param [string] $string: string
4
- // @param [string] $needle: substring to count in $string
5
- // ----------------------------------------------------------------------------------------------------
6
- // @return [number] | false
7
-
8
- @function str-count($string, $needle) {
9
- @if type-of($string) != "string" {
10
- @warn "`str-count` function expecting a string for $string; #{type-of($string)} given.";
11
- @return false;
12
- }
13
-
14
- @if type-of($needle) != "string" {
15
- @warn "`str-count` function expecting a string for $needle; #{type-of($needle)} given.";
16
- @return false;
17
- }
18
-
19
- $index: str-index($string, $needle);
20
- $result: if($index, 1, 0);
21
-
22
- @if $index {
23
- @for $i from $index + str-length($needle) through str-length($string) {
24
- @if str-slice($string, $i, $i + str-length($needle) - 1) == $needle {
25
- $result: $result + 1;
26
- }
27
- }
28
- }
29
-
30
- @return $result;
31
- }
@@ -1,20 +0,0 @@
1
- // Check whether $string ends with $needle
2
- // ----------------------------------------------------------------------------------------------------
3
- // @param [string] $string: string
4
- // @param [string] $needle: substring to check
5
- // ----------------------------------------------------------------------------------------------------
6
- // @return [bool]
7
-
8
- @function str-ends-with($string, $needle) {
9
- @if type-of($string) != "string" {
10
- @warn "`str-starts-with` function expecting a string for $string; #{type-of($string)} given.";
11
- @return false;
12
- }
13
-
14
- @if type-of($needle) != "string" {
15
- @warn "`str-starts-with` function expecting a string for $needle; #{type-of($needle)} given.";
16
- @return false;
17
- }
18
-
19
- @return str-slice($string, -1 * str-length($needle)) == $needle;
20
- }
@@ -1,45 +0,0 @@
1
- // Split $string into several parts using $delimiter
2
- // ----------------------------------------------------------------------------------------------------
3
- // @param [string] $string: string
4
- // @param [string] $delimiter: string to use as a delimiter to split $string
5
- // ----------------------------------------------------------------------------------------------------
6
- // @return [list] | false
7
-
8
- @function str-explode($string, $delimiter: '') {
9
- @if type-of($string) != "string" {
10
- @warn "`explode` function expecting a string; #{type-of($string)} given.";
11
- @return false;
12
- }
13
-
14
- @if type-of($delimiter) != "string" {
15
- @warn "`explode` function expecting a string; #{type-of($delimiter)} given.";
16
- @return false;
17
- }
18
-
19
- $result: ();
20
- $length: str-length($string);
21
-
22
- @if str-length($delimiter) == 0 {
23
- @for $i from 1 through $length {
24
- $result: append($result, str-slice($string, $i, $i));
25
- }
26
- @return $result;
27
- }
28
-
29
- $running: true;
30
- $remaining: $string;
31
-
32
- @while $running {
33
- $index: str-index($remaining, $delimiter);
34
- @if $index {
35
- $slice: str-slice($remaining, 1, $index - 1);
36
- $result: append($result, $slice);
37
- $remaining: str-slice($remaining, $index + str-length($delimiter));
38
- }
39
- @else {
40
- $running: false;
41
- }
42
- }
43
-
44
- @return append($result, $remaining);
45
- }
@@ -1,15 +0,0 @@
1
- // Implode $list into a string
2
- // ----------------------------------------------------------------------------------------------------
3
- // @param [list] $list: list to convert to string
4
- // ----------------------------------------------------------------------------------------------------
5
- // @return [string]
6
-
7
- @function str-implode($list) {
8
- $result: "";
9
-
10
- @each $item in $list {
11
- $result: $result + if(length($item) > 1, str-implode($item), $item);
12
- }
13
-
14
- @return $result;
15
- }
@@ -1,14 +0,0 @@
1
- // Lower case first character of $string
2
- // ----------------------------------------------------------------------------------------------------
3
- // @param [string] $string: string
4
- // ----------------------------------------------------------------------------------------------------
5
- // @return [string]
6
-
7
- @function str-lcfirst($string) {
8
- @if type-of($string) != "string" {
9
- @warn "`str-lcfirst` function expecting a string for $string; #{type-of($string)} given.";
10
- @return false;
11
- }
12
-
13
- @return to-lower-case(str-slice($string, 1, 1)) + str-slice($string, 2);
14
- }
@@ -1,45 +0,0 @@
1
- // Pad $string from $direction with $pad to reach $length characters
2
- // ----------------------------------------------------------------------------------------------------
3
- // @param [string] $string: string
4
- // @param [number] $length: number of characters to go for in returned string
5
- // @param [string] $pad: string to use to pad $string
6
- // @param [string] $direction: direction left or right for padding
7
- // ----------------------------------------------------------------------------------------------------
8
- // @return [string] | false
9
-
10
- @function str-pad($string, $length, $pad: " ", $direction: left) {
11
- @if type-of($string) != "string" {
12
- @warn "`str-pad` function expecting a string for $string; #{type-of($string)} given.";
13
- @return false;
14
- }
15
-
16
- @if type-of($pad) != "string" {
17
- @warn "`str-pad` function expecting a string for $pad; #{type-of($pad)} given.";
18
- @return false;
19
- }
20
-
21
- @if type-of($length) != "number" {
22
- @warn "`str-pad` function expecting a number for $length; #{type-of($length)} given.";
23
- @return false;
24
- }
25
-
26
- $direction: if(index(left right, $direction), $direction, left);
27
- $new-string: $string;
28
- $index: 1;
29
-
30
- @if $length > str-length($string) {
31
- @while str-length($new-string) < $length {
32
- $remains: $length - str-length($new-string);
33
- $pad: if($remains < str-length($pad), str-slice($pad, 1, $remains), $pad);
34
- @if $direction == left {
35
- $new-string: str-insert($new-string, $pad, $index);
36
- $index: $index + str-length($pad);
37
- }
38
- @else {
39
- $new-string: $new-string + $pad;
40
- }
41
- }
42
- }
43
-
44
- @return $new-string;
45
- }
@@ -1,28 +0,0 @@
1
- // Replace occurrences of %s in $string by $elements
2
- // ----------------------------------------------------------------------------------------------------
3
- // @param [string] $string: string
4
- // @param [arglist] $elements: strings to use for replacements in %s
5
- // ----------------------------------------------------------------------------------------------------
6
- // @return [string] | false
7
-
8
- @function str-printf($string, $elements...) {
9
- @if type-of($string) != "string" {
10
- @warn "`str-printf` function expecting a string for $string; #{type-of($string)} given.";
11
- @return false;
12
- }
13
-
14
- $breaker: '%s';
15
- $result: $string;
16
-
17
- @for $i from 1 through length($elements) {
18
- $index: str-index($result, $breaker);
19
- @if $index {
20
- $result: str-slice($result, 1, $index - 1) + stringify(nth($elements, $i)) + str-slice($result, $index + str-length($breaker));
21
- }
22
- @else {
23
- @return $result;
24
- }
25
- }
26
-
27
- @return $result;
28
- }
@@ -1,26 +0,0 @@
1
- // Repeat $string $times times
2
- // ----------------------------------------------------------------------------------------------------
3
- // @param [string] $string: string
4
- // @param [number] $times: number of times to repeat $string
5
- // ----------------------------------------------------------------------------------------------------
6
- // @return [string] | false
7
-
8
- @function str-repeat($string, $times) {
9
- @if type-of($string) != "string" {
10
- @warn "`str-repeat` function expecting a string for $string; #{type-of($string)} given.";
11
- @return false;
12
- }
13
-
14
- @if type-of($times) != "number" {
15
- @warn "`str-repeat` function expecting a number for $times; #{type-of($times)} given.";
16
- @return false;
17
- }
18
-
19
- $result: "";
20
-
21
- @for $i from 1 through $times {
22
- $result: $result + $string;
23
- }
24
-
25
- @return $result;
26
- }
@@ -1,47 +0,0 @@
1
- // Replace $old occurrences by $new in $string respecting $case-sensitive
2
- // ----------------------------------------------------------------------------------------------------
3
- // @param [string] $string: string
4
- // @param [string] $old: old substring to replace by $new
5
- // @param [string] $new: new substring to replace $old
6
- // @param [bool] $case-sensitive: case-sensitivity
7
- // ----------------------------------------------------------------------------------------------------
8
- // @return [string] | false
9
-
10
- @function str-replace($string, $old, $new: '', $case-sensitive: true) {
11
- @if type-of($string) != "string" {
12
- @warn "`str-replace` function expecting a string for $string; #{type-of($string)} given.";
13
- @return false;
14
- }
15
-
16
- @if type-of($old) != "string" {
17
- @warn "`str-replace` function expecting a string for $old; #{type-of($old)} given.";
18
- @return false;
19
- }
20
-
21
- @if type-of($new) != "string" {
22
- @warn "`str-replace` function expecting a string for $new; #{type-of($new)} given.";
23
- @return false;
24
- }
25
-
26
- @if str-index($new, $old) {
27
- @warn "The string to be replaced is contained in the new string. Infinite recursion avoided.";
28
- @return $string;
29
- }
30
-
31
- $index: if(not $case-sensitive, str-index(to-lower-case($string), to-lower-case($old)), str-index($string, $old));
32
-
33
- @if $index and $new != $old {
34
- $result: if($index != 1, quote(str-slice($string, 1, $index - 1)), '');
35
-
36
- @for $i from $index through str-length($string) {
37
- @if $i < $index or $i >= $index + str-length($old) {
38
- $result: $result + str-slice($string, $i, $i);
39
- }
40
- }
41
-
42
- @return quote(str-replace(str-insert($result, $new, $index), $old, $new, $case-sensitive));
43
- }
44
-
45
- @return $string;
46
- }
47
-
@@ -1,20 +0,0 @@
1
- // Reverse $string
2
- // ----------------------------------------------------------------------------------------------------
3
- // @param [string] $string: string
4
- // ----------------------------------------------------------------------------------------------------
5
- // @return [string] | false
6
-
7
- @function str-reverse($string) {
8
- @if type-of($string) != "string" {
9
- @warn "`str-reverse` function expecting a string for $string; #{type-of($string)} given.";
10
- @return false;
11
- }
12
-
13
- $result: "";
14
-
15
- @for $i from str-length($string) * -1 through -1 {
16
- $result: $result + str-slice($string, abs($i), abs($i));
17
- }
18
-
19
- @return $result;
20
- }
@@ -1,43 +0,0 @@
1
- // Rotate all characters from the alphabet in $string by $rot positions
2
- // ----------------------------------------------------------------------------------------------------
3
- // @param [string] $string: string
4
- // @param [number] $rot: number of positions to switch in alphabet
5
- // ----------------------------------------------------------------------------------------------------
6
- // @return [string] | false
7
-
8
- @function str-rot($string, $rot: 13) {
9
- @if type-of($string) != "string" {
10
- @warn "`str-rot` function expecting a string for $string; #{type-of($string)} given.";
11
- @return false;
12
- }
13
-
14
- @if type-of($rot) != "number" {
15
- @warn "`str-rot` function expecting a number for $rot; #{type-of($rot)} given.";
16
- @return false;
17
- }
18
-
19
- $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;
20
- $result: "";
21
- $rot: if(type-of($rot) == "number", floor($rot), 13);
22
-
23
- @for $i from 1 through str-length($string) {
24
- $char: str-slice($string, $i, $i);
25
- $index: index($alphabet, to-lower-case($char));
26
- $is-caps: $index and (index($alphabet, to-lower-case($char)) != index($alphabet, $char));
27
- $new-char: if($index,
28
- if($index + $rot > length($alphabet),
29
- nth($alphabet, $index + $rot - length($alphabet)),
30
- nth($alphabet, $index + $rot)
31
- ),
32
- $char
33
- );
34
-
35
- @if $is-caps {
36
- $new-char: to-upper-case($new-char);
37
- }
38
-
39
- $result: $result + $new-char;
40
- }
41
-
42
- @return $result;
43
- }