@monkvision/common 4.0.3 → 4.0.6
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/README/APP_UTILS.md +52 -0
- package/README/HOOKS.md +242 -0
- package/README/INTERNATIONALIZATION.md +89 -0
- package/README/STATE_MANAGEMENT.md +125 -0
- package/README/THEMING.md +70 -0
- package/README/UTILITIES.md +254 -0
- package/lib/PreventExit/hooks.js +0 -1
- package/lib/PreventExit/index.js +0 -1
- package/lib/PreventExit/store.js +0 -1
- package/lib/apps/analytics.js +0 -1
- package/lib/apps/appState.js +0 -1
- package/lib/apps/appStateProvider.js +0 -1
- package/lib/apps/index.js +0 -1
- package/lib/apps/monitoring.js +0 -1
- package/lib/apps/searchParams.js +0 -1
- package/lib/hooks/index.js +0 -1
- package/lib/hooks/useAsyncEffect.js +0 -1
- package/lib/hooks/useAsyncInterval.js +0 -1
- package/lib/hooks/useInteractiveStatus.js +0 -1
- package/lib/hooks/useInterval.js +0 -1
- package/lib/hooks/useLoadingState.js +0 -1
- package/lib/hooks/useObjectMemo.js +0 -1
- package/lib/hooks/useObjectTranslation.js +0 -1
- package/lib/hooks/useQueue.js +0 -1
- package/lib/hooks/useResponsiveStyle.js +0 -1
- package/lib/hooks/useSearchParams.js +0 -1
- package/lib/hooks/useSightLabel.js +0 -1
- package/lib/hooks/useWindowDimensions.js +0 -1
- package/lib/i18n/index.js +0 -1
- package/lib/i18n/translations/image.js +0 -1
- package/lib/i18n/translations/index.js +0 -1
- package/lib/i18n/translations/vehicleParts.js +0 -1
- package/lib/i18n/utils.js +0 -1
- package/lib/index.js +0 -1
- package/lib/state/actions/createdOneImage.js +0 -1
- package/lib/state/actions/gotOneInspection.js +0 -1
- package/lib/state/actions/index.js +0 -1
- package/lib/state/actions/monkAction.js +0 -1
- package/lib/state/actions/resetState.js +0 -1
- package/lib/state/actions/updatedManyTasks.js +0 -1
- package/lib/state/actions/updatedVehicle.js +0 -1
- package/lib/state/context.js +0 -1
- package/lib/state/hooks.js +0 -1
- package/lib/state/index.js +0 -1
- package/lib/state/provider.js +0 -1
- package/lib/state/reducer.js +0 -1
- package/lib/state/state.js +0 -1
- package/lib/theme/context.js +0 -1
- package/lib/theme/default/index.js +0 -1
- package/lib/theme/default/palette.js +0 -1
- package/lib/theme/hooks.js +0 -1
- package/lib/theme/index.js +0 -1
- package/lib/theme/provider.js +0 -1
- package/lib/theme/theme.js +0 -1
- package/lib/utils/array.utils.js +0 -1
- package/lib/utils/browser.utils.js +0 -1
- package/lib/utils/color.utils.js +0 -1
- package/lib/utils/env.utils.js +0 -1
- package/lib/utils/index.js +0 -1
- package/lib/utils/mimetype.utils.js +0 -1
- package/lib/utils/promise.utils.js +0 -1
- package/lib/utils/state.utils.js +0 -1
- package/lib/utils/string.utils.js +0 -1
- package/lib/utils/zlib.utils.js +0 -1
- package/package.json +22 -14
|
@@ -0,0 +1,254 @@
|
|
|
1
|
+
# Utilities
|
|
2
|
+
This README page is aimed at providing documentation on a specific part of the `@monkvision/common` package : the
|
|
3
|
+
utility functions. You can refer to [this page](README.md) for more general information on the package.
|
|
4
|
+
|
|
5
|
+
This package exports various utility functions used throughout the MonkJs SDK.
|
|
6
|
+
|
|
7
|
+
# Array Utils
|
|
8
|
+
### permutations
|
|
9
|
+
```typescript
|
|
10
|
+
import { permutations } from '@monkvision/common';
|
|
11
|
+
|
|
12
|
+
console.log(permutations([1, 2, 3]));
|
|
13
|
+
// Output : [[1, 2, 3], [1, 3, 2], [2, 1, 3], [2, 3, 1], [3, 1, 2], [3, 2, 1]]
|
|
14
|
+
```
|
|
15
|
+
Returns an array containing all the possible permutations of the given array.
|
|
16
|
+
|
|
17
|
+
### uniq
|
|
18
|
+
```typescript
|
|
19
|
+
import { uniq } from '@monkvision/common';
|
|
20
|
+
|
|
21
|
+
console.log(uniq([1, 1, 1, 2, 3, 3]));
|
|
22
|
+
// Output : [1, 2, 3]
|
|
23
|
+
```
|
|
24
|
+
Return a copy of the given array in which all duplicates have been removed.
|
|
25
|
+
|
|
26
|
+
### flatten
|
|
27
|
+
```typescript
|
|
28
|
+
import { flatten } from '@monkvision/common';
|
|
29
|
+
|
|
30
|
+
console.log(flatten([ 1, [2, 3], [[4], [5, 6]]]));
|
|
31
|
+
// Output : [1, 2, 3, 4, 5, 6]
|
|
32
|
+
```
|
|
33
|
+
Flatten the given array.
|
|
34
|
+
|
|
35
|
+
### flatten
|
|
36
|
+
```typescript
|
|
37
|
+
import { flatMap } from '@monkvision/common';
|
|
38
|
+
|
|
39
|
+
console.log(flatMap([1, 2, 3], (item: number) => [item, item + 1]));
|
|
40
|
+
// Output : [1, 2, 2, 3, 3, 4]
|
|
41
|
+
```
|
|
42
|
+
JS implementation of the
|
|
43
|
+
[Array.prototype.flatMap](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/flatMap)
|
|
44
|
+
method, available on all versions of JavaScript.
|
|
45
|
+
|
|
46
|
+
---
|
|
47
|
+
|
|
48
|
+
# Color Utils
|
|
49
|
+
### getRGBAFromString
|
|
50
|
+
```typescript
|
|
51
|
+
import { getRGBAFromString } from '@monkvision/common';
|
|
52
|
+
|
|
53
|
+
console.log(JSON.stringify(getRGBAFromString('#AF270CCC')));
|
|
54
|
+
// Output : {"r":175,"g":39,"b":12,"a":0.8}
|
|
55
|
+
```
|
|
56
|
+
Returns the RGBA values of the given color. The accepted formats are :
|
|
57
|
+
- RGB : `rgb(167, 224, 146)`
|
|
58
|
+
- RGBA : `rgb(167, 224, 146, 0.03)`
|
|
59
|
+
- HEX : `#A7E092`
|
|
60
|
+
- HEX (alpha) : `#A7E09208`
|
|
61
|
+
- HEX (short) : `#AE9`
|
|
62
|
+
- HEX (short + alpha) : `#AE98`
|
|
63
|
+
|
|
64
|
+
This function is case-insensitive and ignores white spaces.
|
|
65
|
+
|
|
66
|
+
### getHexFromRGBA
|
|
67
|
+
```typescript
|
|
68
|
+
import { getHexFromRGBA } from '@monkvision/common';
|
|
69
|
+
|
|
70
|
+
console.log(getHexFromRGBA({ r: 111, g: 222, b: 0, a: 0.67 }));
|
|
71
|
+
// Output : #6FDE00AB
|
|
72
|
+
```
|
|
73
|
+
Converts RGBA values to their hexadecimal representation.
|
|
74
|
+
|
|
75
|
+
### shadeColor
|
|
76
|
+
```typescript
|
|
77
|
+
import { shadeColor } from '@monkvision/common';
|
|
78
|
+
|
|
79
|
+
console.log(shadeColor('#FC72A7', 0.7));
|
|
80
|
+
// Output : #FFC2FFFF
|
|
81
|
+
```
|
|
82
|
+
Apply a shade of black or white over the given color. The amount of shade to apply works as a ratio :
|
|
83
|
+
- use positive values like 0.08 to lighten the color by 8%
|
|
84
|
+
- use negative values like -0.08 to darken the color by 8%
|
|
85
|
+
|
|
86
|
+
### changeAlpha
|
|
87
|
+
```typescript
|
|
88
|
+
import { changeAlpha } from '@monkvision/common';
|
|
89
|
+
|
|
90
|
+
console.log(changeAlpha('#FF1234FF', 0.5));
|
|
91
|
+
// Output : #FF123480
|
|
92
|
+
```
|
|
93
|
+
Returns a new color equal to the given color but with a different alpha value.
|
|
94
|
+
|
|
95
|
+
### getInteractiveVariants
|
|
96
|
+
```typescript
|
|
97
|
+
import { getInteractiveVariants } from '@monkvision/common';
|
|
98
|
+
|
|
99
|
+
const variants = getInteractiveVariants('#FC72A7');
|
|
100
|
+
/*
|
|
101
|
+
* variants = {
|
|
102
|
+
* [InteractiveStatus.DEFAULT]: '#FC72A7',
|
|
103
|
+
* [InteractiveStatus.HOVERED]: '#FF7BB4',
|
|
104
|
+
* [InteractiveStatus.ACTIVE]: '#FF80BB',
|
|
105
|
+
* [InteractiveStatus.DISABLED]: '#FC72A7',
|
|
106
|
+
* }
|
|
107
|
+
*/
|
|
108
|
+
```
|
|
109
|
+
Create interactive variants (hovered, active...) for the given color. You can specify as an additional parameter the
|
|
110
|
+
type of variation to use for the interactive colors (lighten or darken the color, default = lighten).
|
|
111
|
+
|
|
112
|
+
---
|
|
113
|
+
|
|
114
|
+
# Environment Utils
|
|
115
|
+
### getEnvOrThrow
|
|
116
|
+
```typescript
|
|
117
|
+
import { getEnvOrThrow } from '@monkvision/common';
|
|
118
|
+
|
|
119
|
+
try {
|
|
120
|
+
const example = getEnvOrThrow('REACT_APP_EXAMPLE');
|
|
121
|
+
console.log('Env var is defined :', example);
|
|
122
|
+
} catch (err) {
|
|
123
|
+
console.log('Env var is not defined');
|
|
124
|
+
}
|
|
125
|
+
```
|
|
126
|
+
Returns the value of a given environment variable. If the value does not exist, it throws an error.
|
|
127
|
+
|
|
128
|
+
---
|
|
129
|
+
|
|
130
|
+
# Mimetype Utils
|
|
131
|
+
### MIMETYPE_FILE_EXTENSIONS
|
|
132
|
+
```typescript
|
|
133
|
+
import { MIMETYPE_FILE_EXTENSIONS } from '@monkvision/common';
|
|
134
|
+
|
|
135
|
+
console.log(MIMETYPE_FILE_EXTENSIONS['text/plain']);
|
|
136
|
+
// Output : ['txt']
|
|
137
|
+
```
|
|
138
|
+
Datamap that associates mimetypes to known file extensions corresponding to this mimetype.
|
|
139
|
+
|
|
140
|
+
### getFileExtensions
|
|
141
|
+
```typescript
|
|
142
|
+
import { getFileExtensions } from '@monkvision/common';
|
|
143
|
+
|
|
144
|
+
console.log(getFileExtensions('image/jpeg'));
|
|
145
|
+
// Output : ['jpeg', 'jpg']
|
|
146
|
+
```
|
|
147
|
+
Returns a list of file extensions known to be corresponding to the given mimetype. If no file extension is known for
|
|
148
|
+
this mimetype, this function will throw an error.
|
|
149
|
+
|
|
150
|
+
### getMimetype
|
|
151
|
+
```typescript
|
|
152
|
+
import { getMimetype } from '@monkvision/common';
|
|
153
|
+
|
|
154
|
+
console.log(getMimetype('jpg'));
|
|
155
|
+
// Output : 'image/jpeg'
|
|
156
|
+
```
|
|
157
|
+
Returns the mimetype associated with the given file extension. If the file extension is unknown, this function will
|
|
158
|
+
throw an error.
|
|
159
|
+
|
|
160
|
+
---
|
|
161
|
+
|
|
162
|
+
# Promise Utils
|
|
163
|
+
### timeoutPromise
|
|
164
|
+
```typescript
|
|
165
|
+
import { timeoutPromise } from '@monkvision/common';
|
|
166
|
+
|
|
167
|
+
timeoutPromise(5000).then(() => console.log('Hello!'));
|
|
168
|
+
// Output after 5 seconds : 'Hello!'
|
|
169
|
+
```
|
|
170
|
+
This function creates and returns a new Promise that will resolve to void after the given amount of milliseconds.
|
|
171
|
+
|
|
172
|
+
---
|
|
173
|
+
|
|
174
|
+
# State Utils
|
|
175
|
+
### getInspectionImages
|
|
176
|
+
```typescript
|
|
177
|
+
import { getInspectionImages } from '@monkvision/common';
|
|
178
|
+
|
|
179
|
+
console.log(getInspectionImages(inspectionId, images, filterRetakes));
|
|
180
|
+
// Returns an array of all the images having the given inspectionId.
|
|
181
|
+
```
|
|
182
|
+
Utility function that extracts the images of the given inspection. Set `filterRetakes` to `false` to filter retaken
|
|
183
|
+
pictures.
|
|
184
|
+
|
|
185
|
+
---
|
|
186
|
+
|
|
187
|
+
# String Utils
|
|
188
|
+
### suffix
|
|
189
|
+
```typescript
|
|
190
|
+
import { suffix } from '@monkvision/common';
|
|
191
|
+
|
|
192
|
+
console.log(suffix('my-str', { suffix1: true, suffix2: false }));
|
|
193
|
+
// Output : 'my-str suffix1'
|
|
194
|
+
```
|
|
195
|
+
This function suffixes a string with the given suffixes, only if their value is `true` in the suffixes object param.
|
|
196
|
+
|
|
197
|
+
*Note : The order of the suffixes is not guaranteed.*
|
|
198
|
+
|
|
199
|
+
### words
|
|
200
|
+
```typescript
|
|
201
|
+
import { words } from '@monkvision/common';
|
|
202
|
+
|
|
203
|
+
console.log(words('my-str-test'));
|
|
204
|
+
// Output : 'my str test'
|
|
205
|
+
```
|
|
206
|
+
Split the given string into its composing words.
|
|
207
|
+
|
|
208
|
+
### capitalize
|
|
209
|
+
```typescript
|
|
210
|
+
import { capitalize } from '@monkvision/common';
|
|
211
|
+
|
|
212
|
+
console.log(capitalize('my-str-test'));
|
|
213
|
+
// Output : 'My-str-test'
|
|
214
|
+
```
|
|
215
|
+
Capitalizes (transforms the first character to upper case) the given string.
|
|
216
|
+
|
|
217
|
+
### uncapitalize
|
|
218
|
+
```typescript
|
|
219
|
+
import { uncapitalize } from '@monkvision/common';
|
|
220
|
+
|
|
221
|
+
console.log(uncapitalize('My-str-test'));
|
|
222
|
+
// Output : 'my-str-test'
|
|
223
|
+
```
|
|
224
|
+
Uncapitalizes (transforms the first character to lower case) the given string.
|
|
225
|
+
|
|
226
|
+
### toCamelCase
|
|
227
|
+
```typescript
|
|
228
|
+
import { toCamelCase } from '@monkvision/common';
|
|
229
|
+
|
|
230
|
+
console.log(toCamelCase('My-str-test'));
|
|
231
|
+
// Output : 'myStrTest'
|
|
232
|
+
```
|
|
233
|
+
Converts a string to camel case.
|
|
234
|
+
|
|
235
|
+
---
|
|
236
|
+
|
|
237
|
+
# Zlib Utils
|
|
238
|
+
### zlibCompress
|
|
239
|
+
```typescript
|
|
240
|
+
import { zlibCompress } from '@monkvision/common';
|
|
241
|
+
|
|
242
|
+
console.log(zlibCompress('Hello World!'))
|
|
243
|
+
// Output : 'eJzzSM3JyVcIzy/KSVEEABxJBD4='
|
|
244
|
+
```
|
|
245
|
+
Compresses and encodes a string in base64 using the ZLib algorithm.
|
|
246
|
+
|
|
247
|
+
### zlibDecompress
|
|
248
|
+
```typescript
|
|
249
|
+
import { zlibDecompress } from '@monkvision/common';
|
|
250
|
+
|
|
251
|
+
console.log(zlibDecompress('eJzzSM3JyVcIzy/KSVEEABxJBD4='))
|
|
252
|
+
// Output : 'Hello World!'
|
|
253
|
+
```
|
|
254
|
+
Decompresses a string that has been encoded in base64 and compressed using the Zlib algorithm.
|
package/lib/PreventExit/hooks.js
CHANGED
package/lib/PreventExit/index.js
CHANGED
package/lib/PreventExit/store.js
CHANGED
package/lib/apps/analytics.js
CHANGED
package/lib/apps/appState.js
CHANGED
package/lib/apps/index.js
CHANGED
package/lib/apps/monitoring.js
CHANGED
package/lib/apps/searchParams.js
CHANGED
package/lib/hooks/index.js
CHANGED
|
@@ -67,4 +67,3 @@ function useInteractiveStatus(params) {
|
|
|
67
67
|
}); }, [hovered, active, params === null || params === void 0 ? void 0 : params.disabled, onMouseEnter, onMouseLeave, onMouseDown, onMouseUp]);
|
|
68
68
|
}
|
|
69
69
|
exports.useInteractiveStatus = useInteractiveStatus;
|
|
70
|
-
//# sourceMappingURL=useInteractiveStatus.js.map
|
package/lib/hooks/useInterval.js
CHANGED
package/lib/hooks/useQueue.js
CHANGED
package/lib/i18n/index.js
CHANGED
|
@@ -16,4 +16,3 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./utils"), exports);
|
|
18
18
|
__exportStar(require("./translations"), exports);
|
|
19
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -16,4 +16,3 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./vehicleParts"), exports);
|
|
18
18
|
__exportStar(require("./image"), exports);
|
|
19
|
-
//# sourceMappingURL=index.js.map
|
package/lib/i18n/utils.js
CHANGED
package/lib/index.js
CHANGED
|
@@ -49,4 +49,3 @@ function createdOneImage(state, action) {
|
|
|
49
49
|
return __assign(__assign({}, state), { inspections: __spreadArray([], inspections, true), images: __spreadArray([], images, true) });
|
|
50
50
|
}
|
|
51
51
|
exports.createdOneImage = createdOneImage;
|
|
52
|
-
//# sourceMappingURL=createdOneImage.js.map
|
package/lib/state/context.js
CHANGED
package/lib/state/hooks.js
CHANGED
package/lib/state/index.js
CHANGED
package/lib/state/provider.js
CHANGED
package/lib/state/reducer.js
CHANGED
package/lib/state/state.js
CHANGED
package/lib/theme/context.js
CHANGED
package/lib/theme/hooks.js
CHANGED
package/lib/theme/index.js
CHANGED
package/lib/theme/provider.js
CHANGED
package/lib/theme/theme.js
CHANGED
package/lib/utils/array.utils.js
CHANGED
package/lib/utils/color.utils.js
CHANGED
package/lib/utils/env.utils.js
CHANGED
package/lib/utils/index.js
CHANGED
package/lib/utils/state.utils.js
CHANGED
package/lib/utils/zlib.utils.js
CHANGED