@zohodesk/utils 1.0.0-temp-1

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 (45) hide show
  1. package/README.md +42 -0
  2. package/es/ErrorBoundary.js +29 -0
  3. package/es/StringUtils.js +290 -0
  4. package/es/abbreviateNumber.js +44 -0
  5. package/es/accessKeyCodes.js +18 -0
  6. package/es/applyOpenToCustomize.js +29 -0
  7. package/es/combineCustomStyle.js +39 -0
  8. package/es/compileClassNames.js +29 -0
  9. package/es/constantProps/constant.js +2 -0
  10. package/es/constantProps/index.js +1 -0
  11. package/es/constantProps/uiProps.js +50 -0
  12. package/es/contextFactory.js +15 -0
  13. package/es/createTemplateLiteral.js +77 -0
  14. package/es/crud/ArrayManager.js +63 -0
  15. package/es/crud/ObjectManager.js +54 -0
  16. package/es/crud/arrayCRUD.js +76 -0
  17. package/es/crud/objectCRUD.js +49 -0
  18. package/es/dataTypes.js +25 -0
  19. package/es/debounce.js +12 -0
  20. package/es/deepEqual.js +26 -0
  21. package/es/disCustomStyleProps.js +45 -0
  22. package/es/getCompliedClassName.js +12 -0
  23. package/es/getCompliedCustomId.js +16 -0
  24. package/es/getCurrentTime.js +10 -0
  25. package/es/getCustomBoundingClientRect.js +11 -0
  26. package/es/index.js +11 -0
  27. package/es/isTouchDevice.js +9 -0
  28. package/es/jsonToQueryString.js +6 -0
  29. package/es/loadResource.js +56 -0
  30. package/es/mergeStyle.js +53 -0
  31. package/es/objectUtils.js +4 -0
  32. package/es/omit.js +11 -0
  33. package/es/props/automationProps.js +7 -0
  34. package/es/props/customReducerPropTypes.js +5 -0
  35. package/es/props/customStyleProps.js +9 -0
  36. package/es/props/generalAriaProps.js +6 -0
  37. package/es/props/tagAttributeProps.js +35 -0
  38. package/es/props/tagGeneralAttributeProps.js +35 -0
  39. package/es/props/uiProps.js +95 -0
  40. package/es/reducerHandler.js +18 -0
  41. package/es/renderNode.js +28 -0
  42. package/es/replaceAtFirst.js +3 -0
  43. package/es/replaceAtLast.js +3 -0
  44. package/es/uniqueNumber.js +14 -0
  45. package/package.json +35 -0
@@ -0,0 +1,95 @@
1
+ /* eslint-disable no-labels */
2
+
3
+ /* eslint-disable no-restricted-syntax */
4
+ import PropTypes from 'prop-types';
5
+ import { variants, colors, sizes, shapes, decorations, positions } 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
+ };
66
+ export const getDecorationProps = (decorations, exDecorations) => {
67
+ let decoration = [];
68
+
69
+ if (exDecorations) {
70
+ decoration = [...exDecorations];
71
+ }
72
+
73
+ decoration = [...decoration, ...decorations];
74
+ return {
75
+ textDecoration: PropTypes.oneOf(decoration)
76
+ };
77
+ };
78
+ export const decorationProps = {
79
+ decoration: PropTypes.oneOf(decorations)
80
+ };
81
+ export const getPositionProps = (positions, expositions) => {
82
+ let position = [];
83
+
84
+ if (expositions) {
85
+ position = [...expositions];
86
+ }
87
+
88
+ position = [...position, ...positions];
89
+ return {
90
+ position: PropTypes.oneOf(position)
91
+ };
92
+ };
93
+ export const positionProps = {
94
+ position: PropTypes.oneOf(positions)
95
+ };
@@ -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,28 @@
1
+ import React, { isValidElement } from 'react';
2
+ /**
3
+ * Utility function to render content that can be either a function or a React element
4
+ * @param {Function|React.ReactElement|null|undefined} content - The content to render
5
+ * @param {Object} props - Optional props to pass to the function if content is a function
6
+ * @returns {React.ReactElement|null} - The rendered content or null
7
+ */
8
+
9
+ export default function renderNode(content, props) {
10
+ let result = content;
11
+
12
+ if (typeof content === 'function') {
13
+ result = content(props);
14
+ }
15
+
16
+ return /*#__PURE__*/isValidElement(result) ? result : null;
17
+ }
18
+ ;
19
+ /**
20
+ * Checks if the content is renderable (function or valid React element)
21
+ * @param {any} content - The content to check
22
+ * @returns {boolean} - True if content is renderable
23
+ */
24
+
25
+ export function isRenderable(content) {
26
+ return typeof content === 'function' || /*#__PURE__*/isValidElement(content);
27
+ }
28
+ ;
@@ -0,0 +1,3 @@
1
+ export default ((object, search, replace) => {
2
+ return object.replace(search, replace);
3
+ });
@@ -0,0 +1,3 @@
1
+ export default function (object, search, replace) {
2
+ return object.replace(new RegExp(search + '([^' + search + ']*)$'), replace + '$1');
3
+ }
@@ -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,35 @@
1
+ {
2
+ "name": "@zohodesk/utils",
3
+ "version": "1.0.0-temp-1",
4
+ "description": "DOT Utils Collection",
5
+ "main": "es/index.js",
6
+ "module": "es/index.js",
7
+ "private": false,
8
+ "publishConfig": {
9
+ "access": "public"
10
+ },
11
+ "author": "Z Team",
12
+ "homepage": "https://www.npmjs.com/search?q=@zohodesk",
13
+ "license": "ISC",
14
+ "keywords": [
15
+ "UCL",
16
+ "ZOHODESK",
17
+ "ZTEAM",
18
+ "LIBRARY"
19
+ ],
20
+ "scripts": {
21
+ "download": "react-cli clean ./node_modules ./package-lock.json && npm install",
22
+ "build": "type react-cli && react-cli build:component:es",
23
+ "build:watch": "react-cli build:component:es -w",
24
+ "clean": "react-cli clean unittest coverage es result.json",
25
+ "rtl": "react-cli rtl ./src ./es",
26
+ "nodefix": "node ../buildtool_patch.js",
27
+ "prepare": "npm run clean && npm run build && npm run rtl",
28
+ "test": "react-cli test",
29
+ "jsdoc": "jsdoc -c jsdoc.json"
30
+ },
31
+ "files": [
32
+ "es",
33
+ "!**/__tests__"
34
+ ]
35
+ }