@osimatic/helpers-js 1.2.4 → 1.2.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.
Files changed (3) hide show
  1. package/array.js +17 -0
  2. package/form_helper.js +24 -0
  3. package/package.json +1 -1
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);
package/form_helper.js CHANGED
@@ -258,6 +258,30 @@ class FormHelper {
258
258
  return null;
259
259
  }
260
260
 
261
+ static extractErrorMessageOfJson(json, onlyIfUniqueError=false) {
262
+ if (typeof json == 'undefined' || json == null) {
263
+ return null;
264
+ }
265
+
266
+ if (typeof json.error != 'undefined') {
267
+ return json.error;
268
+ }
269
+
270
+ if (onlyIfUniqueError && !json.length || json.length > 1) {
271
+ return null;
272
+ }
273
+
274
+ if (typeof json[0] != 'undefined' && typeof json[0].error != 'undefined') {
275
+ return json[0].error;
276
+ }
277
+
278
+ if (typeof json[0] != 'undefined' && Array.isArray(json[0]) && json[0].length === 2) {
279
+ return json[0][1];
280
+ }
281
+
282
+ return null;
283
+ }
284
+
261
285
  static hideFormErrors(form) {
262
286
  form.find('div.form_errors').remove();
263
287
  return form;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@osimatic/helpers-js",
3
- "version": "1.2.4",
3
+ "version": "1.2.6",
4
4
  "main": "main.js",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1"