@lumx/core 3.20.1-alpha.36 → 3.20.1-alpha.38
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/utils/className/getBasicClass.js +5 -6
- package/js/utils/className/getBasicClass.min.js +1 -1
- package/js/utils/className/getBasicClass.test.js +1 -2
- package/js/utils/className/getBasicClass.test.min.js +1 -1
- package/js/utils/className/getBasicClass.ts +2 -3
- package/js/utils/className/getRootClassName.js +2 -2
- package/js/utils/className/getRootClassName.min.js +1 -1
- package/js/utils/className/getRootClassName.test.js +1 -1
- package/js/utils/className/getRootClassName.test.min.js +1 -1
- package/js/utils/className/getRootClassName.ts +1 -2
- package/js/utils/className/handleBasicClasses.js +6 -8
- package/js/utils/className/handleBasicClasses.min.js +1 -1
- package/js/utils/className/handleBasicClasses.test.js +2 -3
- package/js/utils/className/handleBasicClasses.test.min.js +1 -1
- package/js/utils/className/handleBasicClasses.ts +3 -5
- package/js/utils/className/index.js +2 -3
- package/js/utils/className/index.min.js +1 -1
- package/js/utils/collection/castArray.js +6 -0
- package/js/utils/collection/castArray.min.js +1 -0
- package/js/utils/collection/castArray.test.js +17 -0
- package/js/utils/collection/castArray.test.min.js +1 -0
- package/js/utils/collection/castArray.test.ts +15 -0
- package/js/utils/collection/castArray.ts +3 -0
- package/js/utils/collection/chunk.js +15 -0
- package/js/utils/collection/chunk.min.js +1 -0
- package/js/utils/collection/chunk.test.js +33 -0
- package/js/utils/collection/chunk.test.min.js +1 -0
- package/js/utils/collection/chunk.test.ts +38 -0
- package/js/utils/collection/chunk.ts +11 -0
- package/js/utils/collection/isEmpty.js +6 -0
- package/js/utils/collection/isEmpty.min.js +1 -0
- package/js/utils/collection/isEmpty.test.js +21 -0
- package/js/utils/collection/isEmpty.test.min.js +1 -0
- package/js/utils/collection/isEmpty.test.ts +21 -0
- package/js/utils/collection/isEmpty.ts +4 -0
- package/js/utils/collection/last.js +6 -0
- package/js/utils/collection/last.min.js +1 -0
- package/js/utils/collection/last.test.js +21 -0
- package/js/utils/collection/last.test.min.js +1 -0
- package/js/utils/collection/last.test.ts +21 -0
- package/js/utils/collection/last.ts +2 -0
- package/js/utils/collection/partitionMulti.js +31 -0
- package/js/utils/collection/partitionMulti.min.js +1 -0
- package/js/utils/collection/partitionMulti.test.js +32 -0
- package/js/utils/collection/partitionMulti.test.min.js +1 -0
- package/js/utils/collection/partitionMulti.test.ts +35 -0
- package/js/utils/collection/partitionMulti.ts +29 -0
- package/js/utils/collection/range.js +6 -0
- package/js/utils/collection/range.min.js +1 -0
- package/js/utils/collection/range.test.js +12 -0
- package/js/utils/collection/range.test.min.js +1 -0
- package/js/utils/collection/range.test.ts +10 -0
- package/js/utils/collection/range.ts +2 -0
- package/js/utils/index.js +6 -8
- package/js/utils/index.min.js +1 -1
- package/js/utils/index.ts +4 -6
- package/js/utils/string/kebabCase.js +30 -0
- package/js/utils/string/kebabCase.min.js +1 -0
- package/js/utils/string/kebabCase.test.js +43 -0
- package/js/utils/string/kebabCase.test.min.js +1 -0
- package/js/utils/string/kebabCase.test.ts +50 -0
- package/js/utils/string/kebabCase.ts +28 -0
- package/package.json +1 -1
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
var kebabCase = require('lodash/kebabCase');
|
|
3
|
+
var js_utils_string_kebabCase = require('../string/kebabCase.js');
|
|
5
4
|
|
|
6
5
|
/**
|
|
7
6
|
* Get the basic CSS class for the given type.
|
|
@@ -12,18 +11,18 @@ var kebabCase = require('lodash/kebabCase');
|
|
|
12
11
|
* @return The basic CSS class.
|
|
13
12
|
*/
|
|
14
13
|
function getBasicClass({ prefix, type, value, }) {
|
|
15
|
-
if (
|
|
14
|
+
if (typeof value === 'boolean') {
|
|
16
15
|
if (!value) {
|
|
17
16
|
// False value should not return a class.
|
|
18
17
|
return '';
|
|
19
18
|
}
|
|
20
19
|
const booleanPrefixes = ['has', 'is'];
|
|
21
20
|
if (booleanPrefixes.some((booleanPrefix) => type.toString().startsWith(booleanPrefix))) {
|
|
22
|
-
return `${prefix}--${kebabCase(type)}`;
|
|
21
|
+
return `${prefix}--${js_utils_string_kebabCase.kebabCase(type)}`;
|
|
23
22
|
}
|
|
24
|
-
return `${prefix}--is-${kebabCase(type)}`;
|
|
23
|
+
return `${prefix}--is-${js_utils_string_kebabCase.kebabCase(type)}`;
|
|
25
24
|
}
|
|
26
|
-
return `${prefix}--${kebabCase(type)}-${value}`;
|
|
25
|
+
return `${prefix}--${js_utils_string_kebabCase.kebabCase(type)}-${value}`;
|
|
27
26
|
}
|
|
28
27
|
|
|
29
28
|
exports.getBasicClass = getBasicClass;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var e=require("
|
|
1
|
+
"use strict";var e=require("../string/kebabCase.min.js");exports.getBasicClass=function({prefix:s,type:t,value:a}){if("boolean"==typeof a){if(!a)return"";return["has","is"].some(e=>t.toString().startsWith(e))?`${s}--${e.kebabCase(t)}`:`${s}--is-${e.kebabCase(t)}`}return`${s}--${e.kebabCase(t)}-${a}`};
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var js_utils_className_getBasicClass = require('./getBasicClass.js');
|
|
4
|
-
require('
|
|
5
|
-
require('lodash/kebabCase');
|
|
4
|
+
require('../string/kebabCase.js');
|
|
6
5
|
|
|
7
6
|
describe(js_utils_className_getBasicClass.getBasicClass, () => {
|
|
8
7
|
it('should return correct basic CSS class for different types and values', () => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var e=require("./getBasicClass.min.js");require("
|
|
1
|
+
"use strict";var e=require("./getBasicClass.min.js");require("../string/kebabCase.min.js"),describe(e.getBasicClass,()=>{it("should return correct basic CSS class for different types and values",()=>{expect(e.getBasicClass({prefix:"test",type:"color",value:"primary"})).toBe("test--color-primary"),expect(e.getBasicClass({prefix:"test",type:"variant",value:"button"})).toBe("test--variant-button"),expect(e.getBasicClass({prefix:"test",type:"isDark",value:!0})).toBe("test--is-dark"),expect(e.getBasicClass({prefix:"test",type:"dark",value:!0})).toBe("test--is-dark"),expect(e.getBasicClass({prefix:"test",type:"hasDark",value:!0})).toBe("test--has-dark"),expect(e.getBasicClass({prefix:"test",type:"isActive",value:!1})).toBe(""),expect(e.getBasicClass({prefix:"test",type:"hasBorder",value:!0})).toBe("test--has-border"),expect(e.getBasicClass({prefix:"test",type:"isVisible",value:!1})).toBe(""),expect(e.getBasicClass({prefix:"test",type:"variant",value:void 0})).toBe("test--variant-undefined")})});
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import
|
|
2
|
-
import kebabCase from 'lodash/kebabCase';
|
|
1
|
+
import { kebabCase } from '../string/kebabCase';
|
|
3
2
|
|
|
4
3
|
/**
|
|
5
4
|
* Get the basic CSS class for the given type.
|
|
@@ -18,7 +17,7 @@ export function getBasicClass({
|
|
|
18
17
|
type: string;
|
|
19
18
|
value: string | number | boolean | undefined;
|
|
20
19
|
}): string {
|
|
21
|
-
if (
|
|
20
|
+
if (typeof value === 'boolean') {
|
|
22
21
|
if (!value) {
|
|
23
22
|
// False value should not return a class.
|
|
24
23
|
return '';
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var kebabCase = require('lodash/kebabCase');
|
|
4
3
|
var js_constants_index = require('../../constants/index.js');
|
|
4
|
+
var js_utils_string_kebabCase = require('../string/kebabCase.js');
|
|
5
5
|
require('../../constants/keycodes.js');
|
|
6
6
|
|
|
7
7
|
// See https://regex101.com/r/YjS1uI/3
|
|
@@ -17,7 +17,7 @@ const LAST_PART_CLASSNAME = /^(.*)-(.+)$/gi;
|
|
|
17
17
|
* lower-snake-case.
|
|
18
18
|
*/
|
|
19
19
|
function getRootClassName(componentName, subComponent) {
|
|
20
|
-
const formattedClassName = `${js_constants_index.CSS_PREFIX}-${kebabCase(componentName)}`;
|
|
20
|
+
const formattedClassName = `${js_constants_index.CSS_PREFIX}-${js_utils_string_kebabCase.kebabCase(componentName)}`;
|
|
21
21
|
if (subComponent) {
|
|
22
22
|
return formattedClassName.replace(LAST_PART_CLASSNAME, '$1__$2');
|
|
23
23
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var e=require("
|
|
1
|
+
"use strict";var e=require("../../constants/index.min.js"),s=require("../string/kebabCase.min.js");require("../../constants/keycodes.min.js");const n=/^(.*)-(.+)$/gi;exports.getRootClassName=function(t,r){const i=`${e.CSS_PREFIX}-${s.kebabCase(t)}`;return r?i.replace(n,"$1__$2"):i};
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var js_utils_className_getRootClassName = require('./getRootClassName.js');
|
|
4
|
-
require('lodash/kebabCase');
|
|
5
4
|
require('../../constants/index.js');
|
|
6
5
|
require('../../constants/keycodes.js');
|
|
6
|
+
require('../string/kebabCase.js');
|
|
7
7
|
|
|
8
8
|
describe(js_utils_className_getRootClassName.getRootClassName, () => {
|
|
9
9
|
it('should transform the component name into a lumx class', () => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var e=require("./getRootClassName.min.js");require("
|
|
1
|
+
"use strict";var e=require("./getRootClassName.min.js");require("../../constants/index.min.js"),require("../../constants/keycodes.min.js"),require("../string/kebabCase.min.js"),describe(e.getRootClassName,()=>{it("should transform the component name into a lumx class",()=>{expect(e.getRootClassName("Table")).toBe("lumx-table")}),it("should transform the sub component name into a lumx class",()=>{expect(e.getRootClassName("TableBody",!0)).toBe("lumx-table__body")})});
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var classNames = require('classnames');
|
|
4
|
-
var
|
|
5
|
-
var isEmpty = require('lodash/isEmpty');
|
|
4
|
+
var js_utils_collection_isEmpty = require('../collection/isEmpty.js');
|
|
6
5
|
var js_utils_className_getBasicClass = require('./getBasicClass.js');
|
|
7
|
-
require('
|
|
6
|
+
require('../string/kebabCase.js');
|
|
8
7
|
|
|
9
8
|
/**
|
|
10
9
|
* Enhance isEmpty method to also works with numbers.
|
|
@@ -16,7 +15,7 @@ const _isEmpty = (value) => {
|
|
|
16
15
|
if (typeof value === 'number') {
|
|
17
16
|
return value === 0;
|
|
18
17
|
}
|
|
19
|
-
return isEmpty(value);
|
|
18
|
+
return js_utils_collection_isEmpty.isEmpty(value);
|
|
20
19
|
};
|
|
21
20
|
/**
|
|
22
21
|
* Return all basic LumX CSS classes which are available for every components.
|
|
@@ -31,11 +30,10 @@ const _isEmpty = (value) => {
|
|
|
31
30
|
*/
|
|
32
31
|
function handleBasicClasses({ prefix, ...props }) {
|
|
33
32
|
const otherClasses = {};
|
|
34
|
-
if (!isEmpty(props)) {
|
|
33
|
+
if (!js_utils_collection_isEmpty.isEmpty(props)) {
|
|
35
34
|
Object.keys(props).forEach((prop) => {
|
|
36
|
-
otherClasses[js_utils_className_getBasicClass.getBasicClass({ prefix, type: prop, value: props[prop] })] =
|
|
37
|
-
? props[prop]
|
|
38
|
-
: !_isEmpty(props[prop]);
|
|
35
|
+
otherClasses[js_utils_className_getBasicClass.getBasicClass({ prefix, type: prop, value: props[prop] })] =
|
|
36
|
+
typeof props[prop] === 'boolean' ? props[prop] : !_isEmpty(props[prop]);
|
|
39
37
|
});
|
|
40
38
|
}
|
|
41
39
|
return classNames(prefix, otherClasses);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var e=require("classnames"),s=require("
|
|
1
|
+
"use strict";var e=require("classnames"),s=require("../collection/isEmpty.min.js"),i=require("./getBasicClass.min.js");require("../string/kebabCase.min.js");exports.handleBasicClasses=function({prefix:r,...t}){const a={};return s.isEmpty(t)||Object.keys(t).forEach(e=>{var n;a[i.getBasicClass({prefix:r,type:e,value:t[e]})]="boolean"==typeof t[e]?t[e]:!("number"==typeof(n=t[e])?0===n:s.isEmpty(n))}),e(r,a)};
|
|
@@ -2,10 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
var js_utils_className_handleBasicClasses = require('./handleBasicClasses.js');
|
|
4
4
|
require('classnames');
|
|
5
|
-
require('
|
|
6
|
-
require('lodash/isEmpty');
|
|
5
|
+
require('../collection/isEmpty.js');
|
|
7
6
|
require('./getBasicClass.js');
|
|
8
|
-
require('
|
|
7
|
+
require('../string/kebabCase.js');
|
|
9
8
|
|
|
10
9
|
describe(js_utils_className_handleBasicClasses.handleBasicClasses, () => {
|
|
11
10
|
it('should return correct combined CSS classes based on props', () => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var e=require("./handleBasicClasses.min.js");require("classnames"),require("
|
|
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,7 +1,6 @@
|
|
|
1
1
|
import classNames from 'classnames';
|
|
2
2
|
|
|
3
|
-
import
|
|
4
|
-
import isEmpty from 'lodash/isEmpty';
|
|
3
|
+
import { isEmpty } from '@lumx/core/js/utils/collection/isEmpty';
|
|
5
4
|
|
|
6
5
|
import { getBasicClass } from './getBasicClass';
|
|
7
6
|
|
|
@@ -34,9 +33,8 @@ export function handleBasicClasses({ prefix, ...props }: { prefix: string; [prop
|
|
|
34
33
|
const otherClasses: any = {};
|
|
35
34
|
if (!isEmpty(props)) {
|
|
36
35
|
Object.keys(props).forEach((prop) => {
|
|
37
|
-
otherClasses[getBasicClass({ prefix, type: prop, value: props[prop] })] =
|
|
38
|
-
? props[prop]
|
|
39
|
-
: !_isEmpty(props[prop]);
|
|
36
|
+
otherClasses[getBasicClass({ prefix, type: prop, value: props[prop] })] =
|
|
37
|
+
typeof props[prop] === 'boolean' ? props[prop] : !_isEmpty(props[prop]);
|
|
40
38
|
});
|
|
41
39
|
}
|
|
42
40
|
|
|
@@ -7,9 +7,8 @@ var js_utils_className_getTypographyClassName = require('./getTypographyClassNam
|
|
|
7
7
|
var js_utils_className_fontColorClass = require('./fontColorClass.js');
|
|
8
8
|
var js_utils_className_resolveColorWithVariants = require('./resolveColorWithVariants.js');
|
|
9
9
|
require('classnames');
|
|
10
|
-
require('
|
|
11
|
-
require('
|
|
12
|
-
require('lodash/kebabCase');
|
|
10
|
+
require('../collection/isEmpty.js');
|
|
11
|
+
require('../string/kebabCase.js');
|
|
13
12
|
require('../../constants/index.js');
|
|
14
13
|
require('../../constants/keycodes.js');
|
|
15
14
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var s=require("./handleBasicClasses.min.js"),e=require("./getBasicClass.min.js"),a=require("./getRootClassName.min.js"),r=require("./getTypographyClassName.min.js"),
|
|
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;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";exports.castArray=r=>Array.isArray(r)?r:[r];
|
|
@@ -0,0 +1,17 @@
|
|
|
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
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
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])})});
|
|
@@ -0,0 +1,15 @@
|
|
|
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
|
+
});
|
|
@@ -0,0 +1,15 @@
|
|
|
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;
|
|
@@ -0,0 +1 @@
|
|
|
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};
|
|
@@ -0,0 +1,33 @@
|
|
|
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
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
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")})});
|
|
@@ -0,0 +1,38 @@
|
|
|
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
|
+
});
|
|
@@ -0,0 +1,11 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";exports.isEmpty=t=>!t||0===Object.entries(t).length;
|
|
@@ -0,0 +1,21 @@
|
|
|
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
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
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)})});
|
|
@@ -0,0 +1,21 @@
|
|
|
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
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";exports.last=t=>t[t.length-1];
|
|
@@ -0,0 +1,21 @@
|
|
|
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
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
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)})});
|
|
@@ -0,0 +1,21 @@
|
|
|
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
|
+
});
|
|
@@ -0,0 +1,31 @@
|
|
|
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;
|
|
@@ -0,0 +1 @@
|
|
|
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]};
|
|
@@ -0,0 +1,32 @@
|
|
|
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
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
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]])})});
|
|
@@ -0,0 +1,35 @@
|
|
|
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
|
+
});
|
|
@@ -0,0 +1,29 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";exports.range=r=>Array.from({length:r},(r,e)=>e);
|
|
@@ -0,0 +1,12 @@
|
|
|
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
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
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])})});
|
|
@@ -0,0 +1,10 @@
|
|
|
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
|
+
});
|
package/js/utils/index.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var noop = require('lodash/noop');
|
|
4
3
|
var js_utils_className_handleBasicClasses = require('./className/handleBasicClasses.js');
|
|
5
4
|
var js_utils_className_getBasicClass = require('./className/getBasicClass.js');
|
|
6
5
|
var js_utils_className_getRootClassName = require('./className/getRootClassName.js');
|
|
@@ -8,9 +7,8 @@ var js_utils_className_getTypographyClassName = require('./className/getTypograp
|
|
|
8
7
|
var js_utils_className_fontColorClass = require('./className/fontColorClass.js');
|
|
9
8
|
var js_utils_className_resolveColorWithVariants = require('./className/resolveColorWithVariants.js');
|
|
10
9
|
require('classnames');
|
|
11
|
-
require('
|
|
12
|
-
require('
|
|
13
|
-
require('lodash/kebabCase');
|
|
10
|
+
require('./collection/isEmpty.js');
|
|
11
|
+
require('./string/kebabCase.js');
|
|
14
12
|
require('../constants/index.js');
|
|
15
13
|
require('../constants/keycodes.js');
|
|
16
14
|
|
|
@@ -65,7 +63,7 @@ function onButtonPressed(handler) {
|
|
|
65
63
|
* @param handleSwipe Callback function.
|
|
66
64
|
* @return Function to remove listeners.
|
|
67
65
|
*/
|
|
68
|
-
function detectSwipe(touchSurface, handleSwipe
|
|
66
|
+
function detectSwipe(touchSurface, handleSwipe) {
|
|
69
67
|
let distX;
|
|
70
68
|
let distY;
|
|
71
69
|
let startX;
|
|
@@ -114,7 +112,7 @@ function detectSwipe(touchSurface, handleSwipe = noop) {
|
|
|
114
112
|
direction = distY < 0 ? 'up' : 'down';
|
|
115
113
|
}
|
|
116
114
|
}
|
|
117
|
-
handleSwipe(direction);
|
|
115
|
+
handleSwipe?.(direction);
|
|
118
116
|
evt.preventDefault();
|
|
119
117
|
};
|
|
120
118
|
touchSurface.addEventListener('touchstart', onTouchStart, false);
|
|
@@ -138,8 +136,8 @@ function isPassiveEventAvailable() {
|
|
|
138
136
|
supportsPassiveOption = true;
|
|
139
137
|
},
|
|
140
138
|
});
|
|
141
|
-
window.addEventListener('testPassiveEventSupport',
|
|
142
|
-
window.removeEventListener('testPassiveEventSupport',
|
|
139
|
+
window.addEventListener('testPassiveEventSupport', () => { }, opts);
|
|
140
|
+
window.removeEventListener('testPassiveEventSupport', () => { }, opts);
|
|
143
141
|
}
|
|
144
142
|
catch (e) {
|
|
145
143
|
// ignored
|
package/js/utils/index.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var e=require("
|
|
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
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import type { KeyboardEvent as ReactKeyboardEvent } from 'react';
|
|
2
2
|
|
|
3
|
-
import noop from 'lodash/noop';
|
|
4
|
-
|
|
5
3
|
export * from './className';
|
|
6
4
|
|
|
7
5
|
type KeyboardEventHandler<E extends KeyboardEvent | ReactKeyboardEvent> = (event: E) => void;
|
|
@@ -68,7 +66,7 @@ declare type SwipeDirection = 'none' | 'up' | 'down' | 'left' | 'right';
|
|
|
68
66
|
* @param handleSwipe Callback function.
|
|
69
67
|
* @return Function to remove listeners.
|
|
70
68
|
*/
|
|
71
|
-
export function detectSwipe(touchSurface: Element, handleSwipe
|
|
69
|
+
export function detectSwipe(touchSurface: Element, handleSwipe?: (direction: SwipeDirection) => void) {
|
|
72
70
|
let distX: number;
|
|
73
71
|
let distY: number;
|
|
74
72
|
let startX: number;
|
|
@@ -119,7 +117,7 @@ export function detectSwipe(touchSurface: Element, handleSwipe: (direction: Swip
|
|
|
119
117
|
direction = distY < 0 ? 'up' : 'down';
|
|
120
118
|
}
|
|
121
119
|
}
|
|
122
|
-
handleSwipe(direction);
|
|
120
|
+
handleSwipe?.(direction);
|
|
123
121
|
evt.preventDefault();
|
|
124
122
|
};
|
|
125
123
|
|
|
@@ -146,8 +144,8 @@ function isPassiveEventAvailable() {
|
|
|
146
144
|
supportsPassiveOption = true;
|
|
147
145
|
},
|
|
148
146
|
});
|
|
149
|
-
window.addEventListener('testPassiveEventSupport',
|
|
150
|
-
window.removeEventListener('testPassiveEventSupport',
|
|
147
|
+
window.addEventListener('testPassiveEventSupport', () => {}, opts);
|
|
148
|
+
window.removeEventListener('testPassiveEventSupport', () => {}, opts);
|
|
151
149
|
} catch (e) {
|
|
152
150
|
// ignored
|
|
153
151
|
}
|
|
@@ -0,0 +1,30 @@
|
|
|
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;
|
|
@@ -0,0 +1 @@
|
|
|
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,"")};
|
|
@@ -0,0 +1,43 @@
|
|
|
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
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
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")})});
|
|
@@ -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
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
"update-version-changelog": "yarn version-changelog ../../CHANGELOG.md"
|
|
35
35
|
},
|
|
36
36
|
"sideEffects": false,
|
|
37
|
-
"version": "3.20.1-alpha.
|
|
37
|
+
"version": "3.20.1-alpha.38",
|
|
38
38
|
"devDependencies": {
|
|
39
39
|
"@rollup/plugin-commonjs": "^29.0.0",
|
|
40
40
|
"@rollup/plugin-terser": "^0.4.4",
|