@omnisass/library 0.2.0 → 2026.1.0-alpha.1

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 (101) hide show
  1. package/.editorconfig +13 -0
  2. package/.omnisass/scripts/bump-version.sh +288 -0
  3. package/.sassdoc.yaml +21 -0
  4. package/.vscode/settings.json +17 -0
  5. package/_configs.scss +10 -45
  6. package/index.scss +5 -91
  7. package/modules/utilities/converters/_convert-em2px.scss +3 -49
  8. package/modules/utilities/converters/_convert-hex2rgb.scss +2 -44
  9. package/modules/utilities/converters/_convert-hex2rgba.scss +2 -57
  10. package/modules/utilities/converters/_convert-px2em.scss +3 -62
  11. package/modules/utilities/converters/_convert-px2rem.scss +3 -62
  12. package/modules/utilities/converters/_convert-rem2px.scss +3 -62
  13. package/modules/utilities/converters/_index.scss +10 -0
  14. package/modules/utilities/getters/_index.scss +23 -0
  15. package/modules/utilities/getters/color/_get-color-brightness.scss +2 -48
  16. package/modules/utilities/getters/color/_get-color-darkest.scss +13 -68
  17. package/modules/utilities/getters/list/_get-list-item-end.scss +2 -29
  18. package/modules/utilities/getters/list/_get-list-item-start.scss +2 -29
  19. package/modules/utilities/getters/list/_get-list-item.scss +6 -82
  20. package/modules/utilities/getters/number/_get-number-from-percent.scss +2 -40
  21. package/modules/utilities/getters/number/_get-number-height-by-ratio.scss +3 -35
  22. package/modules/utilities/getters/number/_get-number-max-safe.scss +112 -0
  23. package/modules/utilities/getters/number/_get-number-max.scss +10 -88
  24. package/modules/utilities/getters/number/_get-number-min-safe.scss +114 -0
  25. package/modules/utilities/getters/number/_get-number-min.scss +9 -84
  26. package/modules/utilities/getters/number/_get-number-percentage-of.scss +2 -58
  27. package/modules/utilities/getters/number/_get-number-unit.scss +5 -46
  28. package/modules/utilities/getters/number/_get-number-width-by-ratio.scss +3 -56
  29. package/modules/utilities/helpers/_index.scss +44 -0
  30. package/modules/utilities/helpers/color/_color-blend-steps.scss +5 -89
  31. package/modules/utilities/helpers/color/_color-blend.scss +11 -85
  32. package/modules/utilities/helpers/color/_color-hue-shift.scss +7 -61
  33. package/modules/utilities/helpers/color/_color-scale.scss +7 -74
  34. package/modules/utilities/helpers/color/_color-shade.scss +2 -60
  35. package/modules/utilities/helpers/color/_color-tint.scss +2 -60
  36. package/modules/utilities/helpers/color/_color-triad.scss +9 -53
  37. package/modules/utilities/helpers/list/_list-dedupe.scss +9 -50
  38. package/modules/utilities/helpers/list/_list-insert-at.scss +16 -86
  39. package/modules/utilities/helpers/list/_list-merge.scss +1 -1
  40. package/modules/utilities/helpers/list/_list-remove-at.scss +9 -71
  41. package/modules/utilities/helpers/list/_list-sum-numbers-safe.scss +17 -81
  42. package/modules/utilities/helpers/list/_list-sum-numbers.scss +9 -57
  43. package/modules/utilities/helpers/number/_number-ceil-to.scss +1 -1
  44. package/modules/utilities/helpers/number/_number-clamp-max.scss +1 -1
  45. package/modules/utilities/helpers/number/_number-clamp-min.scss +1 -1
  46. package/modules/utilities/helpers/number/_number-clamp.scss +1 -1
  47. package/modules/utilities/helpers/number/_number-denormalize.scss +1 -1
  48. package/modules/utilities/helpers/number/_number-fibonacci.scss +2 -2
  49. package/modules/utilities/helpers/number/_number-floor-to.scss +1 -1
  50. package/modules/utilities/helpers/number/_number-format-with-separator.scss +4 -4
  51. package/modules/utilities/helpers/number/_number-normalize.scss +1 -1
  52. package/modules/utilities/helpers/number/_number-random-between-int.scss +1 -1
  53. package/modules/utilities/helpers/number/_number-random-between.scss +1 -1
  54. package/modules/utilities/helpers/number/_number-range.scss +7 -7
  55. package/modules/utilities/helpers/number/_number-round-to-nearest.scss +1 -1
  56. package/modules/utilities/helpers/number/_number-round-to.scss +1 -1
  57. package/modules/utilities/helpers/number/_number-strip-unit.scss +2 -14
  58. package/modules/utilities/helpers/string/_string-capitalize.scss +1 -1
  59. package/modules/utilities/helpers/string/_string-replace.scss +1 -1
  60. package/modules/utilities/helpers/string/_string-trim-end.scss +2 -2
  61. package/modules/utilities/helpers/string/_string-trim-start.scss +2 -2
  62. package/modules/utilities/helpers/string/_string-trim.scss +1 -1
  63. package/modules/utilities/loggers/_index.scss +6 -0
  64. package/modules/utilities/validators/_index.scss +38 -0
  65. package/modules/utilities/validators/{misc/_is-time.scss → _is-time.scss} +2 -2
  66. package/modules/utilities/validators/color/_is-color-light.scss +1 -1
  67. package/modules/utilities/validators/color/_is-color-list.scss +1 -1
  68. package/modules/utilities/validators/list/_is-list-contained.scss +1 -1
  69. package/modules/utilities/validators/number/_is-int-even.scss +1 -1
  70. package/modules/utilities/validators/number/_is-int-odd.scss +1 -1
  71. package/modules/utilities/validators/number/_is-int.scss +1 -1
  72. package/modules/utilities/validators/number/_is-number-has-unit.scss +1 -1
  73. package/modules/utilities/validators/number/_is-number-negative.scss +1 -1
  74. package/modules/utilities/validators/number/_is-number-positive.scss +1 -1
  75. package/modules/utilities/validators/number/_is-number-unitless.scss +1 -1
  76. package/modules/utilities/validators/number/_is-number-zero.scss +1 -1
  77. package/modules/utilities/validators/string/_is-string-contained.scss +25 -25
  78. package/modules/utilities/validators/string/_is-string-empty.scss +1 -1
  79. package/modules/utilities/validators/string/_is-string-ending-with.scss +1 -1
  80. package/modules/utilities/validators/string/_is-string-starting-with.scss +1 -1
  81. package/modules/utilities/validators/type-of/_is-boolean.scss +1 -1
  82. package/modules/utilities/validators/type-of/_is-color.scss +1 -1
  83. package/modules/utilities/validators/type-of/_is-list.scss +1 -1
  84. package/modules/utilities/validators/type-of/_is-map.scss +1 -1
  85. package/modules/utilities/validators/type-of/_is-number.scss +1 -1
  86. package/modules/utilities/validators/type-of/_is-string.scss +1 -1
  87. package/modules/utilities/validators/type-of/_is-type.scss +1 -1
  88. package/package.json +5 -6
  89. package/package.scss +3 -3
  90. package/playground/index.scss +8 -0
  91. package/modules/utilities/converters/_convert-camel2kebab.scss +0 -186
  92. package/modules/utilities/converters/_convert-kebab2camel.scss +0 -232
  93. package/modules/utilities/converters/_convert-kebab2snake.scss +0 -118
  94. package/modules/utilities/converters/_convert-snake2kebab.scss +0 -173
  95. package/modules/utilities/helpers/misc/_url-encode.configs.scss +0 -64
  96. package/modules/utilities/helpers/misc/_url-encode.scss +0 -148
  97. package/modules/utilities/loggers/_log-invalid-type.scss +0 -151
  98. package/modules/utilities/loggers/_log-invalid-value.scss +0 -151
  99. package/test.md +0 -168
  100. package/test.scss +0 -405
  101. package/test.sh +0 -149
