@lumx/core 3.20.1-alpha.27 → 3.20.1-alpha.28

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.
@@ -1,4 +1,4 @@
1
- import kebabCase from 'lodash/kebabCase';
1
+ import { kebabCase } from '../string/kebabCase.js';
2
2
 
3
3
  /**
4
4
  * Get the basic CSS class for the given type.
@@ -1,5 +1,5 @@
1
1
  import { getBasicClass } from './getBasicClass.js';
2
- import 'lodash/kebabCase';
2
+ import '../string/kebabCase.js';
3
3
 
4
4
  describe(getBasicClass, () => {
5
5
  it('should return correct basic CSS class for different types and values', () => {
@@ -1,4 +1,4 @@
1
- import kebabCase from 'lodash/kebabCase';
1
+ import { kebabCase } from '../string/kebabCase';
2
2
 
3
3
  /**
4
4
  * Get the basic CSS class for the given type.
@@ -1,5 +1,5 @@
1
- import kebabCase from 'lodash/kebabCase';
2
1
  import { CSS_PREFIX } from '../../constants/index.js';
2
+ import { kebabCase } from '../string/kebabCase.js';
3
3
  import '../../constants/keycodes.js';
4
4
 
5
5
  // See https://regex101.com/r/YjS1uI/3
@@ -1,7 +1,7 @@
1
1
  import { getRootClassName } from './getRootClassName.js';
2
- import 'lodash/kebabCase';
3
2
  import '../../constants/index.js';
4
3
  import '../../constants/keycodes.js';
4
+ import '../string/kebabCase.js';
5
5
 
6
6
  describe(getRootClassName, () => {
7
7
  it('should transform the component name into a lumx class', () => {
@@ -1,6 +1,5 @@
1
- import kebabCase from 'lodash/kebabCase';
2
-
3
1
  import { CSS_PREFIX } from '../../constants';
2
+ import { kebabCase } from '../string/kebabCase';
4
3
 
5
4
  // See https://regex101.com/r/YjS1uI/3
6
5
  const LAST_PART_CLASSNAME = /^(.*)-(.+)$/gi;
@@ -1,7 +1,7 @@
1
1
  import classNames from 'classnames';
2
2
  import { isEmpty } from '@lumx/core/js/utils/collection/isEmpty';
3
3
  import { getBasicClass } from './getBasicClass.js';
4
- import 'lodash/kebabCase';
4
+ import '../string/kebabCase.js';
5
5
 
6
6
  /**
7
7
  * Enhance isEmpty method to also works with numbers.
@@ -2,7 +2,7 @@ import { handleBasicClasses } from './handleBasicClasses.js';
2
2
  import 'classnames';
3
3
  import '@lumx/core/js/utils/collection/isEmpty';
4
4
  import './getBasicClass.js';
5
- import 'lodash/kebabCase';
5
+ import '../string/kebabCase.js';
6
6
 
7
7
  describe(handleBasicClasses, () => {
8
8
  it('should return correct combined CSS classes based on props', () => {
@@ -6,6 +6,6 @@ export { fontColorClass } from './fontColorClass.js';
6
6
  export { resolveColorWithVariants } from './resolveColorWithVariants.js';
7
7
  import 'classnames';
8
8
  import '@lumx/core/js/utils/collection/isEmpty';
9
- import 'lodash/kebabCase';
9
+ import '../string/kebabCase.js';
10
10
  import '../../constants/index.js';
11
11
  import '../../constants/keycodes.js';
@@ -1,20 +1,20 @@
1
- import { isEmpty } from './isEmpty';
1
+ import { isEmpty } from './isEmpty.js';
2
2
 
3
3
  describe(isEmpty, () => {
4
- it('should return true for falsy values', () => {
5
- expect(isEmpty(undefined)).toBe(true);
6
- expect(isEmpty(null)).toBe(true);
7
- expect(isEmpty(0)).toBe(true);
8
- expect(isEmpty('')).toBe(true);
9
- });
10
-
11
- it('should return true for empty object or array', () => {
12
- expect(isEmpty([])).toBe(true);
13
- expect(isEmpty({})).toBe(true);
14
- });
15
-
16
- it('should return false for non empty object or array', () => {
17
- expect(isEmpty([''])).toBe(false);
18
- expect(isEmpty({ foo: false })).toBe(false);
19
- });
4
+ it('should return true for falsy values', () => {
5
+ expect(isEmpty(undefined)).toBe(true);
6
+ expect(isEmpty(null)).toBe(true);
7
+ expect(isEmpty(0)).toBe(true);
8
+ expect(isEmpty('')).toBe(true);
9
+ });
10
+ it('should return true for empty object or array', () => {
11
+ expect(isEmpty([])).toBe(true);
12
+ expect(isEmpty({})).toBe(true);
13
+ });
14
+ it('should return false for non empty object or array', () => {
15
+ expect(isEmpty([''])).toBe(false);
16
+ expect(isEmpty({
17
+ foo: false
18
+ })).toBe(false);
19
+ });
20
20
  });
@@ -0,0 +1,20 @@
1
+ import { isEmpty } from './isEmpty';
2
+
3
+ describe(isEmpty, () => {
4
+ it('should return true for falsy values', () => {
5
+ expect(isEmpty(undefined)).toBe(true);
6
+ expect(isEmpty(null)).toBe(true);
7
+ expect(isEmpty(0)).toBe(true);
8
+ expect(isEmpty('')).toBe(true);
9
+ });
10
+
11
+ it('should return true for empty object or array', () => {
12
+ expect(isEmpty([])).toBe(true);
13
+ expect(isEmpty({})).toBe(true);
14
+ });
15
+
16
+ it('should return false for non empty object or array', () => {
17
+ expect(isEmpty([''])).toBe(false);
18
+ expect(isEmpty({ foo: false })).toBe(false);
19
+ });
20
+ });
@@ -1,4 +1,4 @@
1
- import { Falsy } from '../../types';
1
+ import type { Falsy } from '../../types';
2
2
 
3
3
  /** Check if object or array is empty (true on falsy values) */
