@zohodesk/utils 1.0.1-alpha.2057
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/LICENSE +22 -0
- package/__testUtils__/globals.js +0 -0
- package/es/ErrorBoundary.js +29 -0
- package/es/__tests__/abbreviateNumber.spec.js +70 -0
- package/es/__tests__/compileClassNames.spec.js +48 -0
- package/es/__tests__/contextFactory.spec.js +12 -0
- package/es/__tests__/createTemplateLiteral.spec.js +4 -0
- package/es/abbreviateNumber.js +44 -0
- package/es/accessKeyCodes.js +18 -0
- package/es/applyOpenToCustomize.js +31 -0
- package/es/combineCustomStyle.js +39 -0
- package/es/compileClassNames.js +151 -0
- package/es/constantProps/index.js +1 -0
- package/es/constantProps/uiProps.js +34 -0
- package/es/contextFactory.js +15 -0
- package/es/createTemplateLiteral.js +77 -0
- package/es/dataTypes.js +25 -0
- package/es/debounce.js +12 -0
- package/es/disCustomStyleProps.js +45 -0
- package/es/getCompliedClassName.js +12 -0
- package/es/getCompliedCustomId.js +16 -0
- package/es/index.js +10 -0
- package/es/isTouchDevice.js +9 -0
- package/es/loadResource.js +56 -0
- package/es/mergeStyle.js +31 -0
- package/es/objectUtils.js +4 -0
- package/es/omit.js +12 -0
- package/es/props/automationProps.js +7 -0
- package/es/props/customReducerPropTypes.js +5 -0
- package/es/props/customStyleProps.js +9 -0
- package/es/props/generalAriaProps.js +6 -0
- package/es/props/tagAttributeProps.js +24 -0
- package/es/props/tagGeneralAttributeProps.js +24 -0
- package/es/props/uiProps.js +65 -0
- package/es/reducerHandler.js +18 -0
- package/es/replaceAtFirst.js +3 -0
- package/es/replaceAtLast.js +3 -0
- package/es/uniqueNumber.js +14 -0
- package/package.json +22 -0
- package/src/ErrorBoundary.js +24 -0
- package/src/__tests__/abbreviateNumber.spec.js +70 -0
- package/src/__tests__/compileClassNames.spec.js +35 -0
- package/src/__tests__/contextFactory.spec.js +13 -0
- package/src/__tests__/createTemplateLiteral.spec.js +4 -0
- package/src/abbreviateNumber.js +35 -0
- package/src/accessKeyCodes.js +19 -0
- package/src/applyOpenToCustomize.js +32 -0
- package/src/combineCustomStyle.js +52 -0
- package/src/compileClassNames.js +156 -0
- package/src/constantProps/index.js +1 -0
- package/src/constantProps/uiProps.js +41 -0
- package/src/contextFactory.js +14 -0
- package/src/createTemplateLiteral.js +73 -0
- package/src/dataTypes.js +30 -0
- package/src/debounce.js +13 -0
- package/src/disCustomStyleProps.js +69 -0
- package/src/getCompliedClassName.js +9 -0
- package/src/getCompliedCustomId.js +15 -0
- package/src/index.js +10 -0
- package/src/isTouchDevice.js +10 -0
- package/src/loadResource.js +45 -0
- package/src/mergeStyle.js +31 -0
- package/src/objectUtils.js +4 -0
- package/src/omit.js +10 -0
- package/src/props/automationProps.js +8 -0
- package/src/props/customReducerPropTypes.js +7 -0
- package/src/props/customStyleProps.js +10 -0
- package/src/props/generalAriaProps.js +7 -0
- package/src/props/tagAttributeProps.js +40 -0
- package/src/props/tagGeneralAttributeProps.js +48 -0
- package/src/props/uiProps.js +72 -0
- package/src/reducerHandler.js +23 -0
- package/src/replaceAtFirst.js +3 -0
- package/src/replaceAtLast.js +3 -0
- package/src/uniqueNumber.js +16 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
Copyright (c) 2015-present Lerna Contributors
|
|
2
|
+
|
|
3
|
+
MIT License
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
6
|
+
a copy of this software and associated documentation files (the
|
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
11
|
+
the following conditions:
|
|
12
|
+
|
|
13
|
+
The above copyright notice and this permission notice shall be
|
|
14
|
+
included in all copies or substantial portions of the Software.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
File without changes
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
export default class ErrorBoundary extends React.Component {
|
|
3
|
+
constructor(props) {
|
|
4
|
+
super(props);
|
|
5
|
+
this.state = {
|
|
6
|
+
hasError: false
|
|
7
|
+
};
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
static getDerivedStateFromError(error) {
|
|
11
|
+
return {
|
|
12
|
+
hasError: true,
|
|
13
|
+
error
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
componentDidCatch(error, errorInfo) {
|
|
18
|
+
console.log(error, errorInfo);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
render() {
|
|
22
|
+
if (this.state.hasError) {
|
|
23
|
+
return this.props.renderFallback(this.state.error);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
return this.props.children;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import abbreviateNumber from '../abbreviateNumber';
|
|
2
|
+
describe("abbreviateNumber", () => {
|
|
3
|
+
test("value should be zero string and input also string", () => {
|
|
4
|
+
let a = abbreviateNumber("0");
|
|
5
|
+
expect(a).toBe("0");
|
|
6
|
+
});
|
|
7
|
+
test("value should be zero string", () => {
|
|
8
|
+
let a = abbreviateNumber(0);
|
|
9
|
+
expect(a).toBe("0");
|
|
10
|
+
});
|
|
11
|
+
test("value should be 1K string", () => {
|
|
12
|
+
let a = abbreviateNumber(1000);
|
|
13
|
+
expect(a).toBe("1K");
|
|
14
|
+
});
|
|
15
|
+
test("value should be 1K string", () => {
|
|
16
|
+
let a = abbreviateNumber(1001);
|
|
17
|
+
expect(a).toBe("1K");
|
|
18
|
+
});
|
|
19
|
+
test("value should be 1K+ string", () => {
|
|
20
|
+
let a = abbreviateNumber(1001);
|
|
21
|
+
expect(a).toBe("1K");
|
|
22
|
+
});
|
|
23
|
+
test("value should be 1M string", () => {
|
|
24
|
+
let a = abbreviateNumber(1000000);
|
|
25
|
+
expect(a).toBe("1M");
|
|
26
|
+
});
|
|
27
|
+
test("value should be 1M+ string", () => {
|
|
28
|
+
let a = abbreviateNumber(1000001);
|
|
29
|
+
expect(a).toBe("1M");
|
|
30
|
+
});
|
|
31
|
+
});
|
|
32
|
+
describe("abbreviateNumber without browser Intl", () => {
|
|
33
|
+
beforeAll(() => {
|
|
34
|
+
global.Intl = null;
|
|
35
|
+
});
|
|
36
|
+
test("value should be zero string and input also string", () => {
|
|
37
|
+
let a = abbreviateNumber("0");
|
|
38
|
+
expect(a).toBe("0");
|
|
39
|
+
});
|
|
40
|
+
test("value should be zero string", () => {
|
|
41
|
+
let a = abbreviateNumber(0);
|
|
42
|
+
expect(a).toBe("0");
|
|
43
|
+
});
|
|
44
|
+
test("value should be zero string", () => {
|
|
45
|
+
let a = abbreviateNumber(0, {
|
|
46
|
+
withAbbr: false
|
|
47
|
+
});
|
|
48
|
+
expect(a).toBe("0");
|
|
49
|
+
});
|
|
50
|
+
test("value should be 1K string", () => {
|
|
51
|
+
let a = abbreviateNumber(1000);
|
|
52
|
+
expect(a).toBe("1K");
|
|
53
|
+
});
|
|
54
|
+
test("value should be 1K string", () => {
|
|
55
|
+
let a = abbreviateNumber(1001);
|
|
56
|
+
expect(a).toBe("1K");
|
|
57
|
+
});
|
|
58
|
+
test("value should be 1K+ string", () => {
|
|
59
|
+
let a = abbreviateNumber(1001);
|
|
60
|
+
expect(a).toBe("1K");
|
|
61
|
+
});
|
|
62
|
+
test("value should be 1M string", () => {
|
|
63
|
+
let a = abbreviateNumber(1000000);
|
|
64
|
+
expect(a).toBe("1M");
|
|
65
|
+
});
|
|
66
|
+
test("value should be 1M+ string", () => {
|
|
67
|
+
let a = abbreviateNumber(1000001);
|
|
68
|
+
expect(a).toBe("1M");
|
|
69
|
+
});
|
|
70
|
+
});
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import compileClassNames from '../compileClassNames';
|
|
2
|
+
describe("compileClassNames", () => {
|
|
3
|
+
test("should be class1", () => {
|
|
4
|
+
let output = compileClassNames({
|
|
5
|
+
"class1": true
|
|
6
|
+
});
|
|
7
|
+
expect(output).toBe("class1");
|
|
8
|
+
});
|
|
9
|
+
test("should be class1 class2", () => {
|
|
10
|
+
let output = compileClassNames({
|
|
11
|
+
"class1": true,
|
|
12
|
+
"class2": true
|
|
13
|
+
});
|
|
14
|
+
expect(output).toBe("class1 class2");
|
|
15
|
+
});
|
|
16
|
+
test("should be class2", () => {
|
|
17
|
+
let output = compileClassNames({
|
|
18
|
+
"class1": false,
|
|
19
|
+
"class2": true
|
|
20
|
+
});
|
|
21
|
+
expect(output).toBe("class2");
|
|
22
|
+
});
|
|
23
|
+
test("should be empty", () => {
|
|
24
|
+
let output = compileClassNames({
|
|
25
|
+
"class1": false,
|
|
26
|
+
"class2": false
|
|
27
|
+
});
|
|
28
|
+
expect(output).toBe("");
|
|
29
|
+
});
|
|
30
|
+
test("should be empty input is empty object ", () => {
|
|
31
|
+
let output = compileClassNames({});
|
|
32
|
+
expect(output).toBe("");
|
|
33
|
+
});
|
|
34
|
+
test("should be class1 multiple argument and first argument with null ", () => {
|
|
35
|
+
let output = compileClassNames(null, {
|
|
36
|
+
class1: true
|
|
37
|
+
});
|
|
38
|
+
expect(output).toBe("class1");
|
|
39
|
+
});
|
|
40
|
+
test("should be multiple argument and first argument with null second arg as string ", () => {
|
|
41
|
+
let output = compileClassNames(null, "class1");
|
|
42
|
+
expect(output).toBe("class1");
|
|
43
|
+
});
|
|
44
|
+
test("should be empty input is empty object ", () => {
|
|
45
|
+
let output = compileClassNames(["class1"]);
|
|
46
|
+
expect(output).toBe("class1");
|
|
47
|
+
});
|
|
48
|
+
});
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import contextFactory from '../contextFactory';
|
|
2
|
+
describe("contextFactory", () => {
|
|
3
|
+
test("create new context", () => {
|
|
4
|
+
let RouterContext = contextFactory("router");
|
|
5
|
+
expect(RouterContext.$$typeof).toBe(Symbol.for('react.context'));
|
|
6
|
+
});
|
|
7
|
+
test("if context exist return same context", () => {
|
|
8
|
+
let RouterContext1 = contextFactory("router");
|
|
9
|
+
let RouterContext2 = contextFactory("router");
|
|
10
|
+
expect(RouterContext1).toBe(RouterContext2);
|
|
11
|
+
});
|
|
12
|
+
});
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
*
|
|
3
|
+
* @param {number|string} count
|
|
4
|
+
* @param {object} options
|
|
5
|
+
* @param {string} options.locale
|
|
6
|
+
* @param {boolean} options.withAbbr
|
|
7
|
+
* @param {number} options.decimals
|
|
8
|
+
* @returns
|
|
9
|
+
*/
|
|
10
|
+
export default function abbreviateNumber() {
|
|
11
|
+
let count = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
|
|
12
|
+
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
13
|
+
|
|
14
|
+
if (typeof count === "string") {
|
|
15
|
+
count = parseInt(count);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
if (global.Intl && global.Intl.NumberFormat) {
|
|
19
|
+
let numberFormat = Intl.NumberFormat(options.locale || "en", {
|
|
20
|
+
notation: "compact" // compactDisplay: "short",
|
|
21
|
+
|
|
22
|
+
});
|
|
23
|
+
return numberFormat.format(count);
|
|
24
|
+
} //Comaptibility
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
const COUNT_ABBRS = ["", "K", "M", "G", "T", "P", "E", "Z", "Y"];
|
|
28
|
+
let {
|
|
29
|
+
withAbbr = true,
|
|
30
|
+
decimals = 2
|
|
31
|
+
} = options;
|
|
32
|
+
const i = 0 === count ? count : Math.floor(Math.log(count) / Math.log(1000));
|
|
33
|
+
let result = parseFloat((count / Math.pow(1000, i)).toFixed(decimals));
|
|
34
|
+
|
|
35
|
+
if (withAbbr) {
|
|
36
|
+
result += `${COUNT_ABBRS[i]}`;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
return result;
|
|
40
|
+
}
|
|
41
|
+
/* need discussion
|
|
42
|
+
1001 => 1K+
|
|
43
|
+
|
|
44
|
+
G, T, P, E, Z,Y are needed in practical */
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export default {
|
|
2
|
+
tab: 9,
|
|
3
|
+
enter: 13,
|
|
4
|
+
space: 32,
|
|
5
|
+
rightArrow: 39,
|
|
6
|
+
leftArrow: 37,
|
|
7
|
+
topArrow: 38,
|
|
8
|
+
bottomArrow: 40
|
|
9
|
+
};
|
|
10
|
+
export const accessKeyNames = {
|
|
11
|
+
'tab': 'tab',
|
|
12
|
+
'enter': 'enter',
|
|
13
|
+
'space': 'space',
|
|
14
|
+
'arrowleft': 'arrowleft',
|
|
15
|
+
'arrowtop': 'arrowtop',
|
|
16
|
+
'arrowright': 'arrowright',
|
|
17
|
+
'arrowbottom': 'arrowbottom'
|
|
18
|
+
};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import "core-js/modules/es.array.includes";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Opening the customization, need to addd for behaviour changes. also add only enabled.
|
|
5
|
+
* @param {*} style
|
|
6
|
+
* @param {*} options
|
|
7
|
+
* Example code
|
|
8
|
+
* <Component openToCutsomize={{prefix:'dot'}} />
|
|
9
|
+
* let style = applyOpenToCustomize(style,openToCutsomize)
|
|
10
|
+
*/
|
|
11
|
+
export default function applyOpenToCustomize(style, options) {
|
|
12
|
+
let resultStyle = style;
|
|
13
|
+
|
|
14
|
+
if (options && options.prefix) {
|
|
15
|
+
resultStyle = { ...style
|
|
16
|
+
};
|
|
17
|
+
let defaultPrefix = options.prefix || "";
|
|
18
|
+
|
|
19
|
+
if (defaultPrefix) {
|
|
20
|
+
defaultPrefix = `${defaultPrefix}-`;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
Object.keys(style).forEach(styleName => {
|
|
24
|
+
if (resultStyle[styleName] && !resultStyle[styleName].includes(styleName)) {
|
|
25
|
+
resultStyle[styleName] = `${resultStyle[styleName]} ${defaultPrefix}${styleName}`;
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
return resultStyle;
|
|
31
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
const REPLACER_SYMBOL = "$";
|
|
2
|
+
/**
|
|
3
|
+
*
|
|
4
|
+
* if two is same ==> do the think if replace do, if append do.
|
|
5
|
+
* replace vs append ==> append
|
|
6
|
+
* append vs replace ==> replace
|
|
7
|
+
* @param {*} style1
|
|
8
|
+
* @param {*} style2
|
|
9
|
+
* @returns
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
export default function combineCustomStyle(style1, style2) {
|
|
13
|
+
let resultStyle = { ...style1
|
|
14
|
+
};
|
|
15
|
+
Object.keys(style2).forEach(styleName => {
|
|
16
|
+
let oldStyleName = style1[`$${styleName}`] ? `$${styleName}` : styleName;
|
|
17
|
+
|
|
18
|
+
if (oldStyleName.startsWith(REPLACER_SYMBOL) && styleName.startsWith(REPLACER_SYMBOL)) {
|
|
19
|
+
resultStyle[styleName] = style2[styleName];
|
|
20
|
+
} else if (!oldStyleName.startsWith(REPLACER_SYMBOL) && !styleName.startsWith(REPLACER_SYMBOL)) {
|
|
21
|
+
resultStyle[styleName] = `${resultStyle[styleName]} ${style2[styleName]}`;
|
|
22
|
+
} else {
|
|
23
|
+
delete resultStyle[oldStyleName];
|
|
24
|
+
resultStyle[styleName] = style2[styleName];
|
|
25
|
+
}
|
|
26
|
+
/*else if (oldStyleName.startsWith(REPLACER_SYMBOL) && !styleName.startsWith(REPLACER_SYMBOL) ) {
|
|
27
|
+
|
|
28
|
+
delete resultStyle[oldStyleName];
|
|
29
|
+
resultStyle[styleName] = style2[styleName];
|
|
30
|
+
}
|
|
31
|
+
else if (!oldStyleName.startsWith(REPLACER_SYMBOL) && styleName.startsWith(REPLACER_SYMBOL) ) {
|
|
32
|
+
|
|
33
|
+
delete resultStyle[oldStyleName];
|
|
34
|
+
resultStyle[styleName] = style2[styleName];
|
|
35
|
+
}*/
|
|
36
|
+
|
|
37
|
+
});
|
|
38
|
+
return resultStyle;
|
|
39
|
+
}
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import dataTypes, { isDataTypeOf } from "./dataTypes";
|
|
2
|
+
import { hasOwnProperty, isToStringReferenceEqual } from "./objectUtils";
|
|
3
|
+
/**
|
|
4
|
+
*
|
|
5
|
+
* @param {object} classinfoList
|
|
6
|
+
* @returns {string}
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
const collectClassNames = function (processedClassNameList) {
|
|
10
|
+
for (let index = 0; index < (arguments.length <= 1 ? 0 : arguments.length - 1); index++) {
|
|
11
|
+
let classInfo = index + 1 < 1 || arguments.length <= index + 1 ? undefined : arguments[index + 1];
|
|
12
|
+
|
|
13
|
+
if (!classInfo) {
|
|
14
|
+
continue;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
if (isDataTypeOf(classInfo, dataTypes.string) || isDataTypeOf(classInfo, dataTypes.number)) {
|
|
18
|
+
processedClassNameList.push(classInfo);
|
|
19
|
+
} else if (isDataTypeOf(classInfo, dataTypes.array)) {
|
|
20
|
+
processedClassNameList.push(collectClassNames.apply(null, classInfo));
|
|
21
|
+
} else if (isDataTypeOf(classInfo, dataTypes.object)) {
|
|
22
|
+
for (let property in classInfo) {
|
|
23
|
+
if (hasOwnProperty.call(classInfo, property) && classInfo[property]) {
|
|
24
|
+
processedClassNameList.push(property === "undefined" ? '' : property);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
export default function compileClassNames() {
|
|
32
|
+
let resultClassNameList = [];
|
|
33
|
+
|
|
34
|
+
for (var _len = arguments.length, classinfoList = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
35
|
+
classinfoList[_key] = arguments[_key];
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
collectClassNames(resultClassNameList, ...classinfoList);
|
|
39
|
+
return resultClassNameList.join(' ');
|
|
40
|
+
}
|
|
41
|
+
;
|
|
42
|
+
/* discussion
|
|
43
|
+
passing object is enough i think. remaining option needed!!!
|
|
44
|
+
*/
|
|
45
|
+
//18-Nov-2021 code review changes updated.
|
|
46
|
+
|
|
47
|
+
/*
|
|
48
|
+
>>>>>>>>>>Code Review Suggestion Starts >>>>>>
|
|
49
|
+
let hasOwn = {}.hasOwnProperty;
|
|
50
|
+
|
|
51
|
+
Accounting readability, please change this to Object.hasOwnProperty
|
|
52
|
+
|
|
53
|
+
---
|
|
54
|
+
const compileClassNames = (...props)=>{
|
|
55
|
+
Please check the alternate term - collate -> collateClassNames -> Collect and Combine the classnames.
|
|
56
|
+
---
|
|
57
|
+
|
|
58
|
+
for (let i = 0; i < props.length; i++) {
|
|
59
|
+
|
|
60
|
+
Please try to to stick with functional programming. Again for the readability perspective.
|
|
61
|
+
Also, please stick with naming conventions for variables (i -> index).
|
|
62
|
+
|
|
63
|
+
---
|
|
64
|
+
if (argType === 'string' || argType === 'number') {
|
|
65
|
+
classes.push(this && this[arg] || arg);
|
|
66
|
+
} else if (Array.isArray(arg)) {
|
|
67
|
+
classes.push(compileClassNames.apply(this, arg));
|
|
68
|
+
} else if (argType === 'object') {
|
|
69
|
+
if (arg.toString === Object.prototype.toString) {
|
|
70
|
+
for (let key in arg) {
|
|
71
|
+
if (hasOwn.call(arg, key) && arg[key]) {
|
|
72
|
+
classes.push(this && this[key] || key);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
} else {
|
|
76
|
+
classes.push(arg.toString());
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
In this code block, pushing up the array,object checks before string || number will be easy to follow up as it clarifies about the reursive call, its context.
|
|
81
|
+
Please check the possibility of avoiding the usage of 'this' statement due to its complexity in understanding the concept.
|
|
82
|
+
|
|
83
|
+
---
|
|
84
|
+
Please write a functional method for the below line for easier understanding
|
|
85
|
+
|
|
86
|
+
if (arg.toString === Object.prototype.toString) {
|
|
87
|
+
|
|
88
|
+
---
|
|
89
|
+
|
|
90
|
+
Adding dedicated method to get the datatype of variables will help to stick on the SRP.
|
|
91
|
+
---
|
|
92
|
+
Check the possibility of providing platform to extend the algorithm works for other data structures like Map, WeakMap,etc..
|
|
93
|
+
|
|
94
|
+
>>>>>>> Code Review Suggestion Ends >>>>>>>>>>>>>>>>
|
|
95
|
+
*/
|
|
96
|
+
|
|
97
|
+
/*
|
|
98
|
+
|
|
99
|
+
>>>>>> Alternative Implementation Starts >>>>>>>>>>>>>>>>
|
|
100
|
+
|
|
101
|
+
let boundHasOwnMethod = Object.hasOwnProperty;
|
|
102
|
+
|
|
103
|
+
const collateClassNames = (...classinfoList) =>{
|
|
104
|
+
let processedClassNameList = [];
|
|
105
|
+
classinfoList.forEach( ( classInfo,index )=>{
|
|
106
|
+
if(!classInfo)
|
|
107
|
+
{
|
|
108
|
+
// continue the next iteration
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
let dataTypeofClassInfo = getDataType(classInfo);
|
|
112
|
+
if (dataTypeofClassInfo === 'string' || dataTypeofClassInfo === 'number')
|
|
113
|
+
{
|
|
114
|
+
processedClassNameList.push(classInfo);
|
|
115
|
+
}
|
|
116
|
+
else if(dataTypeofClassInfo === 'array')
|
|
117
|
+
{
|
|
118
|
+
processedClassNameList.push(collateClassNames(...classInfo));
|
|
119
|
+
}
|
|
120
|
+
else if(dataTypeofClassInfo === 'object')
|
|
121
|
+
{
|
|
122
|
+
for (let property in classInfo) {
|
|
123
|
+
if (boundHasOwnMethod.call(classInfo,property ) && classInfo[property]) {
|
|
124
|
+
processedClassNameList.push(property);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
});
|
|
131
|
+
const joinClassNames = processedClassNameList.join(' ');
|
|
132
|
+
return joinClassNames;
|
|
133
|
+
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
const getDataType = (data)=>{
|
|
137
|
+
let dataTypeofClassInfo = typeof data;
|
|
138
|
+
let isArrayDataType = Array.isArray(data) === true;
|
|
139
|
+
if(isArrayDataType)
|
|
140
|
+
{
|
|
141
|
+
return 'array';
|
|
142
|
+
}
|
|
143
|
+
else
|
|
144
|
+
{
|
|
145
|
+
return dataTypeofClassInfo;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
>>>>>>>>>>>>>>>> Alternative Implementation Ends>>>>>>>>>>>>>>
|
|
151
|
+
*/
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./uiProps";
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
export const variantList = {
|
|
2
|
+
outlined: 'variant_outlined',
|
|
3
|
+
contained: 'variant_contained',
|
|
4
|
+
flushed: 'variant_flushed',
|
|
5
|
+
plain: 'variant_plain'
|
|
6
|
+
};
|
|
7
|
+
export const variants = Object.values(variantList);
|
|
8
|
+
export const sizeList = {
|
|
9
|
+
xsmall: 'size_xsmall',
|
|
10
|
+
small: 'size_small',
|
|
11
|
+
medium: 'size_medium',
|
|
12
|
+
large: 'size_large',
|
|
13
|
+
xlarge: 'size_xlarge'
|
|
14
|
+
};
|
|
15
|
+
export const sizeKeys = Object.keys(sizeList);
|
|
16
|
+
export const sizes = Object.values(sizeList);
|
|
17
|
+
export const colorList = {
|
|
18
|
+
danger: 'color_danger',
|
|
19
|
+
success: 'color_success',
|
|
20
|
+
info: 'color_info',
|
|
21
|
+
primary: 'color_primary',
|
|
22
|
+
secondary: 'color_secondary',
|
|
23
|
+
warning: 'color_warning'
|
|
24
|
+
};
|
|
25
|
+
export const colorKeys = Object.keys(colorList);
|
|
26
|
+
export const colors = Object.values(colorList);
|
|
27
|
+
export const shapeList = {
|
|
28
|
+
circle: 'shape_circle',
|
|
29
|
+
oval: 'shape_oval',
|
|
30
|
+
square: 'shape_square',
|
|
31
|
+
roundedRect: 'shape_roundedRect',
|
|
32
|
+
rounded: 'shape_rounded'
|
|
33
|
+
};
|
|
34
|
+
export const shapes = Object.values(shapeList);
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { createContext } from 'react';
|
|
2
|
+
const context = {};
|
|
3
|
+
/**
|
|
4
|
+
*
|
|
5
|
+
* @param {string} name
|
|
6
|
+
* @returns {object}
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
export default function contextFactory(name) {
|
|
10
|
+
if (!context[name]) {
|
|
11
|
+
context[name] = /*#__PURE__*/createContext();
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
return context[name];
|
|
15
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
export default function createTemplateLiteral(templateStrings) {
|
|
2
|
+
for (var _len = arguments.length, expressionKeys = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
|
3
|
+
expressionKeys[_key - 1] = arguments[_key];
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
return function () {
|
|
7
|
+
for (var _len2 = arguments.length, expressionValues = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
|
|
8
|
+
expressionValues[_key2] = arguments[_key2];
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
let resultString = [templateStrings[0]];
|
|
12
|
+
expressionKeys.forEach(function (expressionKey, i) {
|
|
13
|
+
let expressionValue = expressionValues[i];
|
|
14
|
+
let nextTemplateString = templateStrings[i + 1];
|
|
15
|
+
|
|
16
|
+
if (expressionValue === null || expressionValue === undefined || expressionValue === "") {
|
|
17
|
+
nextTemplateString = nextTemplateString.replace(/^_/, '');
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
resultString.push(expressionValue, nextTemplateString);
|
|
21
|
+
});
|
|
22
|
+
let resultStr = resultString.join('');
|
|
23
|
+
resultStr = resultStr.replace(/_$/, '');
|
|
24
|
+
return resultStr;
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
/* refer the doc https://developers.google.com/web/updates/2015/01/ES6-Template-Strings
|
|
28
|
+
|
|
29
|
+
UnderSatnd the terms - String interpolation, Embedded expressions
|
|
30
|
+
|
|
31
|
+
Go through the topic https://developers.google.com/web/updates/2015/01/ES6-Template-Strings#tagged_templates
|
|
32
|
+
|
|
33
|
+
Things to note fn`Hello ${you}! You're looking ${adjective} today!` desugars to fn(["Hello ", "! You're looking ", " today!"], you, adjective);
|
|
34
|
+
|
|
35
|
+
Please go through the example code
|
|
36
|
+
|
|
37
|
+
Our implementation constructCustomMessage is the handler for the tagged template function.
|
|
38
|
+
It receives the static words and its substitutions as seen above as the arguments.
|
|
39
|
+
|
|
40
|
+
It returns a function that receives the values for the substitutions. Upon passing the values for the inner function
|
|
41
|
+
it executes the algorithm as mentioned in the doc to construct the final message.
|
|
42
|
+
"The (n + 1)th argument corresponds to the substitution that takes place between the nth and (n + 1)th entries in the string array"
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
function constructCustomMessage(staticWordsList, ...embeddedExpressionKeyList)
|
|
46
|
+
{
|
|
47
|
+
return (...valuesForEmbeddedExpressionList)=>{
|
|
48
|
+
|
|
49
|
+
let finalMessage = staticWordsList[0];
|
|
50
|
+
embeddedExpressionKeyList.forEach(function(expressionKey, index) {
|
|
51
|
+
let expressionValue = valuesForEmbeddedExpressionList[index];
|
|
52
|
+
let nextStaticWord = staticWordsList[index+1];
|
|
53
|
+
if(expressionValue===null || expressionValue === undefined || expressionValue === ""){
|
|
54
|
+
// Replace the underscore '_' present at the beginning of string with empty value.
|
|
55
|
+
nextStaticWord = nextStaticWord.replace(/^_/, '');
|
|
56
|
+
}
|
|
57
|
+
finalMessage += expressionValue + nextStaticWord;
|
|
58
|
+
|
|
59
|
+
});
|
|
60
|
+
// Replace the underscore '_' present at the end of string with empty value.
|
|
61
|
+
finalMessage = finalMessage.replace(/_$/,'');
|
|
62
|
+
return finalMessage ;
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
}
|
|
66
|
+
*/
|
|
67
|
+
|
|
68
|
+
/*
|
|
69
|
+
Sample Invocation Format
|
|
70
|
+
|
|
71
|
+
var username;
|
|
72
|
+
var tag;
|
|
73
|
+
var handlerFunctiontoFormMessage = constructCustomMessage`<b>${username} says</b>: "${tag}"`;
|
|
74
|
+
var outputString = handlerFunctiontoFormMessage('Mani Venkat', '& is a fun tag');
|
|
75
|
+
console.log(outputString);
|
|
76
|
+
|
|
77
|
+
*/
|
package/es/dataTypes.js
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
const dataTypes = {
|
|
2
|
+
"number": "number",
|
|
3
|
+
"array": "array",
|
|
4
|
+
"string": "string",
|
|
5
|
+
"object": "object",
|
|
6
|
+
"bigint": "bigint",
|
|
7
|
+
"symbol": "symbol",
|
|
8
|
+
"undefined": "undefined",
|
|
9
|
+
"function": "function",
|
|
10
|
+
"boolean": "boolean"
|
|
11
|
+
};
|
|
12
|
+
export const getDataType = data => {
|
|
13
|
+
let typeofData = typeof data;
|
|
14
|
+
let isArrayDataType = Array.isArray(data);
|
|
15
|
+
|
|
16
|
+
if (isArrayDataType) {
|
|
17
|
+
return dataTypes.array;
|
|
18
|
+
} else {
|
|
19
|
+
return dataTypes[typeofData];
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
export const isDataTypeOf = (data, type) => {
|
|
23
|
+
return getDataType(data) === type;
|
|
24
|
+
};
|
|
25
|
+
export default dataTypes;
|