-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjFactory-helpers.mjs
87 lines (77 loc) · 2.81 KB
/
jFactory-helpers.mjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/**
* -----------------------------------------------------------------------------------------------------------------
* jFactory Helpers
* -----------------------------------------------------------------------------------------------------------------
* Centralize helpers and externals in one module
* -----------------------------------------------------------------------------------------------------------------
* Status: Beta
* -----------------------------------------------------------------------------------------------------------------
*/
// --------------
// jQuery
// --------------
export { default as jQuery } from "jquery";
// --------------
// Lodash
// --------------
// Individual importation improves the tree shaking
// This is supposed to be equivalent to babel-plugin-lodash
// CAUTION
// Please ensure that the bundler configuration is updated accordingly
// to prevent unexpected build errors, see "external" in /scripts/build/buildConfig.js
export { default as helper_camelCase } from "lodash/camelCase.js";
export { default as helper_get } from "lodash/get.js";
export { default as helper_lowerFirst } from "lodash/lowerFirst.js";
export { default as helper_template } from "lodash/template.js";
export { default as helper_isString } from "lodash/isString.js";
export { default as helper_isNumber } from "lodash/isNumber.js";
export { default as helper_isPlainObject } from "lodash/isPlainObject.js";
export { default as helper_defaultsDeep } from "lodash/defaultsDeep.js";
// --------------
// Helpers
// --------------
export const NOOP = () => {};
export const helper_setFunctionName = (name, f) => Object.defineProperty(f, "name", { value: name });
const helper_url_base = typeof window !== "undefined" && window.location ? window.location.href : "http://localhost";
export const helper_url_abs = url => new URL(url, helper_url_base).href
export const helper_isNative = function(f) {
return typeof f === "function" && Function.prototype.toString.call(f).indexOf("[native code]") !== -1
}
export function helper_useragent(id) {
return globalThis.navigator &&
globalThis.navigator.userAgent &&
globalThis.navigator.userAgent.indexOf(id + "/") > 0
}
export const helper_deferred = () => new Deferred;
class Deferred {
constructor() {
this._done = [];
this._fail = [];
}
execute(list) {
for (let h of list){
h()
}
this.fulfilled = true
}
resolve() {
this.execute(this._done);
}
reject() {
this.execute(this._fail);
}
done(callback) {
if (this.fulfilled) {
callback()
} else {
this._done.push(callback);
}
}
fail(callback) {
if (this.fulfilled) {
callback()
} else {
this._fail.push(callback);
}
}
}