@osimatic/helpers-js 1.2.3 → 1.2.5

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/array.js CHANGED
@@ -12,6 +12,16 @@ Array.prototype.unsetVal = function(val) {
12
12
  }
13
13
  };
14
14
 
15
+ Array.prototype.unsetValues = function(values) {
16
+ values.forEach(val => this.unsetVal(val));
17
+ };
18
+
19
+ Array.prototype.pushVal = function(val) {
20
+ if (this.indexOf(val) === -1) {
21
+ this.push(val);
22
+ }
23
+ };
24
+
15
25
  Array.prototype.inArray = function(p_val) {
16
26
  return this.indexOf(p_val) > -1;
17
27
  };
@@ -37,6 +47,13 @@ Array.prototype.intersect = function(array1, array2) {
37
47
  return array1.filter(value => array2.includes(value));
38
48
  }
39
49
 
50
+ Array.prototype.diff = function(array1, array2) {
51
+ function notContainedIn(arr) {
52
+ return element => arr.indexOf(element) === -1;
53
+ }
54
+ return array1.filter(notContainedIn(array2)).concat(array2.filter(notContainedIn(array1)));
55
+ }
56
+
40
57
  Array.prototype.filterUnique = function() {
41
58
  //let onlyUnique = (([value, index, self]) => self.indexOf(value) === index);
42
59
  return this.filter((v, i, a) => a.indexOf(v) === i);
@@ -218,12 +218,14 @@ class ImportFromCsv {
218
218
  });
219
219
  }
220
220
 
221
- static getErrorsHtmlOfImportData(json, divResult) {
221
+ static getErrorsHtmlOfImportData(json, divResult=null) {
222
222
  let resultError = errorMessageImportFailed;
223
223
  resultError += '<ul>';
224
224
  $.each(json, function(idx, errorData) {
225
225
  console.error(errorData);
226
- divResult.find('table tr[data-line="'+errorData.line+'"]').addClass('danger');
226
+ if (null != divResult) {
227
+ divResult.find('table tr[data-line="'+errorData.line+'"]').addClass('danger');
228
+ }
227
229
 
228
230
  resultError += '<li>'+lineLabel.format(errorData.line)+'<ul>';
229
231
  $.each(errorData.errors, function(index, error) {
@@ -235,6 +237,21 @@ class ImportFromCsv {
235
237
  return resultError;
236
238
  }
237
239
 
240
+ static isImportErrors(json) {
241
+ if (!Array.isArray(json)) {
242
+ return false;
243
+ }
244
+
245
+ for (let key in json) {
246
+ let value = json[key];
247
+ if (typeof value == 'object' && typeof value['line'] != 'undefined' && typeof value['errors'] != 'undefined') {
248
+ return true;
249
+ }
250
+ }
251
+
252
+ return false;
253
+ }
254
+
238
255
  static getTabLink(formMatching) {
239
256
  let tabLink = {};
240
257
  formMatching.find('select').each(function(idx, select) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@osimatic/helpers-js",
3
- "version": "1.2.3",
3
+ "version": "1.2.5",
4
4
  "main": "main.js",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1"