@bbn/bbn 1.0.83 → 1.0.85

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,5 +1,6 @@
1
- import { createObject } from '../object/createObject';
2
- import { addInputs } from '../form/addInputs';
1
+ import { createObject } from "../object/createObject";
2
+ import { addInputs } from "../form/addInputs";
3
+ import { setProperty } from "../object/setProperty";
3
4
  /**
4
5
  * Posts a request in a new window.
5
6
  *
@@ -17,33 +18,35 @@ import { addInputs } from '../form/addInputs';
17
18
  * @param {Function} success A function to execute in case of success
18
19
  * @param {String} target The target attribute of the form
19
20
  *
20
- * @returns {undefined}
21
+ * @returns {void}
21
22
  */
22
- const postOut = function (url, data, success, target) {
23
- let form = document.body.querySelector('form#bbn-form_out');
23
+ const postOut = function (url, data, success = null, target = "") {
24
+ let form = document.body.querySelector("form#bbn-form_out");
24
25
  if (!form) {
25
- form = document.createElement('form');
26
- form.classList.add('bbn-no');
27
- form.setAttribute('id', 'bbn-form_out');
28
- form.setAttribute('method', 'post');
29
- form.setAttribute('enctype', 'multipart/form-data-encoded');
30
- form.style.display = 'none';
26
+ form = document.createElement("form");
27
+ form.classList.add("bbn-no");
28
+ form.setAttribute("id", "bbn-form_out");
29
+ form.setAttribute("method", "post");
30
+ form.setAttribute("enctype", "multipart/form-data-encoded");
31
+ setProperty(form, "style.display", "none");
31
32
  document.body.appendChild(form);
32
33
  }
33
- form.innerHTML = '';
34
- form.setAttribute('action', url);
35
- form.setAttribute('target', target || '_blank');
36
- if (!data) {
37
- data = {};
38
- }
39
- data = createObject(data);
40
- if (!data.bbn) {
41
- data.bbn = 'public';
42
- }
43
- addInputs(form, data);
44
- form.submit();
45
- if (success) {
46
- success();
34
+ if (form instanceof HTMLFormElement) {
35
+ form.innerHTML = "";
36
+ form.setAttribute("action", url);
37
+ form.setAttribute("target", target || "_blank");
38
+ if (!data) {
39
+ data = {};
40
+ }
41
+ data = createObject(data);
42
+ if (!data.bbn) {
43
+ data.bbn = "public";
44
+ }
45
+ addInputs(form, data);
46
+ form.submit();
47
+ if (success) {
48
+ success();
49
+ }
47
50
  }
48
51
  };
49
52
  export { postOut };
@@ -19,7 +19,7 @@
19
19
  * @param {Object} data The data if any
20
20
  * @param {Boolean} repl If true the history state object will replace the current one, will be added otherwise
21
21
  *
22
- * @returns {undefined}
22
+ * @returns {void}
23
23
  */
24
- declare const setNavigationVars: (url: any, title: any, data?: object, repl?: boolean) => void;
24
+ declare const setNavigationVars: (url: any, title: any, data?: any, repl?: boolean) => void;
25
25
  export { setNavigationVars };
@@ -23,9 +23,9 @@ import { html2text } from '../html/html2text';
23
23
  * @param {Object} data The data if any
24
24
  * @param {Boolean} repl If true the history state object will replace the current one, will be added otherwise
25
25
  *
26
- * @returns {undefined}
26
+ * @returns {void}
27
27
  */
28
- const setNavigationVars = function (url, title, data, repl) {
28
+ const setNavigationVars = function (url, title, data = null, repl = false) {
29
29
  // Current path becomes old path
30
30
  bbn.env.old_path = bbn.env.path;
31
31
  // URL includes the domain
@@ -49,5 +49,5 @@
49
49
  *
50
50
  * @returns {Object} The configuration object
51
51
  */
52
- declare const treatAjaxArguments: (args: any) => BbnAjaxCfg;
52
+ declare const treatAjaxArguments: (args: any) => any;
53
53
  export { treatAjaxArguments };
@@ -1,7 +1,7 @@
1
- import { isObject } from '../type/isObject';
2
- import { isFunction } from '../type/isFunction';
3
- import { substr } from '../string/substr';
4
- import { numProperties } from '../object/numProperties';
1
+ import { isObject } from "../type/isObject";
2
+ import { isFunction } from "../type/isFunction";
3
+ import { substr } from "../string/substr";
4
+ import { numProperties } from "../object/numProperties";
5
5
  /**
6
6
  * Transforms unordered arguments into a configuratiuon object for Ajax shortcut functions.
7
7
  *
@@ -65,62 +65,63 @@ const treatAjaxArguments = function (args) {
65
65
  t = t.toLowerCase();
66
66
  /* Callbacks */
67
67
  if (isFunction(args[i])) {
68
- if (cfg.errorFn && !cfg.abortFn) {
69
- cfg.abortFn = args[i];
68
+ if (cfg["errorFn"] && !cfg["abortFn"]) {
69
+ cfg["abortFn"] = args[i];
70
70
  }
71
- if (cfg.successFn && !cfg.errorFn) {
72
- cfg.errorFn = args[i];
71
+ if (cfg["successFn"] && !cfg["errorFn"]) {
72
+ cfg["errorFn"] = args[i];
73
73
  }
74
- else if (!cfg.successFn) {
75
- cfg.successFn = args[i];
74
+ else if (!cfg["successFn"]) {
75
+ cfg["successFn"] = args[i];
76
76
  }
77
77
  }
78
78
  else if (args[i] === 1 || args[i] === true) {
79
79
  /* Force */
80
- cfg.force = true;
80
+ cfg["force"] = true;
81
81
  }
82
- else if (t === 'string') {
83
- if (!cfg.url) {
82
+ else if (t === "string") {
83
+ if (!cfg["url"]) {
84
84
  /* Hash */
85
- if (args[i].indexOf('#') === 0 || args[i].indexOf(bbn.env.root + '#') === 0) {
86
- cfg.url = substr(args[i], bbn.env.root.length);
85
+ if (args[i].indexOf("#") === 0 ||
86
+ args[i].indexOf(bbn.env.root + "#") === 0) {
87
+ cfg["url"] = substr(args[i], bbn.env.root.length);
87
88
  }
88
89
  else {
89
90
  /* Link */
90
- cfg.url = args[i];
91
- if (cfg.url.indexOf(bbn.env.root) === 0) {
92
- cfg.url = substr(cfg.url, bbn.env.root.length);
91
+ cfg["url"] = args[i];
92
+ if (cfg["url"].indexOf(bbn.env.root) === 0) {
93
+ cfg["url"] = substr(cfg["url"], bbn.env.root.length);
93
94
  }
94
95
  }
95
96
  }
96
97
  else {
97
98
  /* Ajax datatype */
98
- cfg.datatype = args[i];
99
+ cfg["datatype"] = args[i];
99
100
  }
100
101
  }
101
- else if (args[i] && t === 'object') {
102
+ else if (args[i] && t === "object") {
102
103
  /* Event */
103
104
  if (args[i] instanceof Event) {
104
- cfg.e = args[i];
105
+ cfg["e"] = args[i];
105
106
  }
106
- else if (!cfg.ele && args[i].nodeType === 1) {
107
+ else if (!cfg["ele"] && args[i].nodeType === 1) {
107
108
  /* HTML Element */
108
- cfg.ele = args[i];
109
+ cfg["ele"] = args[i];
109
110
  }
110
- else if (t.toLowerCase() === 'object') {
111
+ else if (t.toLowerCase() === "object") {
111
112
  /* An object to post */
112
- cfg.obj = args[i];
113
+ cfg["obj"] = args[i];
113
114
  }
114
115
  }
115
116
  }
116
- if (!cfg.url && numProperties(cfg)) {
117
- cfg.url = bbn.env.path;
117
+ if (!cfg["url"] && numProperties(cfg)) {
118
+ cfg["url"] = bbn.env.path;
118
119
  }
119
- if (cfg.obj === undefined) {
120
- cfg.obj = { _bbn: 'public' };
120
+ if (cfg["obj"] === undefined) {
121
+ cfg["obj"] = { _bbn: "public" };
121
122
  }
122
- if (!cfg.datatype) {
123
- cfg.datatype = 'json';
123
+ if (!cfg["datatype"]) {
124
+ cfg["datatype"] = "json";
124
125
  }
125
126
  return cfg;
126
127
  };
@@ -14,5 +14,5 @@
14
14
  *
15
15
  * @returns {Promise}
16
16
  */
17
- declare const upload: (url: string, file: any, success?: (d: any) => any, failure?: (d: any) => any, progress?: (d: any, l: any, t: any) => any) => any;
17
+ declare const upload: (url: any, file: any, success?: any, failure?: any, progress?: any) => any;
18
18
  export { upload };
@@ -16,7 +16,7 @@ import { log } from '../browser/log';
16
16
  *
17
17
  * @returns {Promise}
18
18
  */
19
- const upload = function (url, file, success, failure, progress) {
19
+ const upload = function (url, file, success = null, failure = null, progress = null) {
20
20
  let fn = () => {
21
21
  return axios.post(url || bbn.env.path, objectToFormData(file), {
22
22
  headers: {
@@ -17,5 +17,5 @@
17
17
  *
18
18
  * @returns {Boolean} True if focused
19
19
  */
20
- declare const isFocused: (ele: HTMLElement, contain?: boolean) => boolean;
20
+ declare const isFocused: (ele: any, contain?: boolean) => boolean;
21
21
  export { isFocused };
@@ -17,7 +17,7 @@
17
17
  *
18
18
  * @returns {Boolean} True if focused
19
19
  */
20
- const isFocused = function (ele, contain) {
20
+ const isFocused = function (ele, contain = false) {
21
21
  return ele === document.activeElement || (contain && ele.contains && ele.contains(document.activeElement));
22
22
  };
23
23
  export { isFocused };
@@ -17,5 +17,5 @@
17
17
  *
18
18
  * @returns {Boolean} True if focused
19
19
  */
20
- declare const selectElementText: (ele: HTMLElement, win?: Window) => void;
20
+ declare const selectElementText: (ele: any, win?: any) => void;
21
21
  export { selectElementText };
@@ -17,7 +17,7 @@
17
17
  *
18
18
  * @returns {Boolean} True if focused
19
19
  */
20
- const selectElementText = function (ele, win) {
20
+ const selectElementText = function (ele, win = null) {
21
21
  win = win || window;
22
22
  if (ele instanceof HTMLInputElement) {
23
23
  ele.select();
@@ -10,5 +10,5 @@
10
10
  * @param {...any} args
11
11
  * @returns
12
12
  */
13
- declare const warning: (message: string) => void;
13
+ declare const warning: (message: any) => void;
14
14
  export { warning };
@@ -9,7 +9,7 @@
9
9
  * @global
10
10
  * @memberof bbn.fn
11
11
  * @param {HTMLElement} img
12
- * @returns
12
+ * @returns {HTMLCanvasElement}
13
13
  */
14
14
  declare const imageToCanvas: (img: any) => HTMLCanvasElement;
15
15
  export { imageToCanvas };
@@ -9,7 +9,7 @@
9
9
  * @global
10
10
  * @memberof bbn.fn
11
11
  * @param {HTMLElement} img
12
- * @returns
12
+ * @returns {HTMLCanvasElement}
13
13
  */
14
14
  const imageToCanvas = function (img) {
15
15
  let canvas = document.createElement('canvas');
@@ -1,7 +1,6 @@
1
1
  import { imageToCanvas } from './imageToCanvas';
2
2
  const imgToBase64 = function (img, type = 'image/png') {
3
3
  let canvas = imageToCanvas(img);
4
- //return canvasToImage(canvas);
5
4
  return canvas.toDataURL(type);
6
5
  };
7
6
  export { imgToBase64 };
@@ -22,5 +22,5 @@
22
22
  * @param {String} [valEsc="] The string escaper character
23
23
  * @returns {String} A CSV string
24
24
  */
25
- declare const toCSV: (arr: any[], valSep?: string, rowSep?: string, valEsc?: string) => string;
25
+ declare const toCSV: (arr: any, valSep?: string, rowSep?: string, valEsc?: string) => string;
26
26
  export { toCSV };
package/dist/fn.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  declare const fn: {
2
2
  _addLoader: (requestId: any, prom: any, source: any) => number;
3
3
  _compareValues: (a: any, b: any, prop: any, dir?: string) => 0 | 1 | -1;
4
- _deleteLoader: (requestId: string, res?: any, isAbort?: boolean) => boolean;
4
+ _deleteLoader: (requestId: any, res?: any, isAbort?: boolean) => boolean;
5
5
  abort: (requestId: any) => void;
6
6
  abortURL: (url: any) => void;
7
7
  addColors: (colors: object) => void;
@@ -10,7 +10,7 @@ declare const fn: {
10
10
  adjustHeight: () => void;
11
11
  adjustSize: (type: any, eles: any) => void;
12
12
  adjustWidth: () => void;
13
- ajax: (url: any, datatype: string, data: any, success?: (data: object, headers?: object) => any, failure?: (url: string, o?: object) => any, abort?: (message: string, url: string) => any) => any;
13
+ ajax: (url: any, datatype?: any, data?: any, success?: any, failure?: any, abort?: any) => any;
14
14
  analyzeFunction: (fn: any) => {
15
15
  body: any;
16
16
  args: any[];
@@ -28,7 +28,7 @@ declare const fn: {
28
28
  baseName: (path: string, suffix?: string) => string;
29
29
  br2nl: (st: any) => string;
30
30
  calendar: (d?: string | number | Date, wrong_result?: string) => any;
31
- callback: (url: any, res: any, fn?: any, fn2?: any, ele?: any) => boolean;
31
+ callback: (url: any, res?: any, fn?: any, fn2?: any, ele?: any) => boolean;
32
32
  camelize: (str: any) => any;
33
33
  camelToCss: (str: any) => any;
34
34
  canvasToImage: (canvas: any) => HTMLImageElement;
@@ -68,7 +68,7 @@ declare const fn: {
68
68
  diffObj: (obj1: object, obj2: object, unchanged?: boolean, notRoot?: boolean) => any;
69
69
  dirName: (path: any) => string;
70
70
  download: (url: any, filename?: string, params?: any) => any;
71
- downloadContent: (filename: string, content: any, type?: string) => void;
71
+ downloadContent: (filename: any, content: any, type?: any) => void;
72
72
  each: (arr: any, fn: any) => any;
73
73
  eraseCookie: (name: any) => void;
74
74
  error: (errorMsg: any) => never;
@@ -109,7 +109,7 @@ declare const fn: {
109
109
  getFieldValues: (arr: object[], field: string, prop: any, val: any, operator: any) => any[];
110
110
  getHtml: (ele: any, stripComments?: boolean) => any;
111
111
  getHTMLOfSelection: () => string;
112
- getLoader: (requestId: string) => BbnLoader;
112
+ getLoader: (requestId: any) => BbnLoader;
113
113
  getPath: (element: any) => string;
114
114
  getProp: (obj: any, prop: any) => any;
115
115
  getProperty: (obj: any, prop: any) => any;
@@ -146,7 +146,7 @@ declare const fn: {
146
146
  isEmail: (...args: any[]) => boolean;
147
147
  isEmpty: (obj: any) => boolean;
148
148
  isEvent: (...args: any[]) => boolean;
149
- isFocused: (ele: HTMLElement, contain?: boolean) => boolean;
149
+ isFocused: (ele: any, contain?: boolean) => boolean;
150
150
  isFunction: (...args: any[]) => boolean;
151
151
  isHostname: (...args: any[]) => boolean;
152
152
  isInside: (ele: any, ancestor: any) => boolean;
@@ -191,7 +191,7 @@ declare const fn: {
191
191
  percent: (percent: any, cent: any) => number;
192
192
  pickValue: (arr: any[]) => any;
193
193
  post: (...args: any[]) => any;
194
- postOut: (url: string, data: BbnBasicObject, success?: () => any, target?: string) => void;
194
+ postOut: (url: any, data: any, success?: any, target?: string) => void;
195
195
  printf: (format: any) => any;
196
196
  quotes2html: (st: string, type?: string) => string;
197
197
  randomInt: (min: number, max: number) => number;
@@ -211,11 +211,11 @@ declare const fn: {
211
211
  roundDecimal: (value: number, decimals: number) => number;
212
212
  sanitize: (str: any, separator?: string) => any;
213
213
  search: (arr: any[], prop: string | object | import("./fn/object/filterToConditions").Filter | ((a: any, i: string | number | symbol) => boolean), val?: any, operator?: string | number, startFrom?: number) => number;
214
- selectElementText: (ele: HTMLElement, win?: Window) => void;
214
+ selectElementText: (ele: any, win?: any) => void;
215
215
  selector: (ele: string | HTMLElement) => HTMLElement;
216
216
  setCookie: (name: any, value: any, days: any) => void;
217
217
  setCssVar: (varname: any, value: any) => void;
218
- setNavigationVars: (url: any, title: any, data?: object, repl?: boolean) => void;
218
+ setNavigationVars: (url: any, title: any, data?: any, repl?: boolean) => void;
219
219
  setProp: (obj: object, prop: string, value: any, writable?: boolean, configurable?: boolean) => void;
220
220
  setProperty: (obj: object, prop: string, value: any, force?: boolean) => void;
221
221
  shorten: (st: string, len?: number, adj?: string) => string;
@@ -231,14 +231,14 @@ declare const fn: {
231
231
  substr: (str: string, from: number, length?: number) => string;
232
232
  sum: (arr: object[], numberProp: string | ((a: any) => any), prop: string | object, val?: any, operator?: string) => number;
233
233
  timestamp: (seconds?: boolean) => number;
234
- toCSV: (arr: any[], valSep?: string, rowSep?: string, valEsc?: string) => string;
234
+ toCSV: (arr: any, valSep?: string, rowSep?: string, valEsc?: string) => string;
235
235
  toggleFullScreen: () => void;
236
236
  translate: (o: object, namespace?: string) => void;
237
- treatAjaxArguments: (args: any) => BbnAjaxCfg;
237
+ treatAjaxArguments: (args: any) => any;
238
238
  trim: (str: any, hair?: string) => any;
239
239
  uniqString: (...args: any[]) => string;
240
240
  unique: (arr: any[]) => any[];
241
- upload: (url: string, file: any, success?: (d: any) => any, failure?: (d: any) => any, progress?: (d: any, l: any, t: any) => any) => any;
242
- warning: (message: string) => void;
241
+ upload: (url: any, file: any, success?: any, failure?: any, progress?: any) => any;
242
+ warning: (message: any) => void;
243
243
  };
244
244
  export { fn };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bbn/bbn",
3
- "version": "1.0.83",
3
+ "version": "1.0.85",
4
4
  "description": "Javascript toolkit",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",