@lumx/core 3.20.1-alpha.38 → 3.20.1-alpha.39

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 (158) hide show
  1. package/js/constants/design-tokens.d.ts +5421 -0
  2. package/js/constants/design-tokens.js +1 -3
  3. package/js/constants/index.d.ts +232 -0
  4. package/js/constants/index.js +2 -33
  5. package/js/constants/keycodes.d.ts +36 -0
  6. package/js/constants/keycodes.js +1 -11
  7. package/js/custom-colors.d.ts +25 -0
  8. package/js/custom-colors.js +1 -4
  9. package/js/types/Callback.js +0 -1
  10. package/js/types/Falsy.js +0 -1
  11. package/js/types/{GenericProps.ts → GenericProps.d.ts} +0 -1
  12. package/js/types/GenericProps.js +0 -1
  13. package/js/types/HasAriaLabelOrLabelledBy.d.ts +17 -0
  14. package/js/types/HasAriaLabelOrLabelledBy.js +0 -1
  15. package/js/types/HasClassName.js +0 -1
  16. package/js/types/HasCloseMode.js +0 -1
  17. package/js/types/{HasTheme.ts → HasTheme.d.ts} +0 -1
  18. package/js/types/HasTheme.js +0 -1
  19. package/js/types/HeadingElement.js +0 -1
  20. package/js/types/Point.d.ts +7 -0
  21. package/js/types/Point.js +0 -1
  22. package/js/types/Predicate.js +0 -1
  23. package/js/types/RectSize.d.ts +7 -0
  24. package/js/types/RectSize.js +0 -1
  25. package/js/types/{TextElement.ts → TextElement.d.ts} +0 -1
  26. package/js/types/TextElement.js +0 -1
  27. package/js/types/ValueOf.js +0 -1
  28. package/js/types/index.js +0 -1
  29. package/js/utils/className/fontColorClass.d.ts +6 -0
  30. package/js/utils/className/fontColorClass.js +4 -7
  31. package/js/utils/className/getBasicClass.d.ts +13 -0
  32. package/js/utils/className/getBasicClass.js +7 -8
  33. package/js/utils/className/{getRootClassName.ts → getRootClassName.d.ts} +1 -14
  34. package/js/utils/className/getRootClassName.js +4 -7
  35. package/js/utils/className/{getTypographyClassName.ts → getTypographyClassName.d.ts} +1 -4
  36. package/js/utils/className/getTypographyClassName.js +1 -3
  37. package/js/utils/className/handleBasicClasses.d.ts +15 -0
  38. package/js/utils/className/handleBasicClasses.js +10 -11
  39. package/js/utils/className/index.js +6 -22
  40. package/js/utils/className/resolveColorWithVariants.d.ts +3 -0
  41. package/js/utils/className/resolveColorWithVariants.js +1 -3
  42. package/js/utils/events/index.d.ts +2 -0
  43. package/js/utils/events/index.js +2 -0
  44. package/js/utils/events/keyboard.d.ts +24 -0
  45. package/js/utils/events/keyboard.js +44 -0
  46. package/js/utils/events/swipe.d.ts +6 -0
  47. package/js/utils/events/swipe.js +79 -0
  48. package/js/utils/index.d.ts +2 -0
  49. package/js/utils/index.js +8 -215
  50. package/package.json +4 -5
  51. package/js/constants/design-tokens.min.js +0 -1
  52. package/js/constants/design-tokens.ts +0 -2324
  53. package/js/constants/index.min.js +0 -1
  54. package/js/constants/index.ts +0 -231
  55. package/js/constants/keycodes.min.js +0 -1
  56. package/js/constants/keycodes.ts +0 -44
  57. package/js/custom-colors.min.js +0 -1
  58. package/js/custom-colors.ts +0 -56
  59. package/js/types/Callback.min.js +0 -1
  60. package/js/types/Falsy.min.js +0 -1
  61. package/js/types/GenericProps.min.js +0 -1
  62. package/js/types/HasAriaLabelOrLabelledBy.min.js +0 -1
  63. package/js/types/HasAriaLabelOrLabelledBy.ts +0 -19
  64. package/js/types/HasClassName.min.js +0 -1
  65. package/js/types/HasCloseMode.min.js +0 -1
  66. package/js/types/HasTheme.min.js +0 -1
  67. package/js/types/HeadingElement.min.js +0 -1
  68. package/js/types/Point.min.js +0 -1
  69. package/js/types/Point.ts +0 -4
  70. package/js/types/Predicate.min.js +0 -1
  71. package/js/types/RectSize.min.js +0 -1
  72. package/js/types/RectSize.ts +0 -4
  73. package/js/types/TextElement.min.js +0 -1
  74. package/js/types/ValueOf.min.js +0 -1
  75. package/js/types/index.min.js +0 -1
  76. package/js/utils/className/fontColorClass.min.js +0 -1
  77. package/js/utils/className/fontColorClass.test.js +0 -18
  78. package/js/utils/className/fontColorClass.test.min.js +0 -1
  79. package/js/utils/className/fontColorClass.test.ts +0 -15
  80. package/js/utils/className/fontColorClass.ts +0 -12
  81. package/js/utils/className/getBasicClass.min.js +0 -1
  82. package/js/utils/className/getBasicClass.test.js +0 -21
  83. package/js/utils/className/getBasicClass.test.min.js +0 -1
  84. package/js/utils/className/getBasicClass.test.ts +0 -20
  85. package/js/utils/className/getBasicClass.ts +0 -35
  86. package/js/utils/className/getRootClassName.min.js +0 -1
  87. package/js/utils/className/getRootClassName.test.js +0 -15
  88. package/js/utils/className/getRootClassName.test.min.js +0 -1
  89. package/js/utils/className/getRootClassName.test.ts +0 -11
  90. package/js/utils/className/getTypographyClassName.min.js +0 -1
  91. package/js/utils/className/getTypographyClassName.test.js +0 -9
  92. package/js/utils/className/getTypographyClassName.test.min.js +0 -1
  93. package/js/utils/className/getTypographyClassName.test.ts +0 -7
  94. package/js/utils/className/handleBasicClasses.min.js +0 -1
  95. package/js/utils/className/handleBasicClasses.test.js +0 -34
  96. package/js/utils/className/handleBasicClasses.test.min.js +0 -1
  97. package/js/utils/className/handleBasicClasses.test.ts +0 -28
  98. package/js/utils/className/handleBasicClasses.ts +0 -42
  99. package/js/utils/className/index.min.js +0 -1
  100. package/js/utils/className/resolveColorWithVariants.min.js +0 -1
  101. package/js/utils/className/resolveColorWithVariants.test.js +0 -30
  102. package/js/utils/className/resolveColorWithVariants.test.min.js +0 -1
  103. package/js/utils/className/resolveColorWithVariants.test.ts +0 -33
  104. package/js/utils/className/resolveColorWithVariants.ts +0 -11
  105. package/js/utils/collection/castArray.js +0 -6
  106. package/js/utils/collection/castArray.min.js +0 -1
  107. package/js/utils/collection/castArray.test.js +0 -17
  108. package/js/utils/collection/castArray.test.min.js +0 -1
  109. package/js/utils/collection/castArray.test.ts +0 -15
  110. package/js/utils/collection/castArray.ts +0 -3
  111. package/js/utils/collection/chunk.js +0 -15
  112. package/js/utils/collection/chunk.min.js +0 -1
  113. package/js/utils/collection/chunk.test.js +0 -33
  114. package/js/utils/collection/chunk.test.min.js +0 -1
  115. package/js/utils/collection/chunk.test.ts +0 -38
  116. package/js/utils/collection/chunk.ts +0 -11
  117. package/js/utils/collection/isEmpty.js +0 -6
  118. package/js/utils/collection/isEmpty.min.js +0 -1
  119. package/js/utils/collection/isEmpty.test.js +0 -21
  120. package/js/utils/collection/isEmpty.test.min.js +0 -1
  121. package/js/utils/collection/isEmpty.test.ts +0 -21
  122. package/js/utils/collection/isEmpty.ts +0 -4
  123. package/js/utils/collection/last.js +0 -6
  124. package/js/utils/collection/last.min.js +0 -1
  125. package/js/utils/collection/last.test.js +0 -21
  126. package/js/utils/collection/last.test.min.js +0 -1
  127. package/js/utils/collection/last.test.ts +0 -21
  128. package/js/utils/collection/last.ts +0 -2
  129. package/js/utils/collection/partitionMulti.js +0 -31
  130. package/js/utils/collection/partitionMulti.min.js +0 -1
  131. package/js/utils/collection/partitionMulti.test.js +0 -32
  132. package/js/utils/collection/partitionMulti.test.min.js +0 -1
  133. package/js/utils/collection/partitionMulti.test.ts +0 -35
  134. package/js/utils/collection/partitionMulti.ts +0 -29
  135. package/js/utils/collection/range.js +0 -6
  136. package/js/utils/collection/range.min.js +0 -1
  137. package/js/utils/collection/range.test.js +0 -12
  138. package/js/utils/collection/range.test.min.js +0 -1
  139. package/js/utils/collection/range.test.ts +0 -10
  140. package/js/utils/collection/range.ts +0 -2
  141. package/js/utils/index.min.js +0 -1
  142. package/js/utils/index.ts +0 -219
  143. package/js/utils/string/kebabCase.js +0 -30
  144. package/js/utils/string/kebabCase.min.js +0 -1
  145. package/js/utils/string/kebabCase.test.js +0 -43
  146. package/js/utils/string/kebabCase.test.min.js +0 -1
  147. package/js/utils/string/kebabCase.test.ts +0 -50
  148. package/js/utils/string/kebabCase.ts +0 -28
  149. package/lumx.min.css +0 -1
  150. /package/js/types/{Callback.ts → Callback.d.ts} +0 -0
  151. /package/js/types/{Falsy.ts → Falsy.d.ts} +0 -0
  152. /package/js/types/{HasClassName.ts → HasClassName.d.ts} +0 -0
  153. /package/js/types/{HasCloseMode.ts → HasCloseMode.d.ts} +0 -0
  154. /package/js/types/{HeadingElement.ts → HeadingElement.d.ts} +0 -0
  155. /package/js/types/{Predicate.ts → Predicate.d.ts} +0 -0
  156. /package/js/types/{ValueOf.ts → ValueOf.d.ts} +0 -0
  157. /package/js/types/{index.ts → index.d.ts} +0 -0
  158. /package/js/utils/className/{index.ts → index.d.ts} +0 -0
