@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,34 +0,0 @@
1
- 'use strict';
2
-
3
- var js_utils_className_handleBasicClasses = require('./handleBasicClasses.js');
4
- require('classnames');
5
- require('../collection/isEmpty.js');
6
- require('./getBasicClass.js');
7
- require('../string/kebabCase.js');
8
-
9
- describe(js_utils_className_handleBasicClasses.handleBasicClasses, () => {
10
- it('should return correct combined CSS classes based on props', () => {
11
- const className = js_utils_className_handleBasicClasses.handleBasicClasses({
12
- prefix: 'test',
13
- // Undefined
14
- undefined,
15
- // Null
16
- null: null,
17
- // Empty string
18
- emptyString: '',
19
- // Empty array
20
- emptyArray: [],
21
- // Empty object
22
- emptyObject: {},
23
- // String
24
- color: 'red',
25
- // False property
26
- isDisabled: false,
27
- // Boolean without a prefix (is or has)
28
- visible: true,
29
- // Has prefix
30
- hasButton: true,
31
- });
32
- expect(className).toBe('test test--color-red test--is-visible test--has-button');
33
- });
34
- });
@@ -1 +0,0 @@
1
- "use strict";var e=require("./handleBasicClasses.min.js");require("classnames"),require("../collection/isEmpty.min.js"),require("./getBasicClass.min.js"),require("../string/kebabCase.min.js"),describe(e.handleBasicClasses,()=>{it("should return correct combined CSS classes based on props",()=>{const s=e.handleBasicClasses({prefix:"test",undefined:void 0,null:null,emptyString:"",emptyArray:[],emptyObject:{},color:"red",isDisabled:!1,visible:!0,hasButton:!0});expect(s).toBe("test test--color-red test--is-visible test--has-button")})});
@@ -1,28 +0,0 @@
1
- import { handleBasicClasses } from './handleBasicClasses';
2
-
3
- describe(handleBasicClasses, () => {
4
- it('should return correct combined CSS classes based on props', () => {
5
- const className = handleBasicClasses({
6
- prefix: 'test',
7
- // Undefined
8
- undefined,
9
- // Null
10
- null: null,
11
- // Empty string
12
- emptyString: '',
13
- // Empty array
14
- emptyArray: [],
15
- // Empty object
16
- emptyObject: {},
17
- // String
18
- color: 'red',
19
- // False property
20
- isDisabled: false,
21
- // Boolean without a prefix (is or has)
22
- visible: true,
23
- // Has prefix
24
- hasButton: true,
25
- });
26
- expect(className).toBe('test test--color-red test--is-visible test--has-button');
27
- });
28
- });
@@ -1,42 +0,0 @@
1
- import classNames from 'classnames';
2
-
3
- import { isEmpty } from '@lumx/core/js/utils/collection/isEmpty';
4
-
5
- import { getBasicClass } from './getBasicClass';
6
-
7
- /**
8
- * Enhance isEmpty method to also works with numbers.
9
- *
10
- * @param value The value to check.
11
- * @return Whether the input value is empty or != 0.
12
- */
13
- const _isEmpty = (value: any) => {
14
- if (typeof value === 'number') {
15
- return value === 0;
16
- }
17
-
18
- return isEmpty(value);
19
- };
20
-
21
- /**
22
- * Return all basic LumX CSS classes which are available for every components.
23
- *
24
- * @see {@link /src/components/index.d.ts} for the possible values of each parameter.
25
- *
26
- * @param prefix The class name prefix for the generated CSS class.
27
- * @param props All the other props you want to generate a class.
28
- * The rule of thumb: the key is the name of the prop in the class, the value a string that will
29
- * be used in the classname to represent the value of the given prop.
30
- * @return All LumX basic CSS classes.
31
- */
32
- export function handleBasicClasses({ prefix, ...props }: { prefix: string; [prop: string]: any }): string {
33
- const otherClasses: any = {};
34
- if (!isEmpty(props)) {
35
- Object.keys(props).forEach((prop) => {
36
- otherClasses[getBasicClass({ prefix, type: prop, value: props[prop] })] =
37
- typeof props[prop] === 'boolean' ? props[prop] : !_isEmpty(props[prop]);
38
- });
39
- }
40
-
41
- return classNames(prefix, otherClasses);
42
- }
@@ -1 +0,0 @@
1
- "use strict";var s=require("./handleBasicClasses.min.js"),e=require("./getBasicClass.min.js"),a=require("./getRootClassName.min.js"),r=require("./getTypographyClassName.min.js"),i=require("./fontColorClass.min.js"),o=require("./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=s.handleBasicClasses,exports.getBasicClass=e.getBasicClass,exports.getRootClassName=a.getRootClassName,exports.getTypographyClassName=r.getTypographyClassName,exports.fontColorClass=i.fontColorClass,exports.resolveColorWithVariants=o.resolveColorWithVariants;
@@ -1 +0,0 @@
1
- "use strict";exports.resolveColorWithVariants=function(t,r){if(!t)return[void 0,r];const[i,o]=t.split("-");return[i,r||o]};
@@ -1,30 +0,0 @@
1
- 'use strict';
2
-
3
- var js_utils_className_resolveColorWithVariants = require('./resolveColorWithVariants.js');
4
-
5
- describe(js_utils_className_resolveColorWithVariants.resolveColorWithVariants, () => {
6
- it('should handle undefined color', () => {
7
- const result = js_utils_className_resolveColorWithVariants.resolveColorWithVariants(undefined);
8
- expect(result).toEqual([undefined, undefined]);
9
- });
10
- it('should handle undefined color with variant', () => {
11
- const result = js_utils_className_resolveColorWithVariants.resolveColorWithVariants(undefined, 'L2');
12
- expect(result).toEqual([undefined, 'L2']);
13
- });
14
- it('should handle color with undefined variant', () => {
15
- const result = js_utils_className_resolveColorWithVariants.resolveColorWithVariants('primary');
16
- expect(result).toEqual(['primary', undefined]);
17
- });
18
- it('should handle color & variant separated', () => {
19
- const result = js_utils_className_resolveColorWithVariants.resolveColorWithVariants('primary', 'L2');
20
- expect(result).toEqual(['primary', 'L2']);
21
- });
22
- it('should handle color with variant all in one', () => {
23
- const result = js_utils_className_resolveColorWithVariants.resolveColorWithVariants('primary-L2');
24
- expect(result).toEqual(['primary', 'L2']);
25
- });
26
- it('should override color variant with the given color variant', () => {
27
- const result = js_utils_className_resolveColorWithVariants.resolveColorWithVariants('primary-L2', 'D2');
28
- expect(result).toEqual(['primary', 'D2']);
29
- });
30
- });
@@ -1 +0,0 @@
1
- "use strict";var o=require("./resolveColorWithVariants.min.js");describe(o.resolveColorWithVariants,()=>{it("should handle undefined color",()=>{const r=o.resolveColorWithVariants(void 0);expect(r).toEqual([void 0,void 0])}),it("should handle undefined color with variant",()=>{const r=o.resolveColorWithVariants(void 0,"L2");expect(r).toEqual([void 0,"L2"])}),it("should handle color with undefined variant",()=>{const r=o.resolveColorWithVariants("primary");expect(r).toEqual(["primary",void 0])}),it("should handle color & variant separated",()=>{const r=o.resolveColorWithVariants("primary","L2");expect(r).toEqual(["primary","L2"])}),it("should handle color with variant all in one",()=>{const r=o.resolveColorWithVariants("primary-L2");expect(r).toEqual(["primary","L2"])}),it("should override color variant with the given color variant",()=>{const r=o.resolveColorWithVariants("primary-L2","D2");expect(r).toEqual(["primary","D2"])})});
@@ -1,33 +0,0 @@
1
- import { resolveColorWithVariants } from './resolveColorWithVariants';
2
-
3
- describe(resolveColorWithVariants, () => {
4
- it('should handle undefined color', () => {
5
- const result = resolveColorWithVariants(undefined);
6
- expect(result).toEqual([undefined, undefined]);
7
- });
8
-
9
- it('should handle undefined color with variant', () => {
10
- const result = resolveColorWithVariants(undefined, 'L2');
11
- expect(result).toEqual([undefined, 'L2']);
12
- });
13
-
14
- it('should handle color with undefined variant', () => {
15
- const result = resolveColorWithVariants('primary');
16
- expect(result).toEqual(['primary', undefined]);
17
- });
18
-
19
- it('should handle color & variant separated', () => {
20
- const result = resolveColorWithVariants('primary', 'L2');
21
- expect(result).toEqual(['primary', 'L2']);
22
- });
23
-
24
- it('should handle color with variant all in one', () => {
25
- const result = resolveColorWithVariants('primary-L2');
26
- expect(result).toEqual(['primary', 'L2']);
27
- });
28
-
29
- it('should override color variant with the given color variant', () => {
30
- const result = resolveColorWithVariants('primary-L2', 'D2');
31
- expect(result).toEqual(['primary', 'D2']);
32
- });
33
- });
@@ -1,11 +0,0 @@
1
- import { ColorPalette, ColorVariant, ColorWithVariants } from '../../constants';
2
-
3
- /** Resolve color & color variant from a `ColorWithVariants` and optionally a `ColorVariant`. */
4
- export function resolveColorWithVariants(
5
- colorWithVariants?: ColorWithVariants,
6
- colorVariant?: ColorVariant,
7
- ): [color?: ColorPalette, colorVariant?: ColorVariant] {
8
- if (!colorWithVariants) return [undefined, colorVariant];
9
- const [color, baseColorVariant] = colorWithVariants.split('-');
10
- return [color as ColorPalette, (colorVariant || baseColorVariant) as ColorVariant];
11
- }
@@ -1,6 +0,0 @@
1
- 'use strict';
2
-
3
- /** Cast a value into an array if needed */
4
- const castArray = (arrayOrElement) => Array.isArray(arrayOrElement) ? arrayOrElement : [arrayOrElement];
5
-
6
- exports.castArray = castArray;
@@ -1 +0,0 @@
1
- "use strict";exports.castArray=r=>Array.isArray(r)?r:[r];
@@ -1,17 +0,0 @@
1
- 'use strict';
2
-
3
- var js_utils_collection_castArray = require('./castArray.js');
4
-
5
- describe(js_utils_collection_castArray.castArray, () => {
6
- it('should keep existing array', () => {
7
- const input = [1, 2];
8
- const output = js_utils_collection_castArray.castArray(input);
9
- expect(output).toEqual([1, 2]);
10
- expect(output).toBe(input);
11
- });
12
- it('should cast item to array', () => {
13
- const input = 1;
14
- const output = js_utils_collection_castArray.castArray(input);
15
- expect(output).toEqual([1]);
16
- });
17
- });
@@ -1 +0,0 @@
1
- "use strict";var t=require("./castArray.min.js");describe(t.castArray,()=>{it("should keep existing array",()=>{const r=[1,2],a=t.castArray(r);expect(a).toEqual([1,2]),expect(a).toBe(r)}),it("should cast item to array",()=>{const r=t.castArray(1);expect(r).toEqual([1])})});
@@ -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,3 +0,0 @@
1
- /** Cast a value into an array if needed */
2
- export const castArray = <T>(arrayOrElement: T[] | T) =>
3
- Array.isArray(arrayOrElement) ? arrayOrElement : [arrayOrElement];
@@ -1,15 +0,0 @@
1
- 'use strict';
2
-
3
- /** Chunk array in slices of given size */
4
- function chunk(input, size) {
5
- if (size <= 0) {
6
- throw new Error('Size must be greater than 0');
7
- }
8
- const result = [];
9
- for (let i = 0; i < input.length; i += size) {
10
- result.push(input.slice(i, i + size));
11
- }
12
- return result;
13
- }
14
-
15
- exports.chunk = chunk;
@@ -1 +0,0 @@
1
- "use strict";exports.chunk=function(t,e){if(e<=0)throw new Error("Size must be greater than 0");const r=[];for(let n=0;n<t.length;n+=e)r.push(t.slice(n,n+e));return r};
@@ -1,33 +0,0 @@
1
- 'use strict';
2
-
3
- var js_utils_collection_chunk = require('./chunk.js');
4
-
5
- describe(js_utils_collection_chunk.chunk, () => {
6
- it('should do nothing on empty array', () => {
7
- expect(js_utils_collection_chunk.chunk([], 2)).toEqual([]);
8
- });
9
- it('should work with size larger than input array', () => {
10
- expect(js_utils_collection_chunk.chunk([1, 2], 4)).toEqual([[1, 2]]);
11
- });
12
- it('should chunk array with size not perfectly dividing the array length', () => {
13
- expect(js_utils_collection_chunk.chunk([1, 2, 3, 4, 5], 2)).toEqual([[1, 2], [3, 4], [5]]);
14
- });
15
- it('should chunk array with size perfectly dividing the array length', () => {
16
- expect(js_utils_collection_chunk.chunk([1, 2, 3, 4], 2)).toEqual([
17
- [1, 2],
18
- [3, 4],
19
- ]);
20
- });
21
- it('should work with size of 1', () => {
22
- expect(js_utils_collection_chunk.chunk([1, 2, 3], 1)).toEqual([[1], [2], [3]]);
23
- });
24
- it('should work with size equal to array length', () => {
25
- expect(js_utils_collection_chunk.chunk([1, 2, 3], 3)).toEqual([[1, 2, 3]]);
26
- });
27
- it('should throw error when size is 0', () => {
28
- expect(() => js_utils_collection_chunk.chunk([1, 2, 3], 0)).toThrow('Size must be greater than 0');
29
- });
30
- it('should throw error when size is negative', () => {
31
- expect(() => js_utils_collection_chunk.chunk([1, 2, 3], -1)).toThrow('Size must be greater than 0');
32
- });
33
- });
@@ -1 +0,0 @@
1
- "use strict";var e=require("./chunk.min.js");describe(e.chunk,()=>{it("should do nothing on empty array",()=>{expect(e.chunk([],2)).toEqual([])}),it("should work with size larger than input array",()=>{expect(e.chunk([1,2],4)).toEqual([[1,2]])}),it("should chunk array with size not perfectly dividing the array length",()=>{expect(e.chunk([1,2,3,4,5],2)).toEqual([[1,2],[3,4],[5]])}),it("should chunk array with size perfectly dividing the array length",()=>{expect(e.chunk([1,2,3,4],2)).toEqual([[1,2],[3,4]])}),it("should work with size of 1",()=>{expect(e.chunk([1,2,3],1)).toEqual([[1],[2],[3]])}),it("should work with size equal to array length",()=>{expect(e.chunk([1,2,3],3)).toEqual([[1,2,3]])}),it("should throw error when size is 0",()=>{expect(()=>e.chunk([1,2,3],0)).toThrow("Size must be greater than 0")}),it("should throw error when size is negative",()=>{expect(()=>e.chunk([1,2,3],-1)).toThrow("Size must be greater than 0")})});
@@ -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,6 +0,0 @@
1
- 'use strict';
2
-
3
- /** Check if object or array is empty (true on falsy values) */
4
- const isEmpty = (obj) => !obj || Object.entries(obj).length === 0;
5
-
6
- exports.isEmpty = isEmpty;
@@ -1 +0,0 @@
1
- "use strict";exports.isEmpty=t=>!t||0===Object.entries(t).length;
@@ -1,21 +0,0 @@
1
- 'use strict';
2
-
3
- var js_utils_collection_isEmpty = require('./isEmpty.js');
4
-
5
- describe(js_utils_collection_isEmpty.isEmpty, () => {
6
- it('should return true for falsy values', () => {
7
- expect(js_utils_collection_isEmpty.isEmpty(undefined)).toBe(true);
8
- expect(js_utils_collection_isEmpty.isEmpty(null)).toBe(true);
9
- expect(js_utils_collection_isEmpty.isEmpty(0)).toBe(true);
10
- expect(js_utils_collection_isEmpty.isEmpty('')).toBe(true);
11
- expect(js_utils_collection_isEmpty.isEmpty(false)).toBe(true);
12
- });
13
- it('should return true for empty object or array', () => {
14
- expect(js_utils_collection_isEmpty.isEmpty([])).toBe(true);
15
- expect(js_utils_collection_isEmpty.isEmpty({})).toBe(true);
16
- });
17
- it('should return false for non empty object or array', () => {
18
- expect(js_utils_collection_isEmpty.isEmpty([''])).toBe(false);
19
- expect(js_utils_collection_isEmpty.isEmpty({ foo: false })).toBe(false);
20
- });
21
- });
@@ -1 +0,0 @@
1
- "use strict";var e=require("./isEmpty.min.js");describe(e.isEmpty,()=>{it("should return true for falsy values",()=>{expect(e.isEmpty(void 0)).toBe(!0),expect(e.isEmpty(null)).toBe(!0),expect(e.isEmpty(0)).toBe(!0),expect(e.isEmpty("")).toBe(!0),expect(e.isEmpty(!1)).toBe(!0)}),it("should return true for empty object or array",()=>{expect(e.isEmpty([])).toBe(!0),expect(e.isEmpty({})).toBe(!0)}),it("should return false for non empty object or array",()=>{expect(e.isEmpty([""])).toBe(!1),expect(e.isEmpty({foo:!1})).toBe(!1)})});
@@ -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,4 +0,0 @@
1
- import type { Falsy } from '../../types';
2
-
3
- /** Check if object or array is empty (true on falsy values) */
4
- export const isEmpty = (obj: NonNullable<unknown> | Falsy) => !obj || Object.entries(obj).length === 0;
@@ -1,6 +0,0 @@
1
- 'use strict';
2
-
3
- /** Get last item from array */
4
- const last = (array) => array[array.length - 1];
5
-
6
- exports.last = last;
@@ -1 +0,0 @@
1
- "use strict";exports.last=t=>t[t.length-1];
@@ -1,21 +0,0 @@
1
- 'use strict';
2
-
3
- var js_utils_collection_last = require('./last.js');
4
-
5
- describe(js_utils_collection_last.last, () => {
6
- it('should return undefined for empty array', () => {
7
- const input = [];
8
- const output = js_utils_collection_last.last(input);
9
- expect(output).toBeUndefined();
10
- });
11
- it('should return last element from array with single element', () => {
12
- const input = [42];
13
- const output = js_utils_collection_last.last(input);
14
- expect(output).toBe(42);
15
- });
16
- it('should return last element from array with multiple elements', () => {
17
- const input = [1, 2, 3, 4, 5];
18
- const output = js_utils_collection_last.last(input);
19
- expect(output).toBe(5);
20
- });
21
- });
@@ -1 +0,0 @@
1
- "use strict";var e=require("./last.min.js");describe(e.last,()=>{it("should return undefined for empty array",()=>{const t=e.last([]);expect(t).toBeUndefined()}),it("should return last element from array with single element",()=>{const t=e.last([42]);expect(t).toBe(42)}),it("should return last element from array with multiple elements",()=>{const t=e.last([1,2,3,4,5]);expect(t).toBe(5)})});
@@ -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,2 +0,0 @@
1
- /** Get last item from array */
2
- export const last = <T>(array: Array<T>): T | undefined => array[array.length - 1];
@@ -1,31 +0,0 @@
1
- 'use strict';
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
- function partitionMulti(elements, predicates) {
17
- const others = [];
18
- const groups = predicates.map(() => []);
19
- for (const element of elements) {
20
- const index = predicates.findIndex((predicate) => predicate(element));
21
- if (index !== -1) {
22
- groups[index].push(element);
23
- }
24
- else {
25
- others.push(element);
26
- }
27
- }
28
- return [...groups, others];
29
- }
30
-
31
- exports.partitionMulti = partitionMulti;
@@ -1 +0,0 @@
1
- "use strict";exports.partitionMulti=function(t,n){const o=[],s=n.map(()=>[]);for(const i of t){const t=n.findIndex(t=>t(i));-1!==t?s[t].push(i):o.push(i)}return[...s,o]};
@@ -1,32 +0,0 @@
1
- 'use strict';
2
-
3
- var js_utils_collection_partitionMulti = require('./partitionMulti.js');
4
-
5
- describe('partitionMulti', () => {
6
- it('should partition with single predicate', () => {
7
- const data = [0, 1, 2, 3, 4, 5];
8
- const isEven = (n) => n % 2 === 0;
9
- const actual = js_utils_collection_partitionMulti.partitionMulti(data, [isEven]);
10
- expect(actual).toEqual([
11
- [0, 2, 4],
12
- [1, 3, 5],
13
- ]);
14
- });
15
- it('should partition on multiple predicates', () => {
16
- const data = ['a', 1, 'b', false, true];
17
- const isString = (s) => typeof s === 'string';
18
- const isNumber = (s) => typeof s === 'number';
19
- const isNull = (s) => s === null;
20
- const partitions = js_utils_collection_partitionMulti.partitionMulti(data, [isString, isNumber, isNull]);
21
- expect(partitions).toEqual([
22
- // strings
23
- ['a', 'b'],
24
- // numbers
25
- [1],
26
- // nulls
27
- [],
28
- // others
29
- [false, true],
30
- ]);
31
- });
32
- });
@@ -1 +0,0 @@
1
- "use strict";var t=require("./partitionMulti.min.js");describe("partitionMulti",()=>{it("should partition with single predicate",()=>{const i=t.partitionMulti([0,1,2,3,4,5],[t=>t%2==0]);expect(i).toEqual([[0,2,4],[1,3,5]])}),it("should partition on multiple predicates",()=>{const i=t.partitionMulti(["a",1,"b",!1,!0],[t=>"string"==typeof t,t=>"number"==typeof t,t=>null===t]);expect(i).toEqual([["a","b"],[1],[],[!1,!0]])})});
@@ -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,6 +0,0 @@
1
- 'use strict';
2
-
3
- /** Generate a range of number starting at 0 and ending before the given number */
4
- const range = (end) => Array.from({ length: end }, (_, i) => i);
5
-
6
- exports.range = range;