@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
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
// import PropTypes from "prop-types";
|
|
2
|
+
// import mergeStyle from "./mergeStyle";
|
|
3
|
+
// import { Button } from "../../base/src/Button/index";
|
|
4
|
+
// export default (props)=>{
|
|
5
|
+
// let { customStyle, openCustomStyle} = props;
|
|
6
|
+
// return {
|
|
7
|
+
// customStyle,
|
|
8
|
+
// openDefaultToCustomize
|
|
9
|
+
// };
|
|
10
|
+
// }
|
|
11
|
+
// if two is same ==> do the think replace with last , append at end
|
|
12
|
+
// replace vs append ==> append
|
|
13
|
+
// append vs replace ==> replace
|
|
14
|
+
// DotButton.js
|
|
15
|
+
// DotButton.module.css
|
|
16
|
+
// function DotButton({ customStyle }){
|
|
17
|
+
// dotButdefault => customStyle : {
|
|
18
|
+
// base : DotButton.style.pols
|
|
19
|
+
// }
|
|
20
|
+
// props => customStyle {
|
|
21
|
+
// base :
|
|
22
|
+
// }
|
|
23
|
+
// return <Button customStyle={}></Button>
|
|
24
|
+
// }
|
|
25
|
+
// Button => set of compoents
|
|
26
|
+
// DotButton => set of comepons
|
|
27
|
+
// function creatButtonWithIcon({Button,Icon}){
|
|
28
|
+
// return (props)=>{
|
|
29
|
+
// customStyle={}
|
|
30
|
+
// return <Button customStyle={ssss}>
|
|
31
|
+
// <Icon></Icon>
|
|
32
|
+
// </Button>
|
|
33
|
+
// }
|
|
34
|
+
// }
|
|
35
|
+
// Button1.js
|
|
36
|
+
// Icon1.js
|
|
37
|
+
// creatButtonWithIcon({
|
|
38
|
+
// Button : Button1,
|
|
39
|
+
// Icon : Icon1
|
|
40
|
+
// });
|
|
41
|
+
// Button1custome(props){
|
|
42
|
+
// props.customStyle
|
|
43
|
+
// combineCustomStyle()
|
|
44
|
+
// return Button
|
|
45
|
+
// }
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import compileClassNames from "./compileClassNames";
|
|
2
|
+
export default (function (customClassName) {
|
|
3
|
+
let isPlainClassName = typeof customClassName === "string" ? true : false;
|
|
4
|
+
|
|
5
|
+
for (var _len = arguments.length, props = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
|
6
|
+
props[_key - 1] = arguments[_key];
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
return compileClassNames(...props, {
|
|
10
|
+
[customClassName]: !!isPlainClassName
|
|
11
|
+
});
|
|
12
|
+
});
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export default (function (_ref, defaultCustomId) {
|
|
2
|
+
let {
|
|
3
|
+
customId,
|
|
4
|
+
customIdPrefix = "",
|
|
5
|
+
customIdSuffix = ""
|
|
6
|
+
} = _ref;
|
|
7
|
+
let otherCustomOption = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];
|
|
8
|
+
let returnId = customId;
|
|
9
|
+
|
|
10
|
+
if (typeof defaultCustomId === "function") {
|
|
11
|
+
let options = ['', customIdPrefix, customIdSuffix, ...otherCustomOption];
|
|
12
|
+
returnId = defaultCustomId.apply(null, options); //returnId = defaultCustomId`${customIdPrefix} ${customIdSuffix}`;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
return returnId ? returnId.toLowerCase() : null;
|
|
16
|
+
});
|
package/es/index.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
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";
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export default function isTouchDevice() {
|
|
2
|
+
if ('ontouchstart' in window || navigator.maxTouchPoints > 0 || navigator.msMaxTouchPoints > 0) {
|
|
3
|
+
/* browser with either Touch Events of Pointer Events
|
|
4
|
+
running on touch-capable device */
|
|
5
|
+
return true;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
return false;
|
|
9
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/* eslint-disable import/prefer-default-export */
|
|
2
|
+
|
|
3
|
+
/* use promise and remove callback */
|
|
4
|
+
export default function loadResource(url, type, id, callback) {
|
|
5
|
+
let needDefer = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : true;
|
|
6
|
+
return new Promise(resolve => {
|
|
7
|
+
let css;
|
|
8
|
+
let script;
|
|
9
|
+
|
|
10
|
+
if (id && document.getElementById(id)) {
|
|
11
|
+
resolve();
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
if (type === 'css') {
|
|
16
|
+
css = document.createElement('link');
|
|
17
|
+
css.type = 'text/css';
|
|
18
|
+
css.rel = 'stylesheet';
|
|
19
|
+
css.href = url;
|
|
20
|
+
css.id = id || '';
|
|
21
|
+
|
|
22
|
+
css.onload = function () {
|
|
23
|
+
resolve();
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
css.onerror = function () {
|
|
27
|
+
resolve();
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
document.getElementsByTagName('head')[0].appendChild(css);
|
|
31
|
+
} else if (type === 'js') {
|
|
32
|
+
script = document.createElement('script');
|
|
33
|
+
script.type = 'text/javascript';
|
|
34
|
+
script.src = url;
|
|
35
|
+
script.defer = needDefer;
|
|
36
|
+
|
|
37
|
+
script.onload = function () {
|
|
38
|
+
resolve();
|
|
39
|
+
|
|
40
|
+
if (id) {
|
|
41
|
+
script.id = id;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
if (typeof callback === 'function') {
|
|
45
|
+
callback();
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
script.onerror = function () {
|
|
50
|
+
resolve();
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
document.getElementsByTagName('head')[0].appendChild(script);
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
}
|
package/es/mergeStyle.js
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
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
|
+
|
|
13
|
+
export default function mergeStyle(defaultStyle, customStyle) {
|
|
14
|
+
return Object.keys(customStyle).reduce((res, next) => {
|
|
15
|
+
if (next.startsWith(REPLACER_SYMBOL)) {
|
|
16
|
+
let styleValue = customStyle[next];
|
|
17
|
+
let styleName = next.replace(REPLACER_SYMBOL, "");
|
|
18
|
+
|
|
19
|
+
if (!defaultStyle[styleName]) {
|
|
20
|
+
return res;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
res[styleName] = styleValue;
|
|
24
|
+
} else if (defaultStyle[next]) {
|
|
25
|
+
res[next] = defaultStyle[next] + " " + customStyle[next];
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
return res;
|
|
29
|
+
}, { ...defaultStyle
|
|
30
|
+
});
|
|
31
|
+
}
|
package/es/omit.js
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import PropTypes from 'prop-types';
|
|
2
|
+
const attributesList = ["tabIndex"];
|
|
3
|
+
const dataAttribute = "^data|on";
|
|
4
|
+
export const tagAttributesPropType = function (props, propName, componentName) {
|
|
5
|
+
if (Object.prototype.toString.call(props) !== "[object Object]") {
|
|
6
|
+
console.error(`Warning: Failed prop type: Invalid prop \`${propName}\` of type \`${props ? typeof props : undefined}\` supplied to \`${componentName}\`, expected \`object\`.`);
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
let curPattern = new RegExp(`^(${attributesList.join("|")})$`);
|
|
10
|
+
let curPattern2 = new RegExp(dataAttribute);
|
|
11
|
+
Object.keys(props[propName]).forEach(keyName => {
|
|
12
|
+
if (!(curPattern.test(keyName) || curPattern2.test(keyName))) {
|
|
13
|
+
console.warn(`Warning: these attributes name ${keyName} are not allowed in ${propName}`);
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
};
|
|
17
|
+
export default {
|
|
18
|
+
tagAttributes: tagAttributesPropType
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* tagAttributes - is used to spread these attributes for events customize and override few attributes.
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
export const tagAttributes = "tagAttributes";
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import PropTypes from 'prop-types';
|
|
2
|
+
const attributesList = ["accesskey", "contentEditable", "dir", "draggable", "hidden", "lang", "tabIndex", "title", "spellcheck", "translate"];
|
|
3
|
+
const dataAttribute = "^data|on";
|
|
4
|
+
export const tagGeneralAttributesPropType = function (props, propName, componentName) {
|
|
5
|
+
if (Object.prototype.toString.call(props) !== "[object Object]") {
|
|
6
|
+
console.error(`Warning: Failed prop type: Invalid prop \`${propName}\` of type \`${props ? typeof props : undefined}\` supplied to \`${componentName}\`, expected \`object\`.`);
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
let curPattern = new RegExp(`^(${attributesList.join("|")})$`);
|
|
10
|
+
let curPattern2 = new RegExp(dataAttribute);
|
|
11
|
+
Object.keys(props[propName]).forEach(keyName => {
|
|
12
|
+
if (!(curPattern.test(keyName) || curPattern2.test(keyName))) {
|
|
13
|
+
console.warn(`Warning: these attributes name ${keyName} are not allowed in tagGeneralAttributes`);
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
};
|
|
17
|
+
export default {
|
|
18
|
+
tagGeneralAttributes: tagGeneralAttributesPropType
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* tagGeneralAttributes - is to spread the global attributes in component.
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
export const tagGeneralAttributes = "tagGeneralAttributes";
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/* eslint-disable no-labels */
|
|
2
|
+
|
|
3
|
+
/* eslint-disable no-restricted-syntax */
|
|
4
|
+
import PropTypes from 'prop-types';
|
|
5
|
+
import { variants, colors, sizes, shapes } from "../constantProps";
|
|
6
|
+
export const getVariantProps = (variants, exvariant) => {
|
|
7
|
+
let variant = [];
|
|
8
|
+
|
|
9
|
+
if (exvariant) {
|
|
10
|
+
variant = [...exvariant];
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
variant = [...variant, ...variants];
|
|
14
|
+
return {
|
|
15
|
+
variant: PropTypes.oneOf(variant)
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
export const variantProps = {
|
|
19
|
+
variant: PropTypes.oneOf(variants)
|
|
20
|
+
};
|
|
21
|
+
export const getColorProps = (colors, excolors) => {
|
|
22
|
+
let color = [];
|
|
23
|
+
|
|
24
|
+
if (excolors) {
|
|
25
|
+
color = [...excolors];
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
color = [...color, ...colors];
|
|
29
|
+
return {
|
|
30
|
+
color: PropTypes.oneOf(color)
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
export const colorProps = {
|
|
34
|
+
color: PropTypes.oneOf(colors)
|
|
35
|
+
};
|
|
36
|
+
export const getSizeProps = (sizes, exSizes) => {
|
|
37
|
+
let size = [];
|
|
38
|
+
|
|
39
|
+
if (exSizes) {
|
|
40
|
+
size = [...exSizes];
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
size = [...size, ...sizes];
|
|
44
|
+
return {
|
|
45
|
+
size: PropTypes.oneOf(size)
|
|
46
|
+
};
|
|
47
|
+
};
|
|
48
|
+
export const sizeProps = {
|
|
49
|
+
size: PropTypes.oneOf(sizes)
|
|
50
|
+
};
|
|
51
|
+
export const getShapeProps = (shapes, exshapes) => {
|
|
52
|
+
let shape = [];
|
|
53
|
+
|
|
54
|
+
if (exshapes) {
|
|
55
|
+
shape = [...exshapes];
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
shape = [...shape, ...shapes];
|
|
59
|
+
return {
|
|
60
|
+
shape: PropTypes.oneOf(shape)
|
|
61
|
+
};
|
|
62
|
+
};
|
|
63
|
+
export const shapeProps = {
|
|
64
|
+
shape: PropTypes.oneOf(shapes)
|
|
65
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { useReducer } from "react";
|
|
2
|
+
export default function useCommonReducer(defaultReducer, customReducer, initialArg, init) {
|
|
3
|
+
const proxyReducer = (state, action) => {
|
|
4
|
+
let lastState = defaultReducer(state, action);
|
|
5
|
+
|
|
6
|
+
if (customReducer) {
|
|
7
|
+
return customReducer(lastState, action);
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
return lastState;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
const [state, dispatch] = useReducer(proxyReducer, initialArg, init);
|
|
14
|
+
return {
|
|
15
|
+
state,
|
|
16
|
+
dispatch
|
|
17
|
+
};
|
|
18
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export default function uniqueNumber() {
|
|
2
|
+
let prefix = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
|
|
3
|
+
//let randomId = (Date.now() + Math.random()).toString(36);
|
|
4
|
+
var date = Date.now(); // If created at same millisecond as previous
|
|
5
|
+
|
|
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
|
+
uniqueNumber.previous = 0;
|
package/package.json
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@zohodesk/utils",
|
|
3
|
+
"version": "1.0.1-alpha.2057+759889c1",
|
|
4
|
+
"description": "",
|
|
5
|
+
"private": false,
|
|
6
|
+
"publishConfig": {
|
|
7
|
+
"access": "public"
|
|
8
|
+
},
|
|
9
|
+
"main": "es/index.js",
|
|
10
|
+
"scripts": {
|
|
11
|
+
"build": "type react-cli && react-cli build:component:es",
|
|
12
|
+
"build_watch": "react-cli build:component:es -w",
|
|
13
|
+
"clean": "react-cli clean unittest coverage es result.json",
|
|
14
|
+
"rtl": "react-cli rtl ./src ./es",
|
|
15
|
+
"nodefix": "node ../buildtool_patch.js",
|
|
16
|
+
"prepare": "npm run clean && npm run build && npm run rtl",
|
|
17
|
+
"test": "react-cli test"
|
|
18
|
+
},
|
|
19
|
+
"author": "",
|
|
20
|
+
"license": "ISC",
|
|
21
|
+
"gitHead": "759889c1ce980ee197ec9f4117f2608120838b6f"
|
|
22
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
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
|
+
}
|
|
@@ -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
|
+
|
|
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
|
+
})
|
|
@@ -0,0 +1,35 @@
|
|
|
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
|
+
})
|
|
@@ -0,0 +1,13 @@
|
|
|
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
|
+
})
|
|
@@ -0,0 +1,35 @@
|
|
|
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 */
|
|
@@ -0,0 +1,19 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
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
|
+
}
|