@zohodesk/utils 1.0.1-alpha.2059 → 1.0.2-alpha.2065

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 (42) hide show
  1. package/package.json +6 -2
  2. package/__testUtils__/globals.js +0 -0
  3. package/es/__tests__/abbreviateNumber.spec.js +0 -70
  4. package/es/__tests__/compileClassNames.spec.js +0 -48
  5. package/es/__tests__/contextFactory.spec.js +0 -12
  6. package/es/__tests__/createTemplateLiteral.spec.js +0 -4
  7. package/src/ErrorBoundary.js +0 -24
  8. package/src/__tests__/abbreviateNumber.spec.js +0 -70
  9. package/src/__tests__/compileClassNames.spec.js +0 -35
  10. package/src/__tests__/contextFactory.spec.js +0 -13
  11. package/src/__tests__/createTemplateLiteral.spec.js +0 -4
  12. package/src/abbreviateNumber.js +0 -35
  13. package/src/accessKeyCodes.js +0 -19
  14. package/src/applyOpenToCustomize.js +0 -32
  15. package/src/combineCustomStyle.js +0 -52
  16. package/src/compileClassNames.js +0 -156
  17. package/src/constantProps/index.js +0 -1
  18. package/src/constantProps/uiProps.js +0 -41
  19. package/src/contextFactory.js +0 -14
  20. package/src/createTemplateLiteral.js +0 -73
  21. package/src/dataTypes.js +0 -30
  22. package/src/debounce.js +0 -13
  23. package/src/disCustomStyleProps.js +0 -69
  24. package/src/getCompliedClassName.js +0 -9
  25. package/src/getCompliedCustomId.js +0 -15
  26. package/src/index.js +0 -10
  27. package/src/isTouchDevice.js +0 -10
  28. package/src/loadResource.js +0 -45
  29. package/src/mergeStyle.js +0 -31
  30. package/src/objectUtils.js +0 -4
  31. package/src/omit.js +0 -10
  32. package/src/props/automationProps.js +0 -8
  33. package/src/props/customReducerPropTypes.js +0 -7
  34. package/src/props/customStyleProps.js +0 -10
  35. package/src/props/generalAriaProps.js +0 -7
  36. package/src/props/tagAttributeProps.js +0 -40
  37. package/src/props/tagGeneralAttributeProps.js +0 -48
  38. package/src/props/uiProps.js +0 -72
  39. package/src/reducerHandler.js +0 -23
  40. package/src/replaceAtFirst.js +0 -3
  41. package/src/replaceAtLast.js +0 -3
  42. package/src/uniqueNumber.js +0 -16
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zohodesk/utils",
3
- "version": "1.0.1-alpha.2059+c8e24eb4",
3
+ "version": "1.0.2-alpha.2065+905d9748",
4
4
  "description": "",
5
5
  "private": false,
6
6
  "publishConfig": {
@@ -16,7 +16,11 @@
16
16
  "prepare": "npm run clean && npm run build && npm run rtl",
17
17
  "test": "react-cli test"
18
18
  },
19
+ "files": [
20
+ "es",
21
+ "!**/__tests__"
22
+ ],
19
23
  "author": "",
20
24
  "license": "ISC",
21
- "gitHead": "c8e24eb44041a7a63224ecc97aa8fd8cff2c09a8"
25
+ "gitHead": "905d97480eb6ff37bd61dfa7e3956c6227dafb1f"
22
26
  }
