@lumx/core 3.20.1-alpha.30 → 3.20.1-alpha.32
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.
- package/js/constants/design-tokens.js +2292 -5389
- package/js/constants/design-tokens.min.js +1 -0
- package/js/constants/index.js +132 -107
- package/js/constants/index.min.js +1 -0
- package/js/constants/keycodes.js +11 -9
- package/js/constants/keycodes.min.js +1 -0
- package/js/custom-colors.js +20 -17
- package/js/custom-colors.min.js +1 -0
- package/js/types/Callback.js +1 -0
- package/js/types/Callback.min.js +1 -0
- package/js/types/Falsy.js +1 -0
- package/js/types/Falsy.min.js +1 -0
- package/js/types/GenericProps.js +1 -0
- package/js/types/GenericProps.min.js +1 -0
- package/js/types/HasAriaLabelOrLabelledBy.js +1 -0
- package/js/types/HasAriaLabelOrLabelledBy.min.js +1 -0
- package/js/types/HasClassName.js +1 -0
- package/js/types/HasClassName.min.js +1 -0
- package/js/types/HasCloseMode.js +1 -0
- package/js/types/HasCloseMode.min.js +1 -0
- package/js/types/HasTheme.js +1 -0
- package/js/types/HasTheme.min.js +1 -0
- package/js/types/HeadingElement.js +1 -0
- package/js/types/HeadingElement.min.js +1 -0
- package/js/types/Point.js +1 -0
- package/js/types/Point.min.js +1 -0
- package/js/types/Predicate.js +1 -0
- package/js/types/Predicate.min.js +1 -0
- package/js/types/RectSize.js +1 -0
- package/js/types/RectSize.min.js +1 -0
- package/js/types/TextElement.js +1 -0
- package/js/types/TextElement.min.js +1 -0
- package/js/types/ValueOf.js +1 -0
- package/js/types/ValueOf.min.js +1 -0
- package/js/types/index.js +1 -0
- package/js/types/index.min.js +1 -0
- package/js/utils/className/fontColorClass.js +10 -7
- package/js/utils/className/fontColorClass.min.js +1 -0
- package/js/utils/className/fontColorClass.test.js +16 -14
- package/js/utils/className/fontColorClass.test.min.js +1 -0
- package/js/utils/className/getBasicClass.js +17 -18
- package/js/utils/className/getBasicClass.min.js +1 -0
- package/js/utils/className/getBasicClass.test.js +19 -54
- package/js/utils/className/getBasicClass.test.min.js +1 -0
- package/js/utils/className/getBasicClass.ts +3 -2
- package/js/utils/className/getRootClassName.js +11 -10
- package/js/utils/className/getRootClassName.min.js +1 -0
- package/js/utils/className/getRootClassName.test.js +13 -11
- package/js/utils/className/getRootClassName.test.min.js +1 -0
- package/js/utils/className/getRootClassName.ts +2 -1
- package/js/utils/className/getTypographyClassName.js +5 -3
- package/js/utils/className/getTypographyClassName.min.js +1 -0
- package/js/utils/className/getTypographyClassName.test.js +7 -5
- package/js/utils/className/getTypographyClassName.test.min.js +1 -0
- package/js/utils/className/handleBasicClasses.js +23 -26
- package/js/utils/className/handleBasicClasses.min.js +1 -0
- package/js/utils/className/handleBasicClasses.test.js +32 -29
- package/js/utils/className/handleBasicClasses.test.min.js +1 -0
- package/js/utils/className/handleBasicClasses.ts +5 -3
- package/js/utils/className/index.js +23 -11
- package/js/utils/className/index.min.js +1 -0
- package/js/utils/className/resolveColorWithVariants.js +7 -4
- package/js/utils/className/resolveColorWithVariants.min.js +1 -0
- package/js/utils/className/resolveColorWithVariants.test.js +28 -26
- package/js/utils/className/resolveColorWithVariants.test.min.js +1 -0
- package/js/utils/index.js +168 -159
- package/js/utils/index.min.js +1 -0
- package/js/utils/index.ts +6 -4
- package/lumx.min.css +1 -0
- package/package.json +3 -5
- package/js/utils/collection/castArray.js +0 -4
- package/js/utils/collection/castArray.test.js +0 -15
- package/js/utils/collection/castArray.test.ts +0 -15
- package/js/utils/collection/castArray.ts +0 -3
- package/js/utils/collection/chunk.js +0 -13
- package/js/utils/collection/chunk.test.js +0 -28
- package/js/utils/collection/chunk.test.ts +0 -38
- package/js/utils/collection/chunk.ts +0 -11
- package/js/utils/collection/isEmpty.js +0 -4
- package/js/utils/collection/isEmpty.test.js +0 -21
- package/js/utils/collection/isEmpty.test.ts +0 -21
- package/js/utils/collection/isEmpty.ts +0 -4
- package/js/utils/collection/last.js +0 -4
- package/js/utils/collection/last.test.js +0 -19
- package/js/utils/collection/last.test.ts +0 -21
- package/js/utils/collection/last.ts +0 -2
- package/js/utils/collection/partitionMulti.js +0 -28
- package/js/utils/collection/partitionMulti.test.js +0 -26
- package/js/utils/collection/partitionMulti.test.ts +0 -35
- package/js/utils/collection/partitionMulti.ts +0 -29
- package/js/utils/collection/range.js +0 -6
- package/js/utils/collection/range.test.js +0 -10
- package/js/utils/collection/range.test.ts +0 -10
- package/js/utils/collection/range.ts +0 -2
- package/js/utils/string/kebabCase.js +0 -28
- package/js/utils/string/kebabCase.test.js +0 -41
- package/js/utils/string/kebabCase.test.ts +0 -50
- package/js/utils/string/kebabCase.ts +0 -28
package/package.json
CHANGED
|
@@ -19,7 +19,6 @@
|
|
|
19
19
|
"LumX"
|
|
20
20
|
],
|
|
21
21
|
"license": "MIT",
|
|
22
|
-
"type": "module",
|
|
23
22
|
"name": "@lumx/core",
|
|
24
23
|
"publishConfig": {
|
|
25
24
|
"directory": "dist"
|
|
@@ -35,12 +34,11 @@
|
|
|
35
34
|
"update-version-changelog": "yarn version-changelog ../../CHANGELOG.md"
|
|
36
35
|
},
|
|
37
36
|
"sideEffects": false,
|
|
38
|
-
"version": "3.20.1-alpha.
|
|
37
|
+
"version": "3.20.1-alpha.32",
|
|
39
38
|
"devDependencies": {
|
|
40
|
-
"@babel/preset-typescript": "^7.26.0",
|
|
41
|
-
"@rollup/plugin-babel": "^6.0.4",
|
|
42
39
|
"@rollup/plugin-commonjs": "^29.0.0",
|
|
43
|
-
"@rollup/plugin-
|
|
40
|
+
"@rollup/plugin-terser": "^0.4.4",
|
|
41
|
+
"@rollup/plugin-typescript": "^12.1.4",
|
|
44
42
|
"@types/react": "^17.0.2",
|
|
45
43
|
"autoprefixer": "^9.7.4",
|
|
46
44
|
"glob": "^7.1.6",
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { castArray } from '@lumx/core/js/utils/collection/castArray';
|
|
2
|
-
|
|
3
|
-
describe(castArray, () => {
|
|
4
|
-
it('should keep existing array', () => {
|
|
5
|
-
const input = [1, 2];
|
|
6
|
-
const output = castArray(input);
|
|
7
|
-
expect(output).toEqual([1, 2]);
|
|
8
|
-
expect(output).toBe(input);
|
|
9
|
-
});
|
|
10
|
-
it('should cast item to array', () => {
|
|
11
|
-
const input = 1;
|
|
12
|
-
const output = castArray(input);
|
|
13
|
-
expect(output).toEqual([1]);
|
|
14
|
-
});
|
|
15
|
-
});
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { castArray } from '@lumx/core/js/utils/collection/castArray';
|
|
2
|
-
|
|
3
|
-
describe(castArray, () => {
|
|
4
|
-
it('should keep existing array', () => {
|
|
5
|
-
const input = [1, 2];
|
|
6
|
-
const output = castArray(input);
|
|
7
|
-
expect(output).toEqual([1, 2]);
|
|
8
|
-
expect(output).toBe(input);
|
|
9
|
-
});
|
|
10
|
-
it('should cast item to array', () => {
|
|
11
|
-
const input = 1;
|
|
12
|
-
const output = castArray(input);
|
|
13
|
-
expect(output).toEqual([1]);
|
|
14
|
-
});
|
|
15
|
-
});
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
/** Chunk array in slices of given size */
|
|
2
|
-
function chunk(input, size) {
|
|
3
|
-
if (size <= 0) {
|
|
4
|
-
throw new Error('Size must be greater than 0');
|
|
5
|
-
}
|
|
6
|
-
const result = [];
|
|
7
|
-
for (let i = 0; i < input.length; i += size) {
|
|
8
|
-
result.push(input.slice(i, i + size));
|
|
9
|
-
}
|
|
10
|
-
return result;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export { chunk };
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { chunk } from '@lumx/core/js/utils/collection/chunk';
|
|
2
|
-
|
|
3
|
-
describe(chunk, () => {
|
|
4
|
-
it('should do nothing on empty array', () => {
|
|
5
|
-
expect(chunk([], 2)).toEqual([]);
|
|
6
|
-
});
|
|
7
|
-
it('should work with size larger than input array', () => {
|
|
8
|
-
expect(chunk([1, 2], 4)).toEqual([[1, 2]]);
|
|
9
|
-
});
|
|
10
|
-
it('should chunk array with size not perfectly dividing the array length', () => {
|
|
11
|
-
expect(chunk([1, 2, 3, 4, 5], 2)).toEqual([[1, 2], [3, 4], [5]]);
|
|
12
|
-
});
|
|
13
|
-
it('should chunk array with size perfectly dividing the array length', () => {
|
|
14
|
-
expect(chunk([1, 2, 3, 4], 2)).toEqual([[1, 2], [3, 4]]);
|
|
15
|
-
});
|
|
16
|
-
it('should work with size of 1', () => {
|
|
17
|
-
expect(chunk([1, 2, 3], 1)).toEqual([[1], [2], [3]]);
|
|
18
|
-
});
|
|
19
|
-
it('should work with size equal to array length', () => {
|
|
20
|
-
expect(chunk([1, 2, 3], 3)).toEqual([[1, 2, 3]]);
|
|
21
|
-
});
|
|
22
|
-
it('should throw error when size is 0', () => {
|
|
23
|
-
expect(() => chunk([1, 2, 3], 0)).toThrow('Size must be greater than 0');
|
|
24
|
-
});
|
|
25
|
-
it('should throw error when size is negative', () => {
|
|
26
|
-
expect(() => chunk([1, 2, 3], -1)).toThrow('Size must be greater than 0');
|
|
27
|
-
});
|
|
28
|
-
});
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import { chunk } from '@lumx/core/js/utils/collection/chunk';
|
|
2
|
-
|
|
3
|
-
describe(chunk, () => {
|
|
4
|
-
it('should do nothing on empty array', () => {
|
|
5
|
-
expect(chunk([], 2)).toEqual([]);
|
|
6
|
-
});
|
|
7
|
-
|
|
8
|
-
it('should work with size larger than input array', () => {
|
|
9
|
-
expect(chunk([1, 2], 4)).toEqual([[1, 2]]);
|
|
10
|
-
});
|
|
11
|
-
|
|
12
|
-
it('should chunk array with size not perfectly dividing the array length', () => {
|
|
13
|
-
expect(chunk([1, 2, 3, 4, 5], 2)).toEqual([[1, 2], [3, 4], [5]]);
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
it('should chunk array with size perfectly dividing the array length', () => {
|
|
17
|
-
expect(chunk([1, 2, 3, 4], 2)).toEqual([
|
|
18
|
-
[1, 2],
|
|
19
|
-
[3, 4],
|
|
20
|
-
]);
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
it('should work with size of 1', () => {
|
|
24
|
-
expect(chunk([1, 2, 3], 1)).toEqual([[1], [2], [3]]);
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
it('should work with size equal to array length', () => {
|
|
28
|
-
expect(chunk([1, 2, 3], 3)).toEqual([[1, 2, 3]]);
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
it('should throw error when size is 0', () => {
|
|
32
|
-
expect(() => chunk([1, 2, 3], 0)).toThrow('Size must be greater than 0');
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
it('should throw error when size is negative', () => {
|
|
36
|
-
expect(() => chunk([1, 2, 3], -1)).toThrow('Size must be greater than 0');
|
|
37
|
-
});
|
|
38
|
-
});
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
/** Chunk array in slices of given size */
|
|
2
|
-
export function chunk<T>(input: Array<T>, size: number): T[][] {
|
|
3
|
-
if (size <= 0) {
|
|
4
|
-
throw new Error('Size must be greater than 0');
|
|
5
|
-
}
|
|
6
|
-
const result: T[][] = [];
|
|
7
|
-
for (let i = 0; i < input.length; i += size) {
|
|
8
|
-
result.push(input.slice(i, i + size));
|
|
9
|
-
}
|
|
10
|
-
return result;
|
|
11
|
-
}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { isEmpty } from './isEmpty.js';
|
|
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
|
-
expect(isEmpty(false)).toBe(true);
|
|
10
|
-
});
|
|
11
|
-
it('should return true for empty object or array', () => {
|
|
12
|
-
expect(isEmpty([])).toBe(true);
|
|
13
|
-
expect(isEmpty({})).toBe(true);
|
|
14
|
-
});
|
|
15
|
-
it('should return false for non empty object or array', () => {
|
|
16
|
-
expect(isEmpty([''])).toBe(false);
|
|
17
|
-
expect(isEmpty({
|
|
18
|
-
foo: false
|
|
19
|
-
})).toBe(false);
|
|
20
|
-
});
|
|
21
|
-
});
|
|
@@ -1,21 +0,0 @@
|
|
|
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
|
-
expect(isEmpty(false)).toBe(true);
|
|
10
|
-
});
|
|
11
|
-
|
|
12
|
-
it('should return true for empty object or array', () => {
|
|
13
|
-
expect(isEmpty([])).toBe(true);
|
|
14
|
-
expect(isEmpty({})).toBe(true);
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
it('should return false for non empty object or array', () => {
|
|
18
|
-
expect(isEmpty([''])).toBe(false);
|
|
19
|
-
expect(isEmpty({ foo: false })).toBe(false);
|
|
20
|
-
});
|
|
21
|
-
});
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { last } from '@lumx/core/js/utils/collection/last';
|
|
2
|
-
|
|
3
|
-
describe(last, () => {
|
|
4
|
-
it('should return undefined for empty array', () => {
|
|
5
|
-
const input = [];
|
|
6
|
-
const output = last(input);
|
|
7
|
-
expect(output).toBeUndefined();
|
|
8
|
-
});
|
|
9
|
-
it('should return last element from array with single element', () => {
|
|
10
|
-
const input = [42];
|
|
11
|
-
const output = last(input);
|
|
12
|
-
expect(output).toBe(42);
|
|
13
|
-
});
|
|
14
|
-
it('should return last element from array with multiple elements', () => {
|
|
15
|
-
const input = [1, 2, 3, 4, 5];
|
|
16
|
-
const output = last(input);
|
|
17
|
-
expect(output).toBe(5);
|
|
18
|
-
});
|
|
19
|
-
});
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { last } from '@lumx/core/js/utils/collection/last';
|
|
2
|
-
|
|
3
|
-
describe(last, () => {
|
|
4
|
-
it('should return undefined for empty array', () => {
|
|
5
|
-
const input: number[] = [];
|
|
6
|
-
const output = last(input);
|
|
7
|
-
expect(output).toBeUndefined();
|
|
8
|
-
});
|
|
9
|
-
|
|
10
|
-
it('should return last element from array with single element', () => {
|
|
11
|
-
const input = [42];
|
|
12
|
-
const output = last(input);
|
|
13
|
-
expect(output).toBe(42);
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
it('should return last element from array with multiple elements', () => {
|
|
17
|
-
const input = [1, 2, 3, 4, 5];
|
|
18
|
-
const output = last(input);
|
|
19
|
-
expect(output).toBe(5);
|
|
20
|
-
});
|
|
21
|
-
});
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Similar to lodash `partition` function but working with multiple predicates.
|
|
3
|
-
*
|
|
4
|
-
* @example
|
|
5
|
-
* const isString = (s) => typeof s === 'string'
|
|
6
|
-
* const isNumber = (s) => typeof s === 'number'
|
|
7
|
-
* const [strings, numbers, others] = partitionMulti(['a', 1, 'b', false], [isString, isNumber])
|
|
8
|
-
* //=> [['a', 'b'], [1], [false]]
|
|
9
|
-
*
|
|
10
|
-
* @param elements array of elements
|
|
11
|
-
* @param predicates array of predicates to apply on elements
|
|
12
|
-
* @return partitioned elements by the given predicates
|
|
13
|
-
*/
|
|
14
|
-
function partitionMulti(elements, predicates) {
|
|
15
|
-
const others = [];
|
|
16
|
-
const groups = predicates.map(() => []);
|
|
17
|
-
for (const element of elements) {
|
|
18
|
-
const index = predicates.findIndex(predicate => predicate(element));
|
|
19
|
-
if (index !== -1) {
|
|
20
|
-
groups[index].push(element);
|
|
21
|
-
} else {
|
|
22
|
-
others.push(element);
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
return [...groups, others];
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export { partitionMulti };
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { partitionMulti } from './partitionMulti.js';
|
|
2
|
-
|
|
3
|
-
describe('partitionMulti', () => {
|
|
4
|
-
it('should partition with single predicate', () => {
|
|
5
|
-
const data = [0, 1, 2, 3, 4, 5];
|
|
6
|
-
const isEven = n => n % 2 === 0;
|
|
7
|
-
const actual = partitionMulti(data, [isEven]);
|
|
8
|
-
expect(actual).toEqual([[0, 2, 4], [1, 3, 5]]);
|
|
9
|
-
});
|
|
10
|
-
it('should partition on multiple predicates', () => {
|
|
11
|
-
const data = ['a', 1, 'b', false, true];
|
|
12
|
-
const isString = s => typeof s === 'string';
|
|
13
|
-
const isNumber = s => typeof s === 'number';
|
|
14
|
-
const isNull = s => s === null;
|
|
15
|
-
const partitions = partitionMulti(data, [isString, isNumber, isNull]);
|
|
16
|
-
expect(partitions).toEqual([
|
|
17
|
-
// strings
|
|
18
|
-
['a', 'b'],
|
|
19
|
-
// numbers
|
|
20
|
-
[1],
|
|
21
|
-
// nulls
|
|
22
|
-
[],
|
|
23
|
-
// others
|
|
24
|
-
[false, true]]);
|
|
25
|
-
});
|
|
26
|
-
});
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import { partitionMulti } from './partitionMulti';
|
|
2
|
-
|
|
3
|
-
describe('partitionMulti', () => {
|
|
4
|
-
it('should partition with single predicate', () => {
|
|
5
|
-
const data = [0, 1, 2, 3, 4, 5];
|
|
6
|
-
const isEven = (n: number): boolean => n % 2 === 0;
|
|
7
|
-
|
|
8
|
-
const actual = partitionMulti(data, [isEven]);
|
|
9
|
-
|
|
10
|
-
expect(actual).toEqual([
|
|
11
|
-
[0, 2, 4],
|
|
12
|
-
[1, 3, 5],
|
|
13
|
-
]);
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
it('should partition on multiple predicates', () => {
|
|
17
|
-
type T = string | number | boolean;
|
|
18
|
-
const data: T[] = ['a', 1, 'b', false, true];
|
|
19
|
-
const isString = (s: T): boolean => typeof s === 'string';
|
|
20
|
-
const isNumber = (s: T): boolean => typeof s === 'number';
|
|
21
|
-
const isNull = (s: T): boolean => s === null;
|
|
22
|
-
|
|
23
|
-
const partitions = partitionMulti(data, [isString, isNumber, isNull]);
|
|
24
|
-
expect(partitions).toEqual([
|
|
25
|
-
// strings
|
|
26
|
-
['a', 'b'],
|
|
27
|
-
// numbers
|
|
28
|
-
[1],
|
|
29
|
-
// nulls
|
|
30
|
-
[],
|
|
31
|
-
// others
|
|
32
|
-
[false, true],
|
|
33
|
-
]);
|
|
34
|
-
});
|
|
35
|
-
});
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import type { Predicate } from '@lumx/core/js/types';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Similar to lodash `partition` function but working with multiple predicates.
|
|
5
|
-
*
|
|
6
|
-
* @example
|
|
7
|
-
* const isString = (s) => typeof s === 'string'
|
|
8
|
-
* const isNumber = (s) => typeof s === 'number'
|
|
9
|
-
* const [strings, numbers, others] = partitionMulti(['a', 1, 'b', false], [isString, isNumber])
|
|
10
|
-
* //=> [['a', 'b'], [1], [false]]
|
|
11
|
-
*
|
|
12
|
-
* @param elements array of elements
|
|
13
|
-
* @param predicates array of predicates to apply on elements
|
|
14
|
-
* @return partitioned elements by the given predicates
|
|
15
|
-
*/
|
|
16
|
-
export function partitionMulti<T>(elements: T[], predicates: Array<Predicate<T>>): T[][] {
|
|
17
|
-
const others = [] as T[];
|
|
18
|
-
const groups = predicates.map(() => []) as T[][];
|
|
19
|
-
|
|
20
|
-
for (const element of elements) {
|
|
21
|
-
const index = predicates.findIndex((predicate) => predicate(element));
|
|
22
|
-
if (index !== -1) {
|
|
23
|
-
groups[index].push(element);
|
|
24
|
-
} else {
|
|
25
|
-
others.push(element);
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
return [...groups, others];
|
|
29
|
-
}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { range } from './range.js';
|
|
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,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,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
|
-
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 };
|
|
@@ -1,41 +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
|
-
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
|
-
});
|
|
@@ -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
|
-
}
|