@@ -13,7 +13,7 @@
13
13
  /// ---
14
14
  /// @name is-time
15
15
  /// @group utilities-validators
16
- /// @since 2025.12.27
16
+ /// @since 0.0.1
17
17
  /// @access public
18
18
  /// @author Halil İbrahim Çakıroğlu
19
19
  /// @author Murad Rustamov (therteenten) [адаптация]
@@ -105,7 +105,7 @@
105
105
  /// @return {Boolean} - Возвращает `true`, если значение является
106
106
  /// корректным временным значением, иначе возвращает `false`.
107
107
  @function is-time($value) {
108
- @for $i from 1 through list.length($value) {
108
+ @for $-i from 1 through list.length($value) {
109
109
  @if (meta.type-of($value) == 'number' and list.index('ms' 's' 'h', math.unit($value)) != null) or $value == 0 {
110
110
  @return true;
111
111
  } @else {
@@ -12,7 +12,7 @@
12
12
  /// ---
13
13
  /// @name is-color-light
14
14
  /// @group utilities-validators
15
- /// @since 2026.01.03
15
+ /// @since 0.0.1
16
16
  /// @access public
17
17
  /// @author Murad Rustamov (therteenten)
18
18
  /// @link https://sourcecraft.dev/users/therteenten/overview SourceCraft - therteenten
@@ -20,7 +20,7 @@
20
20
  /// ---
21
21
  /// @name is-color-list
22
22
  /// @group utilities-validators
23
- /// @since 2026.01.03
23
+ /// @since 0.0.1
24
24
  /// @access public
25
25
  /// @author Murad Rustamov (therteenten)
26
26
  /// @link https://sourcecraft.dev/users/therteenten/overview SourceCraft - therteenten
@@ -18,7 +18,7 @@
18
18
  /// ---
19
19
  /// @name is-list-contained
20
20
  /// @group utilities-validators
21
- /// @since 2026.01.03
21
+ /// @since 0.0.1
22
22
  /// @access public
23
23
  /// @author Murad Rustamov (therteenten) [адаптация]
24
24
  /// @author Неизвестный автор [идея не моя, но автора исходной функции не помню уже]
@@ -19,7 +19,7 @@
19
19
  /// ---
20
20
  /// @name is-int-even
21
21
  /// @group utilities-validators
22
- /// @since 2026.01.03
22
+ /// @since 0.0.1
23
23
  /// @access public
24
24
  /// @author Murad Rustamov (therteenten)
25
25
  /// @link https://sourcecraft.dev/users/therteenten/overview SourceCraft - therteenten
@@ -20,7 +20,7 @@
20
20
  /// ---
21
21
  /// @name is-int-odd
22
22
  /// @group utilities-validators
23
- /// @since 2026.01.03
23
+ /// @since 0.0.1
24
24
  /// @access public
25
25
  /// @author Murad Rustamov (therteenten)
26
26
  /// @link https://sourcecraft.dev/users/therteenten/overview SourceCraft - therteenten
@@ -23,7 +23,7 @@
23
23
  /// ---
24
24
  /// @name is-int
25
25
  /// @group utilities-validators
26
- /// @since 2026.01.03
26
+ /// @since 0.0.1
27
27
  /// @access public
28
28
  /// @author Zsolt Pentz
29
29
  /// @author Murad Rustamov (therteenten) [адаптация]
@@ -26,7 +26,7 @@
26
26
  /// ---
27
27
  /// @name is-number-has-unit
28
28
  /// @group utilities-validators
29
- /// @since 2026.01.03
29
+ /// @since 0.0.1
30
30
  /// @access public
31
31
  /// @author Murad Rustamov (therteenten)
32
32
  /// @link https://sourcecraft.dev/users/therteenten/overview SourceCraft - therteenten
@@ -20,7 +20,7 @@
20
20
  /// ---
21
21
  /// @name is-number-negative
22
22
  /// @group utilities-validators
23
- /// @since 2026.01.03
23
+ /// @since 0.0.1
24
24
  /// @access public
25
25
  /// @author Murad Rustamov (therteenten)
26
26
  /// @link https://sourcecraft.dev/users/therteenten/overview SourceCraft - therteenten
@@ -19,7 +19,7 @@
19
19
  /// ---
20
20
  /// @name is-number-positive
21
21
  /// @group utilities-validators
22
- /// @since 2026.01.03
22
+ /// @since 0.0.1
23
23
  /// @access public
24
24
  /// @author Murad Rustamov (therteenten)
25
25
  /// @link https://sourcecraft.dev/users/therteenten/overview SourceCraft - therteenten
@@ -22,7 +22,7 @@
22
22
  /// ---
23
23
  /// @name is-number-unitless
24
24
  /// @group utilities-validators
25
- /// @since 2026.01.03
25
+ /// @since 0.0.1
26
26
  /// @access public
27
27
  /// @author Murad Rustamov (therteenten)
28
28
  /// @link https://sourcecraft.dev/users/therteenten/overview SourceCraft - therteenten
@@ -20,7 +20,7 @@
20
20
  /// ---
21
21
  /// @name is-number-zero
22
22
  /// @group utilities-validators
23
- /// @since 2026.01.03
23
+ /// @since 0.0.1
24
24
  /// @access public
25
25
  /// @author Murad Rustamov (therteenten)
26
26
  /// @link https://sourcecraft.dev/users/therteenten/overview SourceCraft - therteenten
@@ -45,7 +45,7 @@
45
45
  /// ---
46
46
  /// @name is-string-contained
47
47
  /// @group utilities-validators
48
- /// @since 2026.01.03
48
+ /// @since 0.0.1
49
49
  /// @access public
50
50
  /// @author Murad Rustamov (therteenten)
51
51
  /// @link https://sourcecraft.dev/users/therteenten/overview SourceCraft - therteenten
@@ -61,35 +61,35 @@
61
61
  /// @link https://webdevblog.ru/sass-strokovye-funkcii/ См. также: WebDevBlog - Строковые функции в Sass
62
62
  /// @link https://stackoverflow.com/questions/32376461/how-to-check-if-a-string-contains-a-substring-in-sass Stack Overflow - Как проверить наличие подстроки в строке в Sass
63
63
  /// @example scss - Базовая проверка наличия подстроки
64
- /// @debug is-string-contained("Hello, world!", "world"); // true
65
- /// @debug is-string-contained("Hello, world!", "planet"); // false
66
- /// @debug is-string-contained("Hello, world!", "hello"); // false (регистрозависимо)
67
- /// @debug is-string-contained("Hello, world!", "WORLD"); // false (регистрозависимо)
64
+ /// @debug is-string-contained("Hello, world!", "world"); // true
65
+ /// @debug is-string-contained("Hello, world!", "planet"); // false
66
+ /// @debug is-string-contained("Hello, world!", "hello"); // false (регистрозависимо)
67
+ /// @debug is-string-contained("Hello, world!", "WORLD"); // false (регистрозависимо)
68
68
  /// @example scss - Проверка с учетом регистра (рекомендуемый подход)
69
- /// @debug is-string-contained(string.to-lower-case("Hello, world!"), "world"); // true
70
- /// @debug is-string-contained(string.to-lower-case("Hello, world!"), "WORLD"); // false
71
- /// // Для регистронезависимой проверки:
72
- /// @function contains-ignore-case($string, $substring) {
73
- /// @return is-string-contained(
74
- /// string.to-lower-case($string),
75
- /// string.to-lower-case($substring)
76
- /// );
77
- /// }
69
+ /// @debug is-string-contained(string.to-lower-case("Hello, world!"), "world"); // true
70
+ /// @debug is-string-contained(string.to-lower-case("Hello, world!"), "WORLD"); // false
71
+ /// // Для регистронезависимой проверки:
72
+ /// @function contains-ignore-case($string, $substring) {
73
+ /// @return is-string-contained(
74
+ /// string.to-lower-case($string),
75
+ /// string.to-lower-case($substring)
76
+ /// );
77
+ /// }
78
78
  /// @example scss - Проверка с пустыми строками
79
- /// @debug is-string-contained("Hello", ""); // true
80
- /// @debug is-string-contained("", "Hello"); // false
81
- /// @debug is-string-contained("", ""); // true
79
+ /// @debug is-string-contained("Hello", ""); // true
80
+ /// @debug is-string-contained("", "Hello"); // false
81
+ /// @debug is-string-contained("", ""); // true
82
82
  /// @example scss - Использование с генерацией классов
83
- /// $button-variants: "primary", "secondary", "danger";
84
- /// @each $variant in $button-variants {
85
- /// .button--#{$variant} {
86
- /// @if is-string-contained($variant, "danger") {
87
- /// background-color: red;
88
- /// } @else {
89
- /// background-color: blue;
90
- /// }
83
+ /// $button-variants: "primary", "secondary", "danger";
84
+ /// @each $variant in $button-variants {
85
+ /// .button--#{$variant} {
86
+ /// @if is-string-contained($variant, "danger") {
87
+ /// background-color: red;
88
+ /// } @else {
89
+ /// background-color: blue;
91
90
  /// }
92
91
  /// }
92
+ /// }
93
93
  /// @param {String} $string - Строка, в которой выполняется
94
94
  /// поиск. Может быть любой строкой, включая пустую строку.
95
95
  /// Значение приводится к строковому типу, если это необходимо.
@@ -16,7 +16,7 @@
16
16
  /// ---
17
17
  /// @name is-string-empty
18
18
  /// @group utilities-validators
19
- /// @since 2026.01.03
19
+ /// @since 0.0.1
20
20
  /// @access public
21
21
  /// @author Murad Rustamov (therteenten)
22
22
  /// @link https://sourcecraft.dev/users/therteenten/overview SourceCraft - therteenten
@@ -17,7 +17,7 @@
17
17
  /// ---
18
18
  /// @name is-string-ending-with
19
19
  /// @group utilities-validators
20
- /// @since 2026.01.03
20
+ /// @since 0.0.1
21
21
  /// @access public
22
22
  /// @author Murad Rustamov (therteenten)
23
23
  /// @link https://sourcecraft.dev/users/therteenten/overview SourceCraft - therteenten
@@ -17,7 +17,7 @@
17
17
  /// ---
18
18
  /// @name is-string-starting-with
19
19
  /// @group utilities-validators
20
- /// @since 2026.01.03
20
+ /// @since 0.0.1
21
21
  /// @access public
22
22
  /// @author Murad Rustamov (therteenten)
23
23
  /// @link https://sourcecraft.dev/users/therteenten/overview SourceCraft - therteenten
@@ -12,7 +12,7 @@
12
12
  /// ---
13
13
  /// @name is-boolean
14
14
  /// @group utilities-validators
15
- /// @since 2025.12.27
15
+ /// @since 0.0.1
16
16
  /// @access public
17
17
  /// @author takamoso
18
18
  /// @author Murad Rustamov (therteenten) [адаптация]
@@ -21,7 +21,7 @@
21
21
  /// ---
22
22
  /// @name is-color
23
23
  /// @group utilities-validators
24
- /// @since 2025.12.27
24
+ /// @since 0.0.1
25
25
  /// @access public
26
26
  /// @author Murad Rustamov (therteenten)
27
27
  /// @link https://sourcecraft.dev/users/therteenten/overview SourceCraft - therteenten
@@ -13,7 +13,7 @@
13
13
  /// ---
14
14
  /// @name is-list
15
15
  /// @group utilities-validators
16
- /// @since 2025.12.27
16
+ /// @since 0.0.1
17
17
  /// @access public
18
18
  /// @author takamoso
19
19
  /// @author Murad Rustamov (therteenten) [адаптация]
@@ -11,7 +11,7 @@
11
11
  /// ---
12
12
  /// @name is-map
13
13
  /// @group utilities-validators
14
- /// @since 2025.12.27
14
+ /// @since 0.0.1
15
15
  /// @access public
16
16
  /// @author takamoso
17
17
  /// @author Murad Rustamov (therteenten) [адаптация]
@@ -8,7 +8,7 @@
8
8
  /// ---
9
9
  /// @name is-number
10
10
  /// @group utilities-validators
11
- /// @since 2025.12.27
11
+ /// @since 0.0.1
12
12
  /// @access public
13
13
  /// @author Murad Rustamov (therteenten)
14
14
  /// @link https://sourcecraft.dev/users/therteenten/overview SourceCraft - therteenten
@@ -11,7 +11,7 @@
11
11
  /// ---
12
12
  /// @name is-string
13
13
  /// @group utilities-validators
14
- /// @since 2025.12.27
14
+ /// @since 0.0.1
15
15
  /// @access public
16
16
  /// @author takamoso
17
17
  /// @author Murad Rustamov (therteenten) [адаптация]
@@ -17,7 +17,7 @@
17
17
  /// ---
18
18
  /// @name is-type
19
19
  /// @group utilities-validators
20
- /// @since 2025.12.27
20
+ /// @since 0.0.1
21
21
  /// @access public
22
22
  /// @author Murad Rustamov (therteenten)
23
23
  /// @link https://sourcecraft.dev/users/therteenten/overview SourceCraft - therteenten
package/package.json CHANGED
@@ -1,8 +1,9 @@
1
1
  {
2
2
  "name": "@omnisass/library",
3
- "version": "0.2.0",
3
+ "version": "2026.01.0-alpha.1",
4
4
  "description": "Библиотека функций и миксинов, написанная на языке CSS-препроцессора Sass. Она предназначена для того, чтобы упростить, ускорить и улучшить процесс создания стилей для веб-сайтов.",
5
5
  "main": "index.scss",
6
+
6
7
  "scripts": {
7
8
  "test": "sass playground/:playground/",
8
9
  "test-with-docs": "sass playground/:playground/ && npm run sassdoc",
@@ -12,8 +13,8 @@
12
13
  },
13
14
  "exports": {
14
15
  ".": {
15
- "sass": "./index.scss"
16
- }
16
+ "sass": "./index.scss"
17
+ }
17
18
  },
18
19
  "keywords": [
19
20
  "sass",
@@ -46,9 +47,7 @@
46
47
  },
47
48
  "homepage": "https://sourcecraft.dev/therteenten",
48
49
  "devDependencies": {
50
+ "sass": "^1.94.2",
49
51
  "sassdoc": "^2.7.4"
50
- },
51
- "dependencies": {
52
- "sass": "^1.97.2"
53
52
  }
54
53
  }
package/package.scss CHANGED
@@ -1,5 +1,5 @@
1
1
  @use 'sass:map';
2
- @use './configs' as libconfigs;
2
+ @use './configs' as libconf;
3
3
 
4
4
  ////
5
5
  /// В данном файле представлены переменные, описывающие
@@ -53,7 +53,7 @@ $description: "Набор утилит, миксинов, расширений
53
53
  /// @name version
54
54
  /// @access private
55
55
  /// @type String | Number
56
- $version: "0.2.0";
56
+ $version: "2026.01.0-alpha.1";
57
57
 
58
58
  /// Тип лицензии библиотеки - используется для указания
59
59
  /// условий использования и распространения.
@@ -130,7 +130,7 @@ $author: (
130
130
  $-author-name: map.get($author, name);
131
131
  $-author-email: map.get($author, email);
132
132
 
133
- @if libconfigs.$set-fingerprint == true {
133
+ @if libconf.$set-fingerprint == true {
134
134
 
135
135
  /*
136
136
  * @package:
@@ -0,0 +1,8 @@
1
+ @use 'sass:math';
2
+ @use 'sass:list';
3
+ @use 'sass:meta';
4
+ @use 'sass:map';
5
+ @use 'sass:color';
6
+ @use 'sass:string';
7
+ @use '../index.scss' as *;
8
+
@@ -1,186 +0,0 @@
1
- @use 'sass:string';
2
- @use '../loggers/log-invalid-type' as *;
3
- @use '../validators/type-of/is-string' as *;
4
-
5
- /// Конвертирует строку из `camelCase` (верблюжья нотация) в
6
- /// `kebab-case` (кебаб-нотация или дефисная нотация).
7
- ///
8
- /// Функция проходит по каждому символу входной строки и
9
- /// преобразует заглавные буквы в строчные с добавлением дефиса
10
- /// перед ними (кроме первого символа). Это позволяет
11
- /// преобразовывать имена переменных JavaScript/TypeScript или
12
- /// названия классов в формате, совместимом с CSS-нотацией.
13
- ///
14
- /// Важные особенности функции:
15
- /// - Сохраняет регистр исходных символов (преобразует к нижнему)
16
- /// - Добавляет дефис перед заглавными буквами (кроме первой)
17
- /// - Итеративно обрабатывает каждый символ строки
18
- /// - Возвращает строку в нижнем регистре с дефисами
19
- /// - Полезно для генерации CSS-классов из JS-объектов
20
- /// - Используется для консистентного именования стилей
21
- /// - Обрабатывает строки любой длины
22
- /// - Не изменяет цифры и специальные символы в строке
23
- /// - Учитывает граничные случаи (пустая строка, одиночный символ)
24
- /// - Обеспечивает двустороннюю совместимость naming convention
25
- /// ---
26
- /// @name convert-camel2kebab
27
- /// @group utilities-converters
28
- /// @since 2026.01.13
29
- /// @access public
30
- /// @author Murad Rustamov (therteenten)
31
- /// @link https://sourcecraft.dev/users/therteenten/overview SourceCraft - therteenten
32
- /// @link https://sourcecraft.dev/omnisass/library SourceCraft - OmniSass
33
- /// @link https://sass-lang.com/documentation/modules/string См. также: Официальная документация Sass - Модуль String
34
- /// @link https://sass-lang.com/documentation/values/strings См. также: Официальная документация Sass - Тип данных "Строки"
35
- /// @link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Object_initializer См. также: MDN Web Docs - Object initializer
36
- /// @link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Grammar_and_types#variable_names См. также: MDN Web Docs - Имена переменных в JavaScript
37
- /// @link https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_nesting/Using_CSS_nesting См. также: MDN Web Docs - Использование CSS Nesting
38
- /// @link https://developer.mozilla.org/en-US/docs/Learn/Getting_started_with_the_web/JavaScript_basics См. также: MDN Web Docs - Основы JavaScript
39
- /// @link https://css-tricks.com/snippets/sass/string-case-conversion-functions/ См. также: CSS-Tricks - Функции преобразования регистра строк в Sass
40
- /// @link https://css-tricks.com/sass-techniques-from-the-trenches/ См. также: CSS-Tricks - Sass техники из практики
41
- /// @link https://sass-guidelin.es/ru/#section-42 См. также: Sass Guidelines - Раздел про строки
42
- /// @link https://www.w3schools.com/js/js_conventions.asp См. также: W3Schools - Соглашения по коду JavaScript
43
- /// @example scss - Базовые преобразования
44
- /// @debug convert-camel2kebab('camelCase'); // 'camel-case'
45
- /// @debug convert-camel2kebab('backgroundColor'); // 'background-color'
46
- /// @debug convert-camel2kebab('fontSize'); // 'font-size'
47
- /// @debug convert-camel2kebab('borderRadius'); // 'border-radius'
48
- /// @debug convert-camel2kebab('paddingLeft'); // 'padding-left'
49
- /// @debug convert-camel2kebab('marginBottom'); // 'margin-bottom'
50
- /// @example scss - Граничные случаи
51
- /// @debug convert-camel2kebab('single'); // 'single'
52
- /// @debug convert-camel2kebab(''); // '' (пустая строка)
53
- /// @debug convert-camel2kebab('A'); // 'a'
54
- /// @debug convert-camel2kebab('AB'); // 'a-b'
55
- /// @debug convert-camel2kebab('AlreadyKebab'); // 'already-kebab'
56
- /// @debug convert-camel2kebab('lowercase'); // 'lowercase'
57
- /// @example scss - Компоненты и классы
58
- /// @debug convert-camel2kebab('ButtonPrimary'); // 'button-primary'
59
- /// @debug convert-camel2kebab('ModalHeader'); // 'modal-header'
60
- /// @debug convert-camel2kebab('CardContent'); // 'card-content'
61
- /// @debug convert-camel2kebab('InputGroup'); // 'input-group'
62
- /// @debug convert-camel2kebab('NavBar'); // 'nav-bar'
63
- /// @debug convert-camel2kebab('SideMenu'); // 'side-menu'
64
- /// @example scss - Интеграция с JavaScript объектами
65
- /// // Преобразование ключей объекта JS в CSS-классы
66
- /// $js-config: (
67
- /// primaryColor: 'blue',
68
- /// secondaryColor: 'gray',
69
- /// fontSizeSmall: 12px,
70
- /// borderRadiusLarge: 8px
71
- /// );
72
- ///
73
- /// @each $key, $value in $js-config {
74
- /// .#{convert-camel2kebab($key)} {
75
- /// content: $value;
76
- /// }
77
- /// }
78
- /// @example css - Результат
79
- /// .primary-color {
80
- /// content: "blue";
81
- /// }
82
- ///
83
- /// .secondary-color {
84
- /// content: "gray";
85
- /// }
86
- ///
87
- /// .font-size-small {
88
- /// content: 12px;
89
- /// }
90
- ///
91
- /// .border-radius-large {
92
- /// content: 8px;
93
- /// }
94
- /// @param {String} $value - Строка в `camelCase` нотации для
95
- /// конвертации. Может содержать буквы (верхний и нижний
96
- /// регистр), цифры и специальные символы. Функция
97
- /// преобразует заглавные буквы в строчные и добавляет
98
- /// дефисы перед ними.
99
- /// @return {String} - Строка в kebab-case нотации, где все
100
- /// символы преобразованы к нижнему регистру, а перед
101
- /// заглавными буквами (кроме первой) добавлены дефисы.
102
- /// Результат готов к использованию как CSS-класс или
103
- /// часть селектора.
104
- /// @throws {Error} - Может выбросить ошибку при передаче
105
- /// нестроковых значений. Аргумент должен быть строкой
106
- /// для корректной работы строковых функций Sass.
107
- @function convert-camel2kebab($value) {
108
-
109
- // Переменная для накопления результата преобразования.
110
- // Инициализируется пустой строкой.
111
- $-result: '';
112
-
113
- // Проверка типа входного параметра: ожидается строковое значение.
114
- // Функция is-string() проверяет, является ли $value строкой
115
- // (тип данных string).
116
- @if not is-string($value) {
117
-
118
- // Если $value не является строкой, возвращаем ошибку через
119
- // стандартную функцию логирования. Это предотвращает
120
- // выполнение операции преобразования с некорректными данными.
121
- @return log-invalid-type(
122
- 'convert-camel2kebab',
123
- $value,
124
- '$value',
125
- 'string'
126
- );
127
-
128
- }
129
-
130
- // Основная логика выполняется только если $value является
131
- // корректной строкой.
132
- @else {
133
-
134
- // Определение длины входной строки для организации цикла.
135
- // Функция string.length() возвращает количество символов
136
- // в строке.
137
- $-length: string.length($value);
138
-
139
- // Цикл по всем символам строки от первого до последнего.
140
- // Индекс $i последовательно принимает значения от 1 до $-length.
141
- @for $i from 1 through $-length {
142
-
143
- // Извлечение текущего символа строки по индексу $i.
144
- // Функция string.slice() возвращает подстроку,
145
- // в данном случае - один символ.
146
- $-char: string.slice($value, $i, $i);
147
-
148
- // Проверка: является ли текущий символ заглавной буквой
149
- // и не является ли он первым символом в строке.
150
- // Условие $-char == string.to-upper-case($-char) проверяет,
151
- // что символ в верхнем регистре (сравнивая его с его же
152
- // версией в верхнем регистре).
153
- // Условие $i > 1 гарантирует, что мы не добавляем дефис
154
- // перед первым символом (даже если он заглавный).
155
- @if $-char == string.to-upper-case($-char) and $i > 1 {
156
-
157
- // Если символ - заглавная буква и не первый в строке:
158
- // 1. Добавляем дефис "-" к результату
159
- // 2. Добавляем символ, преобразованный в нижний регистр
160
- //
161
- // Это преобразует camelCase в kebab-case:
162
- // Пример: "camelCase" → "camel-case"
163
- // "C" (на позиции 6) → "-c"
164
- $-result: $-result + '-' + string.to-lower-case($-char);
165
-
166
- } @else {
167
-
168
- // Если символ не является заглавной буквой ИЛИ
169
- // это первый символ в строке:
170
- // Добавляем символ, преобразованный в нижний регистр.
171
- //
172
- // Это гарантирует, что вся строка будет в нижнем регистре
173
- // и первый символ никогда не получит дефис перед собой.
174
- $-result: $-result + string.to-lower-case($-char);
175
-
176
- }
177
-
178
- }
179
-
180
- // Возвращаем итоговую строку после преобразования
181
- // всех символов.
182
- @return $-result;
183
-
184
- }
185
-
186
- }