4
- export const isEmpty = (obj: object | Falsy) => !obj || Object.entries(obj).length === 0;
4
+ export const isEmpty = (obj: {} | Falsy) => !obj || Object.entries(obj).length === 0;
@@ -1,9 +1,9 @@
1
- import { range } from './range';
1
+ import { range } from './range.js';
2
2
 
3
3
  describe(range, () => {
4
- it('should generate a number range', () => {
5
- expect(range(0)).toEqual([]);
6
- expect(range(1)).toEqual([0]);
7
- expect(range(5)).toEqual([0, 1, 2, 3, 4]);
8
- });
4
+ it('should generate a number range', () => {
5
+ expect(range(0)).toEqual([]);
6
+ expect(range(1)).toEqual([0]);
7
+ expect(range(5)).toEqual([0, 1, 2, 3, 4]);
8
+ });
9
9
  });
@@ -0,0 +1,9 @@
1
+ import { range } from './range';
2
+
3
+ describe(range, () => {
4
+ it('should generate a number range', () => {
5
+ expect(range(0)).toEqual([]);
6
+ expect(range(1)).toEqual([0]);
7
+ expect(range(5)).toEqual([0, 1, 2, 3, 4]);
8
+ });
9
+ });
package/js/utils/index.js CHANGED
@@ -6,7 +6,7 @@ export { fontColorClass } from './className/fontColorClass.js';
6
6
  export { resolveColorWithVariants } from './className/resolveColorWithVariants.js';
7
7
  import 'classnames';
8
8
  import '@lumx/core/js/utils/collection/isEmpty';
9
- import 'lodash/kebabCase';
9
+ import './string/kebabCase.js';
10
10
  import '../constants/index.js';
11
11
  import '../constants/keycodes.js';
12
12
 