@@ -1 +0,0 @@
1
- "use strict";exports.range=r=>Array.from({length:r},(r,e)=>e);
@@ -1,12 +0,0 @@
1
- 'use strict';
2
-
3
- var js_utils_collection_range = require('./range.js');
4
-
5
- describe(js_utils_collection_range.range, () => {
6
- it('should generate a number range', () => {
7
- expect(js_utils_collection_range.range(-2)).toEqual([]);
8
- expect(js_utils_collection_range.range(0)).toEqual([]);
9
- expect(js_utils_collection_range.range(1)).toEqual([0]);
10
- expect(js_utils_collection_range.range(5)).toEqual([0, 1, 2, 3, 4]);
11
- });
12
- });
@@ -1 +0,0 @@
1
- "use strict";var e=require("./range.min.js");describe(e.range,()=>{it("should generate a number range",()=>{expect(e.range(-2)).toEqual([]),expect(e.range(0)).toEqual([]),expect(e.range(1)).toEqual([0]),expect(e.range(5)).toEqual([0,1,2,3,4])})});
@@ -1,10 +0,0 @@
1
- import { range } from './range';
2
-
3
- describe(range, () => {
4
- it('should generate a number range', () => {
5
- expect(range(-2)).toEqual([]);
6
- expect(range(0)).toEqual([]);
7
- expect(range(1)).toEqual([0]);
8
- expect(range(5)).toEqual([0, 1, 2, 3, 4]);
9
- });
10
- });
@@ -1,2 +0,0 @@
1
- /** Generate a range of number starting at 0 and ending before the given number */
2
- export const range = (end: number) => Array.from({ length: end }, (_, i) => i);
@@ -1 +0,0 @@
1
- "use strict";var e=require("./className/handleBasicClasses.min.js"),t=require("./className/getBasicClass.min.js"),s=require("./className/getRootClassName.min.js"),r=require("./className/getTypographyClassName.min.js"),a=require("./className/fontColorClass.min.js"),n=require("./className/resolveColorWithVariants.min.js");require("classnames"),require("./collection/isEmpty.min.js"),require("./string/kebabCase.min.js"),require("../constants/index.min.js"),require("../constants/keycodes.min.js"),exports.handleBasicClasses=e.handleBasicClasses,exports.getBasicClass=t.getBasicClass,exports.getRootClassName=s.getRootClassName,exports.getTypographyClassName=r.getTypographyClassName,exports.fontColorClass=a.fontColorClass,exports.resolveColorWithVariants=n.resolveColorWithVariants,exports.detectHorizontalSwipe=function(e,t){let s,r,a,n,o;const i=e=>{const[t]=Array.from(e.changedTouches);s=t.pageX,r=t.pageY,n=(new Date).getTime(),o=!1},c=e=>{if(o)return;if(a=(new Date).getTime()-n,a>300)return;const[i]=Array.from(e.changedTouches),c=i.pageX-s,u=i.pageY-r;if(!(Math.abs(c)>=150&&Math.abs(u)<=150))return;t(c<0?"left":"right"),o=!0},u=!!function(){let e=!1;try{const t=Object.defineProperty({},"passive",{get(){e=!0}});window.addEventListener("testPassiveEventSupport",()=>{},t),window.removeEventListener("testPassiveEventSupport",()=>{},t)}catch(e){}return e}()&&{passive:!0};return e.addEventListener("touchstart",i,u),e.addEventListener("touchmove",c,u),()=>{e.removeEventListener("touchstart",i,u),e.removeEventListener("touchmove",c,u)}},exports.detectSwipe=function(e,t){let s,r,a,n,o,i,c;const u=e=>{const[t]=Array.from(e.changedTouches);o="none",a=t.pageX,n=t.pageY,c=(new Date).getTime(),e.preventDefault()},l=e=>{e.preventDefault()},m=e=>{const[u]=Array.from(e.changedTouches);s=u.pageX-a,r=u.pageY-n,i=(new Date).getTime()-c,i<=300&&(Math.abs(s)>=150&&Math.abs(r)<=100?o=s<0?"left":"right":Math.abs(r)>=150&&Math.abs(s)<=100&&(o=r<0?"up":"down")),t?.(o),e.preventDefault()};return e.addEventListener("touchstart",u,!1),e.addEventListener("touchmove",l,!1),e.addEventListener("touchend",m,!1),()=>{e.removeEventListener("touchstart",u,!1),e.removeEventListener("touchmove",l,!1),e.removeEventListener("touchend",m,!1)}},exports.onButtonPressed=function(e){return t=>{"Enter"!==t.key&&" "!==t.key||e(t)}},exports.onEnterPressed=function(e){return t=>{"Enter"===t.key&&e(t)}},exports.onEscapePressed=function(e){return t=>{"Escape"===t.key&&e(t)}};
package/js/utils/index.ts DELETED
@@ -1,219 +0,0 @@
1
- import type { KeyboardEvent as ReactKeyboardEvent } from 'react';
2
-
3
- export * from './className';
4
-
5
- type KeyboardEventHandler<E extends KeyboardEvent | ReactKeyboardEvent> = (event: E) => void;
6
-
7
- /**
8
- * Make sure the pressed key is the enter key before calling the callback.
9
- *
10
- * @param handler The handler to call on enter/return press.
11
- * @return The decorated function.
12
- */
13
- export function onEnterPressed<E extends KeyboardEvent | ReactKeyboardEvent>(
14
- handler: KeyboardEventHandler<E>,
15
- ): KeyboardEventHandler<E> {
16
- return (evt) => {
17
- if (evt.key !== 'Enter') {
18
- return;
19
- }
20
- handler(evt);
21
- };
22
- }
23
-
24
- /**
25
- * Make sure the pressed key is the escape key before calling the callback.
26
- *
27
- * @param handler The handler to call on enter/return press.
28
- * @return The decorated function.
29
- */
30
- export function onEscapePressed<E extends KeyboardEvent | ReactKeyboardEvent>(
31
- handler: KeyboardEventHandler<E>,
32
- ): KeyboardEventHandler<E> {
33
- return (evt) => {
34
- if (evt.key !== 'Escape') {
35
- return;
36
- }
37
- handler(evt);
38
- };
39
- }
40
-
41
- /**
42
- * Handle button key pressed (Enter + Space).
43
- *
44
- * @param handler The handler to call.
45
- * @return The decorated function.
46
- */
47
- export function onButtonPressed<E extends KeyboardEvent | ReactKeyboardEvent>(
48
- handler: KeyboardEventHandler<E>,
49
- ): KeyboardEventHandler<E> {
50
- return (evt) => {
51
- if (evt.key !== 'Enter' && evt.key !== ' ') {
52
- return;
53
- }
54
- handler(evt);
55
- };
56
- }
57
-
58
- declare type SwipeDirection = 'none' | 'up' | 'down' | 'left' | 'right';
59
-
60
- /**
61
- * Detects swipe direction.
62
- * Credits: http://javascriptkit.com/javatutors/touchevents2.shtml.
63
- *
64
- * @deprecated use `detectHorizontalSwipe` instead if possible (better performance and does not block scroll)
65
- * @param touchSurface Element that will hold touch events.
66
- * @param handleSwipe Callback function.
67
- * @return Function to remove listeners.
68
- */
69
- export function detectSwipe(touchSurface: Element, handleSwipe?: (direction: SwipeDirection) => void) {
70
- let distX: number;
71
- let distY: number;
72
- let startX: number;
73
- let startY: number;
74
- let direction: SwipeDirection;
75
- // Required min distance traveled to be considered swipe.
76
- const threshold = 150;
77
- // Maximum distance allowed at the same time in perpendicular direction.
78
- const restraint = 100;
79
- // Maximum time allowed to travel that distance.
80
- const allowedTime = 300;
81
- let elapsedTime: number;
82
- let startTime: number;
83
-
84
- const onTouchStart = (evt: Event) => {
85
- const [touch] = Array.from((evt as TouchEvent).changedTouches);
86
- direction = 'none';
87
- // Const dist = 0;
88
- startX = touch.pageX;
89
- startY = touch.pageY;
90
- // Record time when finger first makes contact with surface.
91
- startTime = new Date().getTime();
92
- evt.preventDefault();
93
- };
94
-
95
- const onTouchMove = (evt: Event) => {
96
- // Prevent scrolling when inside DIV.
97
- evt.preventDefault();
98
- };
99
-
100
- const onTouchEnd = (evt: Event) => {
101
- const [touch] = Array.from((evt as TouchEvent).changedTouches);
102
- // Get horizontal dist traveled by finger while in contact with surface.
103
- distX = touch.pageX - startX;
104
- // Get vertical dist traveled by finger while in contact with surface.
105
- distY = touch.pageY - startY;
106
- // Get time elapsed.
107
- elapsedTime = new Date().getTime() - startTime;
108
- if (elapsedTime <= allowedTime) {
109
- // First condition for awipe met.
110
- if (Math.abs(distX) >= threshold && Math.abs(distY) <= restraint) {
111
- // 2nd condition for horizontal swipe met.
112
- // If dist traveled is negative, it indicates left swipe.
113
- direction = distX < 0 ? 'left' : 'right';
114
- } else if (Math.abs(distY) >= threshold && Math.abs(distX) <= restraint) {
115
- // 2nd condition for vertical swipe met.
116
- // If dist traveled is negative, it indicates up swipe.
117
- direction = distY < 0 ? 'up' : 'down';
118
- }
119
- }
120
- handleSwipe?.(direction);
121
- evt.preventDefault();
122
- };
123
-
124
- touchSurface.addEventListener('touchstart', onTouchStart, false);
125
- touchSurface.addEventListener('touchmove', onTouchMove, false);
126
- touchSurface.addEventListener('touchend', onTouchEnd, false);
127
-
128
- return () => {
129
- touchSurface.removeEventListener('touchstart', onTouchStart, false);
130
- touchSurface.removeEventListener('touchmove', onTouchMove, false);
131
- touchSurface.removeEventListener('touchend', onTouchEnd, false);
132
- };
133
- }
134
-
135
- /**
136
- * Checks whether or not the browser support passive events.
137
- * @see https://github.com/Modernizr/Modernizr/blob/6d56d814b9682843313b16060adb25a58d83a317/feature-detects/dom/passiveeventlisteners.js
138
- */
139
- function isPassiveEventAvailable() {
140
- let supportsPassiveOption = false;
141
- try {
142
- const opts = Object.defineProperty({}, 'passive', {
143
- get() {
144
- supportsPassiveOption = true;
145
- },
146
- });
147
- window.addEventListener('testPassiveEventSupport', () => {}, opts);
148
- window.removeEventListener('testPassiveEventSupport', () => {}, opts);
149
- } catch (e) {
150
- // ignored
151
- }
152
- return supportsPassiveOption;
153
- }
154
-
155
- /**
156
- * Detects horizontal swipe direction without blocking the browser scroll using passive event.
157
- * @see http://javascriptkit.com/javatutors/touchevents2.shtml
158
- * @see https://github.com/WICG/EventListenerOptions/blob/gh-pages/explainer.md
159
- */
160
- export function detectHorizontalSwipe(touchSurface: Element, handleSwipe: (direction: 'right' | 'left') => void) {
161
- let startX: number;
162
- let startY: number;
163
- // Required min distance traveled to be considered swipe.
164
- const threshold = 150;
165
- // Maximum distance allowed at the same time in perpendicular direction.
166
- const restraint = 150;
167
- // Maximum time allowed to travel that distance.
168
- const allowedTime = 300;
169
- let elapsedTime: number;
170
- let startTime: number;
171
- let finished: boolean;
172
-
173
- const onTouchStart = (evt: Event) => {
174
- const [touch] = Array.from((evt as TouchEvent).changedTouches);
175
- startX = touch.pageX;
176
- startY = touch.pageY;
177
- // Record time when finger first makes contact with surface.
178
- startTime = new Date().getTime();
179
- finished = false;
180
- };
181
-
182
- const onTouchMove = (evt: Event) => {
183
- if (finished) {
184
- return;
185
- }
186
-
187
- elapsedTime = new Date().getTime() - startTime;
188
- if (elapsedTime > allowedTime) {
189
- // Touch swipe too long to be considered.
190
- return;
191
- }
192
-
193
- const [touch] = Array.from((evt as TouchEvent).changedTouches);
194
- // Get horizontal dist traveled by finger while in contact with surface.
195
- const distX = touch.pageX - startX;
196
- // Get vertical dist traveled by finger while in contact with surface.
197
- const distY = touch.pageY - startY;
198
-
199
- if (!(Math.abs(distX) >= threshold && Math.abs(distY) <= restraint)) {
200
- // Swipe is not horizontal.
201
- return;
202
- }
203
- // Swipe direction.
204
- const direction = distX < 0 ? 'left' : 'right';
205
-
206
- handleSwipe(direction);
207
- finished = true;
208
- };
209
-
210
- // Activate passive event if possible for better scrolling performance.
211
- const eventOptions: any = isPassiveEventAvailable() ? { passive: true } : false;
212
- touchSurface.addEventListener('touchstart', onTouchStart, eventOptions);
213
- touchSurface.addEventListener('touchmove', onTouchMove, eventOptions);
214
-
215
- return () => {
216
- touchSurface.removeEventListener('touchstart', onTouchStart, eventOptions);
217
- touchSurface.removeEventListener('touchmove', onTouchMove, eventOptions);
218
- };
219
- }
@@ -1,30 +0,0 @@
1
- 'use strict';
2
-
3
- /**
4
- * Converts a string to kebab-case.
5
- *
6
- * @param str The string to convert
7
- * @returns The kebab-cased string
8
- *
9
- * @example
10
- * kebabCase('fooBar') // 'foo-bar'
11
- * kebabCase('FooBar') // 'foo-bar'
12
- * kebabCase('foo_bar') // 'foo-bar'
13
- * kebabCase('foo bar') // 'foo-bar'
14
- * kebabCase('FOO_BAR') // 'foo-bar'
15
- */
16
- function kebabCase(str) {
17
- return (str
18
- // Insert a hyphen before any uppercase letter that follows a lowercase letter or number
19
- .replace(/([a-z0-9])([A-Z])/g, '$1-$2')
20
- // Insert a hyphen before any uppercase letter that is followed by a lowercase letter and preceded by an uppercase letter
21
- .replace(/([A-Z])([A-Z][a-z])/g, '$1-$2')
22
- // Replace spaces and underscores with hyphens
23
- .replace(/[\s_]+/g, '-')
24
- // Convert to lowercase
25
- .toLowerCase()
26
- // Remove leading/trailing hyphens
27
- .replace(/^-+|-+$/g, ''));
28
- }
29
-
30
- exports.kebabCase = kebabCase;
@@ -1 +0,0 @@
1
- "use strict";exports.kebabCase=function(e){return e.replace(/([a-z0-9])([A-Z])/g,"$1-$2").replace(/([A-Z])([A-Z][a-z])/g,"$1-$2").replace(/[\s_]+/g,"-").toLowerCase().replace(/^-+|-+$/g,"")};
@@ -1,43 +0,0 @@
1
- 'use strict';
2
-
3
- var js_utils_string_kebabCase = require('./kebabCase.js');
4
-
5
- describe(js_utils_string_kebabCase.kebabCase, () => {
6
- it('should convert camelCase to kebab-case', () => {
7
- expect(js_utils_string_kebabCase.kebabCase('fooBar')).toBe('foo-bar');
8
- expect(js_utils_string_kebabCase.kebabCase('fooBarBaz')).toBe('foo-bar-baz');
9
- });
10
- it('should convert PascalCase to kebab-case', () => {
11
- expect(js_utils_string_kebabCase.kebabCase('FooBar')).toBe('foo-bar');
12
- expect(js_utils_string_kebabCase.kebabCase('FooBarBaz')).toBe('foo-bar-baz');
13
- });
14
- it('should convert snake_case to kebab-case', () => {
15
- expect(js_utils_string_kebabCase.kebabCase('foo_bar')).toBe('foo-bar');
16
- expect(js_utils_string_kebabCase.kebabCase('foo_bar_baz')).toBe('foo-bar-baz');
17
- });
18
- it('should convert spaces to hyphens', () => {
19
- expect(js_utils_string_kebabCase.kebabCase('foo bar')).toBe('foo-bar');
20
- expect(js_utils_string_kebabCase.kebabCase('foo bar baz')).toBe('foo-bar-baz');
21
- });
22
- it('should handle UPPERCASE strings', () => {
23
- expect(js_utils_string_kebabCase.kebabCase('FOO_BAR')).toBe('foo-bar');
24
- expect(js_utils_string_kebabCase.kebabCase('FOOBAR')).toBe('foobar');
25
- });
26
- it('should handle mixed formats', () => {
27
- expect(js_utils_string_kebabCase.kebabCase('fooBar_baz qux')).toBe('foo-bar-baz-qux');
28
- });
29
- it('should handle strings that are already kebab-case', () => {
30
- expect(js_utils_string_kebabCase.kebabCase('foo-bar')).toBe('foo-bar');
31
- });
32
- it('should handle empty strings', () => {
33
- expect(js_utils_string_kebabCase.kebabCase('')).toBe('');
34
- });
35
- it('should handle single words', () => {
36
- expect(js_utils_string_kebabCase.kebabCase('foo')).toBe('foo');
37
- expect(js_utils_string_kebabCase.kebabCase('Foo')).toBe('foo');
38
- });
39
- it('should remove leading and trailing hyphens', () => {
40
- expect(js_utils_string_kebabCase.kebabCase('_foo_bar_')).toBe('foo-bar');
41
- expect(js_utils_string_kebabCase.kebabCase(' foo bar ')).toBe('foo-bar');
42
- });
43
- });
@@ -1 +0,0 @@
1
- "use strict";var e=require("./kebabCase.min.js");describe(e.kebabCase,()=>{it("should convert camelCase to kebab-case",()=>{expect(e.kebabCase("fooBar")).toBe("foo-bar"),expect(e.kebabCase("fooBarBaz")).toBe("foo-bar-baz")}),it("should convert PascalCase to kebab-case",()=>{expect(e.kebabCase("FooBar")).toBe("foo-bar"),expect(e.kebabCase("FooBarBaz")).toBe("foo-bar-baz")}),it("should convert snake_case to kebab-case",()=>{expect(e.kebabCase("foo_bar")).toBe("foo-bar"),expect(e.kebabCase("foo_bar_baz")).toBe("foo-bar-baz")}),it("should convert spaces to hyphens",()=>{expect(e.kebabCase("foo bar")).toBe("foo-bar"),expect(e.kebabCase("foo bar baz")).toBe("foo-bar-baz")}),it("should handle UPPERCASE strings",()=>{expect(e.kebabCase("FOO_BAR")).toBe("foo-bar"),expect(e.kebabCase("FOOBAR")).toBe("foobar")}),it("should handle mixed formats",()=>{expect(e.kebabCase("fooBar_baz qux")).toBe("foo-bar-baz-qux")}),it("should handle strings that are already kebab-case",()=>{expect(e.kebabCase("foo-bar")).toBe("foo-bar")}),it("should handle empty strings",()=>{expect(e.kebabCase("")).toBe("")}),it("should handle single words",()=>{expect(e.kebabCase("foo")).toBe("foo"),expect(e.kebabCase("Foo")).toBe("foo")}),it("should remove leading and trailing hyphens",()=>{expect(e.kebabCase("_foo_bar_")).toBe("foo-bar"),expect(e.kebabCase(" foo bar ")).toBe("foo-bar")})});
@@ -1,50 +0,0 @@
1
- import { kebabCase } from '@lumx/core/js/utils/string/kebabCase';
2
-
3
- describe(kebabCase, () => {
4
- it('should convert camelCase to kebab-case', () => {
5
- expect(kebabCase('fooBar')).toBe('foo-bar');
6
- expect(kebabCase('fooBarBaz')).toBe('foo-bar-baz');
7
- });
8
-
9
- it('should convert PascalCase to kebab-case', () => {
10
- expect(kebabCase('FooBar')).toBe('foo-bar');
11
- expect(kebabCase('FooBarBaz')).toBe('foo-bar-baz');
12
- });
13
-
14
- it('should convert snake_case to kebab-case', () => {
15
- expect(kebabCase('foo_bar')).toBe('foo-bar');
16
- expect(kebabCase('foo_bar_baz')).toBe('foo-bar-baz');
17
- });
18
-
19
- it('should convert spaces to hyphens', () => {
20
- expect(kebabCase('foo bar')).toBe('foo-bar');
21
- expect(kebabCase('foo bar baz')).toBe('foo-bar-baz');
22
- });
23
-
24
- it('should handle UPPERCASE strings', () => {
25
- expect(kebabCase('FOO_BAR')).toBe('foo-bar');
26
- expect(kebabCase('FOOBAR')).toBe('foobar');
27
- });
28
-
29
- it('should handle mixed formats', () => {
30
- expect(kebabCase('fooBar_baz qux')).toBe('foo-bar-baz-qux');
31
- });
32
-
33
- it('should handle strings that are already kebab-case', () => {
34
- expect(kebabCase('foo-bar')).toBe('foo-bar');
35
- });
36
-
37
- it('should handle empty strings', () => {
38
- expect(kebabCase('')).toBe('');
39
- });
40
-
41
- it('should handle single words', () => {
42
- expect(kebabCase('foo')).toBe('foo');
43
- expect(kebabCase('Foo')).toBe('foo');
44
- });
45
-
46
- it('should remove leading and trailing hyphens', () => {
47
- expect(kebabCase('_foo_bar_')).toBe('foo-bar');
48
- expect(kebabCase(' foo bar ')).toBe('foo-bar');
49
- });
50
- });
@@ -1,28 +0,0 @@
1
- /**
2
- * Converts a string to kebab-case.
3
- *
4
- * @param str The string to convert
5
- * @returns The kebab-cased string
6
- *
7
- * @example
8
- * kebabCase('fooBar') // 'foo-bar'
9
- * kebabCase('FooBar') // 'foo-bar'
10
- * kebabCase('foo_bar') // 'foo-bar'
11
- * kebabCase('foo bar') // 'foo-bar'
12
- * kebabCase('FOO_BAR') // 'foo-bar'
13
- */
14
- export function kebabCase(str: string): string {
15
- return (
16
- str
17
- // Insert a hyphen before any uppercase letter that follows a lowercase letter or number
18
- .replace(/([a-z0-9])([A-Z])/g, '$1-$2')
19
- // Insert a hyphen before any uppercase letter that is followed by a lowercase letter and preceded by an uppercase letter
20
- .replace(/([A-Z])([A-Z][a-z])/g, '$1-$2')
21
- // Replace spaces and underscores with hyphens
22
- .replace(/[\s_]+/g, '-')
23
- // Convert to lowercase
24
- .toLowerCase()
25
- // Remove leading/trailing hyphens
26
- .replace(/^-+|-+$/g, '')
27
- );
28
- }