sirius-common-utils 1.0.0 → 1.0.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.
@@ -1,132 +0,0 @@
1
- import _ from "lodash";
2
- import AxiosUtils from "./AxiosUtils";
3
-
4
- const constants = {
5
- CANVAS_WIDTH: 480,
6
- CANVAS_HEIGHT: 270,
7
- }
8
-
9
- /**
10
- * create an empty 2 dimension array
11
- */
12
- function new2dArray(width, height, initValue) {
13
- let array = [];
14
- for (let rowIdx = 0; rowIdx < height; rowIdx++) {
15
- let newRow = [];
16
- for (let colIdx = 0; colIdx < width; colIdx++) {
17
- newRow.push(initValue);
18
- }
19
- array.push(newRow);
20
- }
21
- return array;
22
- }
23
-
24
- /**
25
- * render grey level ImageDataArray to Canvas
26
- */
27
- function renderImageDataArrayToCtx(ctx, imageDataArray) {
28
- let height = imageDataArray.length;
29
- let width = imageDataArray[0].length;
30
- let imageData = new ImageData(width, height);
31
- let idx = 0;
32
- for (let rowIdx = 0; rowIdx < height; rowIdx++) {
33
- for (let colIdx = 0; colIdx < width; colIdx++) {
34
- let grayData = imageDataArray[rowIdx][colIdx];
35
-
36
- imageData.data[idx + 0] = grayData;
37
- imageData.data[idx + 1] = grayData;
38
- imageData.data[idx + 2] = grayData;
39
- imageData.data[idx + 3] = 255;
40
- idx = idx + 4;
41
- }
42
- }
43
- ctx.putImageData(imageData, 0, 0, 0, 0, width, height);
44
- }
45
-
46
- function getImageDataArrayFromCtx(ctx, canvasWidth, canvasHeight) {
47
- let imageData = ctx.getImageData(0, 0, canvasWidth, canvasHeight);
48
-
49
- let isEmpty = true;
50
- let imageDataArray = [];
51
- for (let i = 0; i < imageData.data.length; i = i + 4) {
52
- let red = imageData.data[i];
53
- imageDataArray[i / 4] = red;
54
- if (red !== 255) {
55
- isEmpty = false;
56
- }
57
- }
58
-
59
- if (isEmpty) {
60
- return null;
61
- }
62
-
63
- imageDataArray = _.chunk(imageDataArray, canvasWidth);
64
- return imageDataArray;
65
- }
66
-
67
- function initCanvas(ctx, canvasWidth, canvasHeight) {
68
- ctx.fillStyle = "white";
69
- ctx.lineWidth = 1;
70
- ctx.lineCap = 'round';
71
- ctx.lineJoin = 'round';
72
-
73
- ctx.fillRect(0, 0, canvasWidth, canvasHeight);
74
- ctx.fill();
75
- }
76
-
77
- async function convertCanvasToBlobFile(canvas, fileName, fileType = 'image/jpeg') {
78
- return new Promise((resolve, reject) => {
79
- canvas.toBlob(async function (blob) {
80
- const file = new File([blob], fileName);
81
- resolve(file);
82
- }, fileType, 0.9);
83
- });
84
- }
85
-
86
- /**
87
- * Build grey level ImageDataArray from text
88
- */
89
- function calcImageDataArrayFromText(valueText) {
90
- if (valueText == null) {
91
- return;
92
- }
93
-
94
- let imageDataArray = [];
95
- _.each(valueText.split(";"), (rowData, rowIdx) => {
96
- let row = [];
97
- _.each(rowData.split(","), (item, colIdx) => {
98
- row.push(item);
99
- });
100
- imageDataArray.push(row);
101
- });
102
- return imageDataArray;
103
- }
104
-
105
- function calcTextFromImageDataArray(imageDataArray) {
106
- if (imageDataArray == null) {
107
- return;
108
- }
109
-
110
- let valueText = "";
111
- for (let rowIdx = 0; rowIdx < imageDataArray.length; rowIdx++) {
112
- if (rowIdx > 0) {
113
- valueText += ";";
114
- }
115
- valueText += imageDataArray[rowIdx].join(",");
116
- }
117
- return valueText;
118
- }
119
-
120
- export default {
121
- constants: constants,
122
- new2dArray: new2dArray,
123
- initCanvas: initCanvas,
124
- //common
125
- convertCanvasToBlobFile: convertCanvasToBlobFile,
126
-
127
- //for signature
128
- renderImageDataArrayToCtx: renderImageDataArrayToCtx,
129
- getImageDataArrayFromCtx: getImageDataArrayFromCtx,
130
- calcImageDataArrayFromText: calcImageDataArrayFromText,
131
- calcTextFromImageDataArray: calcTextFromImageDataArray,
132
- };
@@ -1,17 +0,0 @@
1
- import _ from "lodash";
2
-
3
- let pattern=/[`~!@#$^\-&*()=|{}':;,\\\[\].<>\/?\s]/g;
4
-
5
- function buildKeyword(text) {
6
- if(!text){
7
- return '';
8
- }
9
-
10
- let keyword = text.replace(pattern, '').toUpperCase();
11
- return keyword;
12
- }
13
-
14
-
15
- export default {
16
- buildKeyword: buildKeyword,
17
- };