File without changes
@@ -1,70 +0,0 @@
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
- });
@@ -1,48 +0,0 @@
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
- });
@@ -1,12 +0,0 @@
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
- });
@@ -1,4 +0,0 @@
1
- import createTemplateLiteral from '../createTemplateLiteral';
2
- describe("createTemplateLiteral", () => {
3
- test("", () => {});
4
- });
@@ -1,24 +0,0 @@
1
- import React from 'react';
2
-
3
- export default class ErrorBoundary extends React.Component {
4
- constructor(props) {
5
- super(props);
6
- this.state = { hasError: false };
7
- }
8
-
9
- static getDerivedStateFromError(error) {
10
- return { hasError: true, error };
11
- }
12
-
13
- componentDidCatch(error, errorInfo) {
14
- console.log(error, errorInfo);
15
- }
16
-
17
- render() {
18
- if (this.state.hasError) {
19
- return this.props.renderFallback(this.state.error);
20
- }
21
-
22
- return this.props.children;
23
- }
24
- }
@@ -1,70 +0,0 @@
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
-
37
- test("value should be zero string and input also string", () => {
38
- let a = abbreviateNumber("0");
39
- expect(a).toBe("0");
40
- })
41
- test("value should be zero string", () => {
42
- let a = abbreviateNumber(0);
43
- expect(a).toBe("0");
44
- })
45
- test("value should be zero string", () => {
46
- let a = abbreviateNumber(0, { withAbbr: false });
47
- expect(a).toBe("0");
48
- })
49
- test("value should be 1K string", () => {
50
- let a = abbreviateNumber(1000);
51
- expect(a).toBe("1K");
52
- })
53
- test("value should be 1K string", () => {
54
- let a = abbreviateNumber(1001);
55
- expect(a).toBe("1K");
56
- })
57
- test("value should be 1K+ string", () => {
58
- let a = abbreviateNumber(1001);
59
- expect(a).toBe("1K");
60
- })
61
- test("value should be 1M string", () => {
62
- let a = abbreviateNumber(1000000);
63
- expect(a).toBe("1M");
64
- })
65
- test("value should be 1M+ string", () => {
66
- let a = abbreviateNumber(1000001);
67
- expect(a).toBe("1M");
68
- })
69
-
70
- })
@@ -1,35 +0,0 @@
1
- import compileClassNames from '../compileClassNames';
2
- describe("compileClassNames", () => {
3
- test("should be class1", () => {
4
- let output = compileClassNames({ "class1": true });
5
- expect(output).toBe("class1")
6
- })
7
- test("should be class1 class2", () => {
8
- let output = compileClassNames({ "class1": true, "class2": true });
9
- expect(output).toBe("class1 class2")
10
- })
11
- test("should be class2", () => {
12
- let output = compileClassNames({ "class1": false, "class2": true });
13
- expect(output).toBe("class2")
14
- })
15
- test("should be empty", () => {
16
- let output = compileClassNames({ "class1": false, "class2": false });
17
- expect(output).toBe("")
18
- })
19
- test("should be empty input is empty object ", () => {
20
- let output = compileClassNames({});
21
- expect(output).toBe("")
22
- })
23
- test("should be class1 multiple argument and first argument with null ", () => {
24
- let output = compileClassNames(null, { class1: true });
25
- expect(output).toBe("class1")
26
- })
27
- test("should be multiple argument and first argument with null second arg as string ", () => {
28
- let output = compileClassNames(null, "class1");
29
- expect(output).toBe("class1")
30
- })
31
- test("should be empty input is empty object ", () => {
32
- let output = compileClassNames(["class1"]);
33
- expect(output).toBe("class1")
34
- })
35
- })
@@ -1,13 +0,0 @@
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
-
13
- })
@@ -1,4 +0,0 @@
1
- import createTemplateLiteral from '../createTemplateLiteral';
2
- describe("createTemplateLiteral",()=>{
3
- test("",()=>{})
4
- })
@@ -1,35 +0,0 @@
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(count = 0, options = {}) {
11
- if (typeof count === "string") {
12
- count = parseInt(count);
13
- }
14
- if (global.Intl && global.Intl.NumberFormat) {
15
- let numberFormat = Intl.NumberFormat(options.locale || "en", {
16
- notation: "compact"
17
- // compactDisplay: "short",
18
- });
19
- return numberFormat.format(count);
20
- }
21
- //Comaptibility
22
- const COUNT_ABBRS = ["", "K", "M", "G", "T", "P", "E", "Z", "Y"];
23
- let { withAbbr = true, decimals = 2 } = options;
24
- const i = 0 === count ? count : Math.floor(Math.log(count) / Math.log(1000));
25
- let result = parseFloat((count / Math.pow(1000, i)).toFixed(decimals));
26
- if (withAbbr) {
27
- result += `${COUNT_ABBRS[i]}`;
28
- }
29
- return result;
30
- }
31
-
32
- /* need discussion
33
- 1001 => 1K+
34
-
35
- G, T, P, E, Z,Y are needed in practical */
@@ -1,19 +0,0 @@
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
-
11
- export const accessKeyNames = {
12
- 'tab' : 'tab',
13
- 'enter' : 'enter',
14
- 'space' : 'space',
15
- 'arrowleft' : 'arrowleft',
16
- 'arrowtop' : 'arrowtop',
17
- 'arrowright' : 'arrowright',
18
- 'arrowbottom' : 'arrowbottom'
19
- }
@@ -1,32 +0,0 @@
1
- /**
2
- * Opening the customization, need to addd for behaviour changes. also add only enabled.
3
- * @param {*} style
4
- * @param {*} options
5
- * Example code
6
- * <Component openToCutsomize={{prefix:'dot'}} />
7
- * let style = applyOpenToCustomize(style,openToCutsomize)
8
- */
9
- export default function applyOpenToCustomize(style, options) {
10
-
11
- let resultStyle = style;
12
-
13
- if (options && options.prefix) {
14
-
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
-
31
- return resultStyle;
32
- }
@@ -1,52 +0,0 @@
1
- const REPLACER_SYMBOL = "$";
2
-
3
- /**
4
- *
5
- * if two is same ==> do the think if replace do, if append do.
6
- * replace vs append ==> append
7
- * append vs replace ==> replace
8
- * @param {*} style1
9
- * @param {*} style2
10
- * @returns
11
- */
12
- export default function combineCustomStyle(style1, style2) {
13
-
14
- let resultStyle = { ...style1};
15
-
16
- Object.keys(style2).forEach(styleName => {
17
-
18
- let oldStyleName = style1[`$${styleName}`] ? `$${styleName}` : styleName;
19
-
20
- if (oldStyleName.startsWith(REPLACER_SYMBOL) && styleName.startsWith(REPLACER_SYMBOL)) {
21
-
22
- resultStyle[styleName] = style2[styleName];
23
-
24
- }
25
- else if ( !oldStyleName.startsWith(REPLACER_SYMBOL) && !styleName.startsWith(REPLACER_SYMBOL) ) {
26
-
27
- resultStyle[styleName] = `${resultStyle[styleName]} ${style2[styleName]}`;
28
-
29
- }
30
- else{
31
- delete resultStyle[oldStyleName];
32
- resultStyle[styleName] = style2[styleName];
33
- }
34
-
35
- /*else if (oldStyleName.startsWith(REPLACER_SYMBOL) && !styleName.startsWith(REPLACER_SYMBOL) ) {
36
-
37
- delete resultStyle[oldStyleName];
38
- resultStyle[styleName] = style2[styleName];
39
-
40
- }
41
- else if (!oldStyleName.startsWith(REPLACER_SYMBOL) && styleName.startsWith(REPLACER_SYMBOL) ) {
42
-
43
- delete resultStyle[oldStyleName];
44
- resultStyle[styleName] = style2[styleName];
45
-
46
- }*/
47
-
48
- });
49
-
50
- return resultStyle;
51
-
52
- }
@@ -1,156 +0,0 @@
1
- import dataTypes, { isDataTypeOf } from "./dataTypes";
2
- import { hasOwnProperty, isToStringReferenceEqual } from "./objectUtils";
3
-
4
- /**
5
- *
6
- * @param {object} classinfoList
7
- * @returns {string}
8
- */
9
- const collectClassNames = (processedClassNameList,...classinfoList) => {
10
-
11
- for (let index = 0; index < classinfoList.length; index++) {
12
-
13
- let classInfo = classinfoList[index];
14
-
15
- if (!classInfo) {
16
- continue;
17
- }
18
-
19
- if (isDataTypeOf(classInfo, dataTypes.string) || isDataTypeOf(classInfo, dataTypes.number)) {
20
- processedClassNameList.push(classInfo);
21
- }
22
- else if (isDataTypeOf(classInfo, dataTypes.array)) {
23
- processedClassNameList.push(collectClassNames.apply(null, classInfo));
24
- }
25
- else if (isDataTypeOf(classInfo, dataTypes.object)) {
26
-
27
- for (let property in classInfo) {
28
- if (hasOwnProperty.call(classInfo, property) && classInfo[property]) {
29
- processedClassNameList.push(property==="undefined"?'':property);
30
- }
31
- }
32
-
33
- }
34
- }
35
-
36
- }
37
-
38
- export default function compileClassNames(...classinfoList){
39
- let resultClassNameList = [];
40
- collectClassNames(resultClassNameList,...classinfoList);
41
- return resultClassNameList.join(' ');
42
- };
43
-
44
-
45
- /* discussion
46
- passing object is enough i think. remaining option needed!!!
47
- */
48
-
49
-
50
- //18-Nov-2021 code review changes updated.
51
-
52
- /*
53
- >>>>>>>>>>Code Review Suggestion Starts >>>>>>
54
- let hasOwn = {}.hasOwnProperty;
55
-
56
- Accounting readability, please change this to Object.hasOwnProperty
57
-
58
- ---
59
- const compileClassNames = (...props)=>{
60
- Please check the alternate term - collate -> collateClassNames -> Collect and Combine the classnames.
61
- ---
62
-
63
- for (let i = 0; i < props.length; i++) {
64
-
65
- Please try to to stick with functional programming. Again for the readability perspective.
66
- Also, please stick with naming conventions for variables (i -> index).
67
-
68
- ---
69
- if (argType === 'string' || argType === 'number') {
70
- classes.push(this && this[arg] || arg);
71
- } else if (Array.isArray(arg)) {
72
- classes.push(compileClassNames.apply(this, arg));
73
- } else if (argType === 'object') {
74
- if (arg.toString === Object.prototype.toString) {
75
- for (let key in arg) {
76
- if (hasOwn.call(arg, key) && arg[key]) {
77
- classes.push(this && this[key] || key);
78
- }
79
- }
80
- } else {
81
- classes.push(arg.toString());
82
- }
83
- }
84
- }
85
- 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.
86
- Please check the possibility of avoiding the usage of 'this' statement due to its complexity in understanding the concept.
87
-
88
- ---
89
- Please write a functional method for the below line for easier understanding
90
-
91
- if (arg.toString === Object.prototype.toString) {
92
-
93
- ---
94
-
95
- Adding dedicated method to get the datatype of variables will help to stick on the SRP.
96
- ---
97
- Check the possibility of providing platform to extend the algorithm works for other data structures like Map, WeakMap,etc..
98
-
99
- >>>>>>> Code Review Suggestion Ends >>>>>>>>>>>>>>>>
100
- */
101
-
102
- /*
103
-
104
- >>>>>> Alternative Implementation Starts >>>>>>>>>>>>>>>>
105
-
106
- let boundHasOwnMethod = Object.hasOwnProperty;
107
-
108
- const collateClassNames = (...classinfoList) =>{
109
- let processedClassNameList = [];
110
- classinfoList.forEach( ( classInfo,index )=>{
111
- if(!classInfo)
112
- {
113
- // continue the next iteration
114
- return;
115
- }
116
- let dataTypeofClassInfo = getDataType(classInfo);
117
- if (dataTypeofClassInfo === 'string' || dataTypeofClassInfo === 'number')
118
- {
119
- processedClassNameList.push(classInfo);
120
- }
121
- else if(dataTypeofClassInfo === 'array')
122
- {
123
- processedClassNameList.push(collateClassNames(...classInfo));
124
- }
125
- else if(dataTypeofClassInfo === 'object')
126
- {
127
- for (let property in classInfo) {
128
- if (boundHasOwnMethod.call(classInfo,property ) && classInfo[property]) {
129
- processedClassNameList.push(property);
130
- }
131
- }
132
- }
133
-
134
-
135
- });
136
- const joinClassNames = processedClassNameList.join(' ');
137
- return joinClassNames;
138
-
139
- }
140
-
141
- const getDataType = (data)=>{
142
- let dataTypeofClassInfo = typeof data;
143
- let isArrayDataType = Array.isArray(data) === true;
144
- if(isArrayDataType)
145
- {
146
- return 'array';
147
- }
148
- else
149
- {
150
- return dataTypeofClassInfo;
151
- }
152
-
153
- };
154
-
155
- >>>>>>>>>>>>>>>> Alternative Implementation Ends>>>>>>>>>>>>>>
156
- */
@@ -1 +0,0 @@
1
- export * from "./uiProps";
@@ -1,41 +0,0 @@
1
- export const variantList = {
2
- outlined: 'variant_outlined',
3
- contained: 'variant_contained',
4
- flushed: 'variant_flushed',
5
- plain: 'variant_plain'
6
- };
7
-
8
- export const variants = Object.values(variantList);
9
-
10
- export const sizeList = {
11
- xsmall: 'size_xsmall',
12
- small: 'size_small',
13
- medium: 'size_medium',
14
- large: 'size_large',
15
- xlarge: 'size_xlarge'
16
- };
17
-
18
- export const sizeKeys = Object.keys(sizeList);
19
- export const sizes = Object.values(sizeList);
20
-
21
- export const colorList = {
22
- danger: 'color_danger',
23
- success: 'color_success',
24
- info: 'color_info',
25
- primary: 'color_primary',
26
- secondary: 'color_secondary',
27
- warning: 'color_warning'
28
- };
29
-
30
- export const colorKeys = Object.keys(colorList);
31
- export const colors = Object.values(colorList);
32
-
33
- export const shapeList = {
34
- circle: 'shape_circle',
35
- oval: 'shape_oval',
36
- square: 'shape_square',
37
- roundedRect: 'shape_roundedRect',
38
- rounded: 'shape_rounded'
39
- };
40
-
41
- export const shapes = Object.values(shapeList);
@@ -1,14 +0,0 @@
1
- import { createContext } from 'react';
2
-
3
- const context = {}
4
- /**
5
- *
6
- * @param {string} name
7
- * @returns {object}
8
- */
9
- export default function contextFactory(name) {
10
- if (!context[name]) {
11
- context[name] = createContext();
12
- }
13
- return context[name]
14
- }
@@ -1,73 +0,0 @@
1
- export default function createTemplateLiteral(templateStrings, ...expressionKeys) {
2
-
3
- return ( ...expressionValues) => {
4
-
5
- let resultString = [templateStrings[0]];
6
- expressionKeys.forEach(function (expressionKey, i) {
7
- let expressionValue = expressionValues[i];
8
- let nextTemplateString = templateStrings[i + 1];
9
- if (expressionValue === null || expressionValue === undefined || expressionValue === "") {
10
- nextTemplateString = nextTemplateString.replace(/^_/, '');
11
- }
12
- resultString.push(expressionValue, nextTemplateString);
13
- });
14
-
15
- let resultStr = resultString.join('');
16
- resultStr = resultStr.replace(/_$/, '');
17
- return resultStr;
18
- };
19
- }
20
-
21
-
22
-
23
- /* refer the doc https://developers.google.com/web/updates/2015/01/ES6-Template-Strings
24
-
25
- UnderSatnd the terms - String interpolation, Embedded expressions
26
-
27
- Go through the topic https://developers.google.com/web/updates/2015/01/ES6-Template-Strings#tagged_templates
28
-
29
- Things to note fn`Hello ${you}! You're looking ${adjective} today!` desugars to fn(["Hello ", "! You're looking ", " today!"], you, adjective);
30
-
31
- Please go through the example code
32
-
33
- Our implementation constructCustomMessage is the handler for the tagged template function.
34
- It receives the static words and its substitutions as seen above as the arguments.
35
-
36
- It returns a function that receives the values for the substitutions. Upon passing the values for the inner function
37
- it executes the algorithm as mentioned in the doc to construct the final message.
38
- "The (n + 1)th argument corresponds to the substitution that takes place between the nth and (n + 1)th entries in the string array"
39
-
40
-
41
- function constructCustomMessage(staticWordsList, ...embeddedExpressionKeyList)
42
- {
43
- return (...valuesForEmbeddedExpressionList)=>{
44
-
45
- let finalMessage = staticWordsList[0];
46
- embeddedExpressionKeyList.forEach(function(expressionKey, index) {
47
- let expressionValue = valuesForEmbeddedExpressionList[index];
48
- let nextStaticWord = staticWordsList[index+1];
49
- if(expressionValue===null || expressionValue === undefined || expressionValue === ""){
50
- // Replace the underscore '_' present at the beginning of string with empty value.
51
- nextStaticWord = nextStaticWord.replace(/^_/, '');
52
- }
53
- finalMessage += expressionValue + nextStaticWord;
54
-
55
- });
56
- // Replace the underscore '_' present at the end of string with empty value.
57
- finalMessage = finalMessage.replace(/_$/,'');
58
- return finalMessage ;
59
- };
60
-
61
- }
62
- */
63
-
64
- /*
65
- Sample Invocation Format
66
-
67
- var username;
68
- var tag;
69
- var handlerFunctiontoFormMessage = constructCustomMessage`<b>${username} says</b>: "${tag}"`;
70
- var outputString = handlerFunctiontoFormMessage('Mani Venkat', '& is a fun tag');
71
- console.log(outputString);
72
-
73
- */
package/src/dataTypes.js DELETED
@@ -1,30 +0,0 @@
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
-
13
- export const getDataType = (data)=>{
14
- let typeofData = typeof data;
15
- let isArrayDataType = Array.isArray(data);
16
- if(isArrayDataType)
17
- {
18
- return dataTypes.array;
19
- }
20
- else
21
- {
22
- return dataTypes[typeofData];
23
- }
24
- };
25
-
26
- export const isDataTypeOf=(data,type)=>{
27
- return getDataType(data) === type;
28
- }
29
-
30
- export default dataTypes;
package/src/debounce.js DELETED
@@ -1,13 +0,0 @@
1
- export default function debounce(fn, delay) {
2
- let handle = null
3
-
4
- return function () {
5
- if (handle) {
6
- handle = clearTimeout(handle)
7
- }
8
-
9
- handle = setTimeout(() => {
10
- fn(...arguments)
11
- }, delay)
12
- }
13
- }
@@ -1,69 +0,0 @@
1
- // import PropTypes from "prop-types";
2
- // import mergeStyle from "./mergeStyle";
3
- // import { Button } from "../../base/src/Button/index";
4
- // export default (props)=>{
5
-
6
- // let { customStyle, openCustomStyle} = props;
7
-
8
- // return {
9
- // customStyle,
10
- // openDefaultToCustomize
11
- // };
12
-
13
- // }
14
-
15
-
16
- // if two is same ==> do the think replace with last , append at end
17
-
18
- // replace vs append ==> append
19
- // append vs replace ==> replace
20
-
21
-
22
- // DotButton.js
23
- // DotButton.module.css
24
- // function DotButton({ customStyle }){
25
-
26
- // dotButdefault => customStyle : {
27
- // base : DotButton.style.pols
28
- // }
29
-
30
- // props => customStyle {
31
- // base :
32
- // }
33
-
34
- // return <Button customStyle={}></Button>
35
- // }
36
-
37
- // Button => set of compoents
38
- // DotButton => set of comepons
39
-
40
- // function creatButtonWithIcon({Button,Icon}){
41
-
42
- // return (props)=>{
43
-
44
- // customStyle={}
45
- // return <Button customStyle={ssss}>
46
-
47
- // <Icon></Icon>
48
- // </Button>
49
-
50
- // }
51
-
52
- // }
53
-
54
-
55
- // Button1.js
56
- // Icon1.js
57
- // creatButtonWithIcon({
58
-
59
- // Button : Button1,
60
- // Icon : Icon1
61
-
62
- // });
63
-
64
- // Button1custome(props){
65
-
66
- // props.customStyle
67
- // combineCustomStyle()
68
- // return Button
69
- // }
@@ -1,9 +0,0 @@
1
- import compileClassNames from "./compileClassNames";
2
-
3
- export default (customClassName, ...props) => {
4
-
5
- let isPlainClassName = typeof customClassName === "string" ? true : false;
6
- return compileClassNames(...props, {
7
- [customClassName]: !!isPlainClassName
8
- });
9
- }
@@ -1,15 +0,0 @@
1
- export default (
2
- { customId, customIdPrefix = "", customIdSuffix = "" },
3
- defaultCustomId,
4
- otherCustomOption=[]
5
- ) => {
6
- let returnId = customId;
7
-
8
- if (typeof defaultCustomId === "function") {
9
- let options = [ '',customIdPrefix, customIdSuffix, ...otherCustomOption];
10
- returnId = defaultCustomId.apply(null,options);
11
- //returnId = defaultCustomId`${customIdPrefix} ${customIdSuffix}`;
12
- }
13
-
14
- return returnId ? returnId.toLowerCase() : null;
15
- };
package/src/index.js DELETED
@@ -1,10 +0,0 @@
1
- export { default as debounce } from './debounce';
2
- export { default as uniqueNumber } from './uniqueNumber'
3
- export { default as omit } from './omit';
4
- export { default as mergeStyle } from './mergeStyle'
5
- export { default as applyOpenToCustomize } from './applyOpenToCustomize';
6
- export { default as combineCustomStyle } from './combineCustomStyle'
7
- export { default as compileClassNames } from './compileClassNames';
8
- export { default as ErrorBoundary } from './ErrorBoundary'
9
- export { default as loadResource } from './loadResource'
10
- export { default as accessKeyCodes, accessKeyNames } from "./accessKeyCodes";
@@ -1,10 +0,0 @@
1
- export default function isTouchDevice() {
2
- if (('ontouchstart' in window) ||
3
- (navigator.maxTouchPoints > 0) ||
4
- (navigator.msMaxTouchPoints > 0)) {
5
- /* browser with either Touch Events of Pointer Events
6
- running on touch-capable device */
7
- return true;
8
- }
9
- return false;
10
- }
@@ -1,45 +0,0 @@
1
- /* eslint-disable import/prefer-default-export */
2
- /* use promise and remove callback */
3
- export default function loadResource(url, type, id, callback, needDefer = true) {
4
- return new Promise((resolve) => {
5
- let css;
6
- let script;
7
- if (id && document.getElementById(id)) {
8
- resolve();
9
- return;
10
- }
11
- if (type === 'css') {
12
- css = document.createElement('link');
13
- css.type = 'text/css';
14
- css.rel = 'stylesheet';
15
- css.href = url;
16
- css.id = id || '';
17
- css.onload = function () {
18
- resolve();
19
- };
20
- css.onerror = function () {
21
- resolve();
22
- };
23
- document.getElementsByTagName('head')[0].appendChild(css);
24
- } else if (type === 'js') {
25
- script = document.createElement('script');
26
- script.type = 'text/javascript';
27
- script.src = url;
28
- script.defer = needDefer;
29
-
30
- script.onload = function () {
31
- resolve();
32
- if (id) {
33
- script.id = id;
34
- }
35
- if (typeof callback === 'function') {
36
- callback();
37
- }
38
- };
39
- script.onerror = function () {
40
- resolve();
41
- };
42
- document.getElementsByTagName('head')[0].appendChild(script);
43
- }
44
- });
45
- }
package/src/mergeStyle.js DELETED
@@ -1,31 +0,0 @@
1
- /**
2
- * REPLACER_SYMBOL used to indentify
3
- */
4
- const REPLACER_SYMBOL = "$";
5
- /**
6
- * $ startWith is used for replace the existing style.
7
- * all other will be append
8
- * @param {*} defaultStyle
9
- * @param {*} customStyle
10
- * @returns
11
- */
12
- export default function mergeStyle(defaultStyle, customStyle) {
13
- return Object.keys(customStyle).reduce((res, next) => {
14
- if (next.startsWith(REPLACER_SYMBOL)) {
15
- let styleValue = customStyle[next];
16
- let styleName = next.replace(REPLACER_SYMBOL, "");
17
-
18
- if (!defaultStyle[styleName]) {
19
- return res;
20
- }
21
-
22
- res[styleName] = styleValue;
23
- } else if (defaultStyle[next]) {
24
- res[next] = defaultStyle[next] + " " + customStyle[next];
25
- }
26
-
27
- return res;
28
- }, { ...defaultStyle
29
- });
30
-
31
- }
@@ -1,4 +0,0 @@
1
- export const hasOwnProperty = Object.hasOwnProperty;
2
- export const isToStringReferenceEqual =(data)=>{
3
- return data.toString === Object.prototype.toString
4
- }
package/src/omit.js DELETED
@@ -1,10 +0,0 @@
1
- export default (keys) => {
2
- return function omit(obj) {
3
- return Object.keys(obj).reduce((res, next) => {
4
- if (!keys.includes(next)) {
5
- res[next] = obj[next];
6
- }
7
- return res;
8
- }, {})
9
- }
10
- }
@@ -1,8 +0,0 @@
1
- import PropTypes from 'prop-types';
2
-
3
- export const automationPropsName = 'customId';
4
- export default {
5
- customId: PropTypes.oneOfType([PropTypes.string, PropTypes.object]),
6
- customIdPrefix: PropTypes.string,
7
- customIdSuffix: PropTypes.string
8
- };
@@ -1,7 +0,0 @@
1
- import PropTypes from 'prop-types';
2
-
3
- export default {
4
- customReducer: PropTypes.func
5
- };
6
-
7
- export const customReducer = 'customReducer';
@@ -1,10 +0,0 @@
1
- import PropTypes from 'prop-types';
2
-
3
- export default {
4
- customStyle: PropTypes.object
5
- };
6
-
7
- /**
8
- * Prop Name
9
- */
10
- export const customStyle = "customStyle";
@@ -1,7 +0,0 @@
1
- import PropTypes from 'prop-types';
2
-
3
- export default {
4
- 'aria-label': PropTypes.string,
5
- 'aria-labelledby': PropTypes.string,
6
- tabIndex: PropTypes.oneOfType([PropTypes.string, PropTypes.number])
7
- };
@@ -1,40 +0,0 @@
1
- import PropTypes from 'prop-types';
2
-
3
- const attributesList = [
4
- "tabIndex"
5
- ];
6
-
7
- const dataAttribute = "^data|on";
8
-
9
- export const tagAttributesPropType = function(props, propName, componentName ) {
10
-
11
- if( Object.prototype.toString.call(props) !== "[object Object]"){
12
-
13
- console.error(`Warning: Failed prop type: Invalid prop \`${propName}\` of type \`${ props ? (typeof props) : undefined}\` supplied to \`${componentName}\`, expected \`object\`.`);
14
-
15
- }
16
-
17
- let curPattern = new RegExp(`^(${attributesList.join("|")})$`);
18
- let curPattern2 = new RegExp(dataAttribute);
19
-
20
- Object.keys(props[propName]).forEach((keyName)=>{
21
-
22
- if( !(curPattern.test( keyName ) || curPattern2.test(keyName)) ){
23
-
24
- console.warn(`Warning: these attributes name ${keyName} are not allowed in ${propName}`);
25
-
26
- }
27
-
28
- });
29
-
30
- }
31
-
32
- export default {
33
- tagAttributes: tagAttributesPropType
34
- }
35
-
36
-
37
- /**
38
- * tagAttributes - is used to spread these attributes for events customize and override few attributes.
39
- */
40
- export const tagAttributes = "tagAttributes";
@@ -1,48 +0,0 @@
1
- import PropTypes from 'prop-types';
2
-
3
- const attributesList = [
4
- "accesskey",
5
- "contentEditable",
6
- "dir",
7
- "draggable",
8
- "hidden",
9
- "lang",
10
- "tabIndex",
11
- "title",
12
- "spellcheck",
13
- "translate"
14
- ];
15
-
16
- const dataAttribute = "^data|on";
17
-
18
- export const tagGeneralAttributesPropType = function(props, propName, componentName ) {
19
-
20
- if( Object.prototype.toString.call(props) !== "[object Object]"){
21
-
22
- console.error(`Warning: Failed prop type: Invalid prop \`${propName}\` of type \`${ props ? (typeof props) : undefined}\` supplied to \`${componentName}\`, expected \`object\`.`);
23
-
24
- }
25
-
26
- let curPattern = new RegExp(`^(${attributesList.join("|")})$`);
27
- let curPattern2 = new RegExp(dataAttribute);
28
-
29
- Object.keys(props[propName]).forEach((keyName)=>{
30
-
31
- if( !(curPattern.test( keyName ) || curPattern2.test(keyName)) ){
32
-
33
- console.warn(`Warning: these attributes name ${keyName} are not allowed in tagGeneralAttributes`);
34
-
35
- }
36
-
37
- });
38
-
39
- }
40
-
41
- export default {
42
- tagGeneralAttributes: tagGeneralAttributesPropType
43
- }
44
-
45
- /**
46
- * tagGeneralAttributes - is to spread the global attributes in component.
47
- */
48
- export const tagGeneralAttributes = "tagGeneralAttributes";
@@ -1,72 +0,0 @@
1
- /* eslint-disable no-labels */
2
- /* eslint-disable no-restricted-syntax */
3
- import PropTypes from 'prop-types';
4
-
5
- import { variants , colors, sizes, shapes } from "../constantProps";
6
-
7
- export const getVariantProps = (variants,exvariant)=>{
8
- let variant=[];
9
- if(exvariant){
10
- variant=[...exvariant]
11
- }
12
- variant=[...variant,...variants]
13
- return(
14
- {variant:PropTypes.oneOf(variant)}
15
- )
16
- }
17
-
18
- export const variantProps = {
19
-
20
- variant : PropTypes.oneOf(variants)
21
- };
22
-
23
-
24
- export const getColorProps = (colors,excolors)=>{
25
- let color=[];
26
- if(excolors){
27
- color=[...excolors]
28
- }
29
- color=[...color,...colors]
30
- return(
31
- {color:PropTypes.oneOf(color)}
32
- )
33
-
34
- };
35
-
36
-
37
- export const colorProps = {
38
- color : PropTypes.oneOf(colors)
39
- };
40
-
41
-
42
- export const getSizeProps = (sizes,exSizes)=>{
43
- let size=[];
44
- if(exSizes){
45
- size=[...exSizes]
46
- }
47
- size=[...size,...sizes]
48
- return(
49
- {size:PropTypes.oneOf(size)}
50
- )
51
- };
52
-
53
- export const sizeProps = {
54
-
55
- size : PropTypes.oneOf(sizes)
56
- };
57
-
58
- export const getShapeProps = (shapes,exshapes)=>{
59
- let shape=[];
60
- if(exshapes){
61
- shape=[...exshapes]
62
- }
63
- shape=[...shape,...shapes]
64
- return(
65
- {shape:PropTypes.oneOf(shape)}
66
- )
67
- };
68
-
69
- export const shapeProps = {
70
-
71
- shape : PropTypes.oneOf(shapes)
72
- };
@@ -1,23 +0,0 @@
1
- import { useReducer } from "react";
2
- export default function useCommonReducer(
3
- defaultReducer,
4
- customReducer,
5
- initialArg,
6
- init
7
- ) {
8
- const proxyReducer = (state, action) => {
9
- let lastState = defaultReducer(state, action);
10
-
11
- if (customReducer) {
12
- return customReducer(lastState, action);
13
- }
14
-
15
- return lastState;
16
- };
17
- const [state, dispatch] = useReducer(proxyReducer, initialArg, init);
18
-
19
- return {
20
- state,
21
- dispatch
22
- };
23
- }
@@ -1,3 +0,0 @@
1
- export default (object,search,replace)=>{
2
- return object.replace(search,replace);
3
- }
@@ -1,3 +0,0 @@
1
- export default function (object, search, replace) {
2
- return object.replace(new RegExp(search+"([^"+search+"]*)$"), replace+"$1");
3
- }
@@ -1,16 +0,0 @@
1
- export default function uniqueNumber(prefix=''){
2
- //let randomId = (Date.now() + Math.random()).toString(36);
3
- var date = Date.now();
4
-
5
- // If created at same millisecond as previous
6
- if (date <= uniqueNumber.previous) {
7
- date = ++uniqueNumber.previous;
8
- } else {
9
- uniqueNumber.previous = date;
10
- }
11
-
12
- return prefix ? `${prefix}-${date}` : date;
13
- }
14
-
15
- uniqueNumber.previous = 0;
16
-