@@ -0,0 +1,28 @@
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
+ function kebabCase(str) {
15
+ return str
16
+ // Insert a hyphen before any uppercase letter that follows a lowercase letter or number
17
+ .replace(/([a-z0-9])([A-Z])/g, '$1-$2')
18
+ // Insert a hyphen before any uppercase letter that is followed by a lowercase letter and preceded by an uppercase letter
19
+ .replace(/([A-Z])([A-Z][a-z])/g, '$1-$2')
20
+ // Replace spaces and underscores with hyphens
21
+ .replace(/[\s_]+/g, '-')
22
+ // Convert to lowercase
23
+ .toLowerCase()
24
+ // Remove leading/trailing hyphens
25
+ .replace(/^-+|-+$/g, '');
26
+ }
27
+
28
+ export { kebabCase };
@@ -0,0 +1,41 @@
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
+ it('should convert PascalCase to kebab-case', () => {
9
+ expect(kebabCase('FooBar')).toBe('foo-bar');
10
+ expect(kebabCase('FooBarBaz')).toBe('foo-bar-baz');
11
+ });
12
+ it('should convert snake_case to kebab-case', () => {
13
+ expect(kebabCase('foo_bar')).toBe('foo-bar');
14
+ expect(kebabCase('foo_bar_baz')).toBe('foo-bar-baz');
15
+ });
16
+ it('should convert spaces to hyphens', () => {
17
+ expect(kebabCase('foo bar')).toBe('foo-bar');
18
+ expect(kebabCase('foo bar baz')).toBe('foo-bar-baz');
19
+ });
20
+ it('should handle UPPERCASE strings', () => {
21
+ expect(kebabCase('FOO_BAR')).toBe('foo-bar');
22
+ expect(kebabCase('FOOBAR')).toBe('foobar');
23
+ });
24
+ it('should handle mixed formats', () => {
25
+ expect(kebabCase('fooBar_baz qux')).toBe('foo-bar-baz-qux');
26
+ });
27
+ it('should handle strings that are already kebab-case', () => {
28
+ expect(kebabCase('foo-bar')).toBe('foo-bar');
29
+ });
30
+ it('should handle empty strings', () => {
31
+ expect(kebabCase('')).toBe('');
32
+ });
33
+ it('should handle single words', () => {
34
+ expect(kebabCase('foo')).toBe('foo');
35
+ expect(kebabCase('Foo')).toBe('foo');
36
+ });
37
+ it('should remove leading and trailing hyphens', () => {
38
+ expect(kebabCase('_foo_bar_')).toBe('foo-bar');
39
+ expect(kebabCase(' foo bar ')).toBe('foo-bar');
40
+ });
41
+ });
@@ -0,0 +1,50 @@
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
+ });
@@ -0,0 +1,28 @@
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
+ }
package/package.json CHANGED
@@ -31,25 +31,30 @@
31
31
  "scripts": {
32
32
  "generate:design-tokens": "yarn node style-dictionary",
33
33
  "build": "rollup -c",
34
+ "test": "vitest run",
34
35
  "update-version-changelog": "yarn version-changelog ../../CHANGELOG.md"
35
36
  },
36
37
  "sideEffects": false,
37
- "version": "3.20.1-alpha.27",
38
+ "version": "3.20.1-alpha.28",
38
39
  "devDependencies": {
39
40
  "@babel/preset-typescript": "^7.26.0",
40
41
  "@rollup/plugin-babel": "^6.0.4",
41
- "@rollup/plugin-commonjs": "^19.0.2",
42
+ "@rollup/plugin-commonjs": "^29.0.0",
42
43
  "@rollup/plugin-node-resolve": "16.0.0",
43
44
  "@types/react": "^17.0.2",
44
45
  "autoprefixer": "^9.7.4",
45
46
  "glob": "^7.1.6",
46
47
  "postcss": "^8.5.6",
47
- "rollup": "^2.79.1",
48
+ "rollup": "3.29.5",
48
49
  "rollup-plugin-cleaner": "^1.0.0",
49
50
  "rollup-plugin-copy": "^3.5.0",
50
51
  "sass": "^1.54.0",
51
52
  "style-dictionary": "^3.9.0",
52
53
  "tinycolor2": "^1.4.1",
53
- "version-changelog": "^3.1.1"
54
+ "typescript": "^5.4.3",
55
+ "version-changelog": "^3.1.1",
56
+ "vite": "^6.3.5",
57
+ "vite-tsconfig-paths": "^5.1.4",
58
+ "vitest": "^3.0.0"
54
59
  }
55
60
  }