@webalternatif/js-core 1.0.0
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/.babelrc +12 -0
- package/.idea/inspectionProfiles/Project_Default.xml +12 -0
- package/.idea/js-core.iml +8 -0
- package/.idea/modules.xml +8 -0
- package/.idea/php.xml +20 -0
- package/.idea/vcs.xml +6 -0
- package/LICENSE +21 -0
- package/README.md +7 -0
- package/dist/cjs/array.js +116 -0
- package/dist/cjs/dom.js +466 -0
- package/dist/cjs/eventDispatcher.js +96 -0
- package/dist/cjs/i18n.js +50 -0
- package/dist/cjs/index.js +55 -0
- package/dist/cjs/is.js +85 -0
- package/dist/cjs/math.js +92 -0
- package/dist/cjs/random.js +38 -0
- package/dist/cjs/string.js +474 -0
- package/dist/cjs/stringPrototype.js +16 -0
- package/dist/cjs/traversal.js +110 -0
- package/dist/cjs/utils.js +118 -0
- package/dist/esm/array.js +116 -0
- package/dist/esm/dom.js +466 -0
- package/dist/esm/eventDispatcher.js +96 -0
- package/dist/esm/i18n.js +50 -0
- package/dist/esm/index.js +55 -0
- package/dist/esm/is.js +85 -0
- package/dist/esm/math.js +92 -0
- package/dist/esm/random.js +38 -0
- package/dist/esm/string.js +474 -0
- package/dist/esm/stringPrototype.js +16 -0
- package/dist/esm/traversal.js +110 -0
- package/dist/esm/utils.js +118 -0
- package/i18n/agenda/en.js +73 -0
- package/i18n/agenda/fr.js +73 -0
- package/i18n/agenda/index.js +2 -0
- package/i18n/ajaxform/en.js +5 -0
- package/i18n/ajaxform/fr.js +5 -0
- package/i18n/ajaxform/index.js +2 -0
- package/i18n/ajaxupload/en.js +12 -0
- package/i18n/ajaxupload/fr.js +12 -0
- package/i18n/ajaxupload/index.js +2 -0
- package/i18n/autocomplete/en.js +3 -0
- package/i18n/autocomplete/fr.js +3 -0
- package/i18n/autocomplete/index.js +2 -0
- package/i18n/confirm/en.js +5 -0
- package/i18n/confirm/fr.js +5 -0
- package/i18n/confirm/index.js +2 -0
- package/i18n/core/en.js +4 -0
- package/i18n/core/fr.js +4 -0
- package/i18n/core/index.js +2 -0
- package/i18n/datagrid/en.js +8 -0
- package/i18n/datagrid/fr.js +8 -0
- package/i18n/datagrid/index.js +2 -0
- package/i18n/date/en.js +51 -0
- package/i18n/date/fr.js +51 -0
- package/i18n/date/index.js +2 -0
- package/i18n/datetimepicker/en.js +30 -0
- package/i18n/datetimepicker/fr.js +30 -0
- package/i18n/datetimepicker/index.js +2 -0
- package/i18n/dialog/en.js +3 -0
- package/i18n/dialog/fr.js +3 -0
- package/i18n/dialog/index.js +2 -0
- package/i18n/fulldayeventagenda/en.js +73 -0
- package/i18n/fulldayeventagenda/fr.js +73 -0
- package/i18n/fulldayeventagenda/index.js +2 -0
- package/i18n/index.d.ts +4 -0
- package/i18n/index.js +15 -0
- package/i18n/richtexteditor/en.js +58 -0
- package/i18n/richtexteditor/fr.js +58 -0
- package/i18n/richtexteditor/index.js +2 -0
- package/i18n/select/en.js +3 -0
- package/i18n/select/fr.js +3 -0
- package/i18n/select/index.js +2 -0
- package/i18n/timepicker/en.js +3 -0
- package/i18n/timepicker/fr.js +3 -0
- package/i18n/timepicker/index.js +2 -0
- package/i18n/useragenda/en.js +74 -0
- package/i18n/useragenda/fr.js +73 -0
- package/i18n/useragenda/index.js +2 -0
- package/jest.config.js +14 -0
- package/package.json +33 -0
- package/src/array.js +124 -0
- package/src/dom.js +569 -0
- package/src/eventDispatcher.js +118 -0
- package/src/i18n.js +55 -0
- package/src/index.js +33 -0
- package/src/is.js +89 -0
- package/src/math.js +109 -0
- package/src/random.js +40 -0
- package/src/string.js +576 -0
- package/src/stringPrototype.js +15 -0
- package/src/traversal.js +134 -0
- package/src/utils.js +130 -0
- package/tests/array.test.js +326 -0
- package/tests/dom.test.js +239 -0
- package/tests/eventdispatcher.test.js +177 -0
- package/tests/i18n.test.js +132 -0
- package/tests/index.test.js +29 -0
- package/tests/is.test.js +354 -0
- package/tests/math.test.js +221 -0
- package/tests/random.test.js +72 -0
- package/tests/string.test.js +1106 -0
- package/tests/traversal.test.js +517 -0
- package/tests/utils.test.js +371 -0
- package/tsconfig.json +16 -0
- package/types/array.d.ts +8 -0
- package/types/dom.d.ts +241 -0
- package/types/eventDispatcher.d.ts +12 -0
- package/types/i18n.d.ts +4 -0
- package/types/index.d.ts +139 -0
- package/types/is.d.ts +16 -0
- package/types/math.d.ts +7 -0
- package/types/random.d.ts +7 -0
- package/types/string.d.ts +37 -0
- package/types/stringPrototype.d.ts +1 -0
- package/types/traversal.d.ts +7 -0
- package/types/utils.d.ts +7 -0
- package/webpack.config.cjs +31 -0
package/src/i18n.js
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import * as i18n from "../i18n/index.js";
|
|
2
|
+
import {isFunction, isUndefined} from "./is.js";
|
|
3
|
+
|
|
4
|
+
export const translate = function (lang, ns, label) {
|
|
5
|
+
let language = lang;
|
|
6
|
+
|
|
7
|
+
if (isUndefined(label)) {
|
|
8
|
+
if (isUndefined(ns)) {
|
|
9
|
+
label = lang;
|
|
10
|
+
ns = 'core';
|
|
11
|
+
} else {
|
|
12
|
+
label = ns;
|
|
13
|
+
ns = lang;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
language = getLang();
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const translationExists =
|
|
20
|
+
!isUndefined(i18n[ns]) &&
|
|
21
|
+
!isUndefined(i18n[ns][language]) &&
|
|
22
|
+
!isUndefined(i18n[ns][language][label]);
|
|
23
|
+
|
|
24
|
+
if (translationExists) {
|
|
25
|
+
const tr = i18n[ns][language][label];
|
|
26
|
+
return isFunction(tr) ? tr() : tr;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
if (lang !== 'en') {
|
|
30
|
+
return translate('en', ns, label);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
return label;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export const _ = translate
|
|
37
|
+
|
|
38
|
+
let _lang;
|
|
39
|
+
|
|
40
|
+
export const getLang = () => {
|
|
41
|
+
if (!_lang) setLang();
|
|
42
|
+
return _lang;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export const setLang = (lang) => {
|
|
46
|
+
if (!lang) {
|
|
47
|
+
if (typeof navigator !== 'undefined' && navigator.language) {
|
|
48
|
+
lang = navigator.language;
|
|
49
|
+
} else if (typeof process !== 'undefined' && process.env) {
|
|
50
|
+
lang = (process.env.LANG || process.env.LC_ALL || process.env.LC_MESSAGES);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
_lang = (lang || 'en').trim().toLowerCase().slice(0, 2);
|
|
55
|
+
}
|
package/src/index.js
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import * as stringFunctions from './string.js';
|
|
2
|
+
import './stringPrototype.js';
|
|
3
|
+
import * as arrayFunctions from './array.js';
|
|
4
|
+
import * as traversal from './traversal.js';
|
|
5
|
+
import dom, {getStyle, isDomElement, isWindow} from './dom.js';
|
|
6
|
+
import * as math from './math.js';
|
|
7
|
+
import * as utils from './utils.js';
|
|
8
|
+
import * as i18n from './i18n.js';
|
|
9
|
+
import eventDispatcher from './eventDispatcher.js'
|
|
10
|
+
|
|
11
|
+
const webf = {
|
|
12
|
+
...stringFunctions,
|
|
13
|
+
...arrayFunctions,
|
|
14
|
+
...traversal,
|
|
15
|
+
dom, isWindow, isDomElement, getStyle,
|
|
16
|
+
...math,
|
|
17
|
+
...utils,
|
|
18
|
+
...i18n,
|
|
19
|
+
eventDispatcher
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export default webf
|
|
23
|
+
|
|
24
|
+
export {
|
|
25
|
+
stringFunctions,
|
|
26
|
+
arrayFunctions,
|
|
27
|
+
traversal,
|
|
28
|
+
getStyle,
|
|
29
|
+
dom,
|
|
30
|
+
math,
|
|
31
|
+
utils,
|
|
32
|
+
eventDispatcher,
|
|
33
|
+
};
|
package/src/is.js
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import {inArray} from "./array.js";
|
|
2
|
+
|
|
3
|
+
export const isString = function (str) {
|
|
4
|
+
return typeof(str) == 'string' || Object.prototype.toString.call(str) === '[object String]';
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export const isObject = function (o) {
|
|
8
|
+
return !!o && !isArray(o) && typeof o === 'object';
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export const isFunction = function(f) {
|
|
12
|
+
return !!f && typeof f === 'function';
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export const isPlainObject = function(o) {
|
|
16
|
+
if (false === isObject(o)) return false
|
|
17
|
+
if (undefined === o.constructor) return true
|
|
18
|
+
if (false === isObject(o.constructor.prototype)) return false;
|
|
19
|
+
if (o.constructor.prototype.hasOwnProperty('isPrototypeOf') === false) return false;
|
|
20
|
+
|
|
21
|
+
return true;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export const isBoolean = function(b) {
|
|
25
|
+
return b === true || b === false;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export const isBool = isBoolean;
|
|
29
|
+
|
|
30
|
+
export const isUndefined = function(v) {
|
|
31
|
+
return typeof v === 'undefined';
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export const isArray = function(a) {
|
|
35
|
+
return Array.isArray(a);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export const isDate = function (o) {
|
|
39
|
+
return !!o && Object.prototype.toString.call(o) === '[object Date]'
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export const isEvent = function(o) {
|
|
43
|
+
return isObject(o) && (!!o.preventDefault || /\[object Event\]/.test(o.constructor.toString()));
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export const isInteger = function(n) {
|
|
47
|
+
return /^[\-]?\d+$/.test(n + '');
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export const isInt = isInteger
|
|
51
|
+
|
|
52
|
+
export const isFloat = function(n) {
|
|
53
|
+
return /^[\-]?\d+(\.\d+)?$/.test(n + '');
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export const isScalar = (value) => {
|
|
57
|
+
const type = typeof value;
|
|
58
|
+
|
|
59
|
+
return value === null || inArray(type, ['string', 'number', 'bigint', 'symbol', 'boolean']);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export const isEventSupported = (function() {
|
|
63
|
+
const TAGNAMES = {
|
|
64
|
+
select: 'input',
|
|
65
|
+
change: 'input',
|
|
66
|
+
submit: 'form',
|
|
67
|
+
reset: 'form',
|
|
68
|
+
error: 'img',
|
|
69
|
+
load: 'img',
|
|
70
|
+
abort: 'img'
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function isEventSupported(eventName) {
|
|
74
|
+
let el = document.createElement(TAGNAMES[eventName] || 'div');
|
|
75
|
+
eventName = 'on' + eventName;
|
|
76
|
+
const isSupported = (eventName in el);
|
|
77
|
+
|
|
78
|
+
el = null;
|
|
79
|
+
|
|
80
|
+
return isSupported;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
return isEventSupported;
|
|
84
|
+
})();
|
|
85
|
+
|
|
86
|
+
export const isTouchDevice = function()
|
|
87
|
+
{
|
|
88
|
+
return isEventSupported('touchstart');
|
|
89
|
+
}
|
package/src/math.js
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import {each} from "./traversal.js";
|
|
2
|
+
import {isArray, isFunction, isObject} from "./is.js";
|
|
3
|
+
import {reverse} from "./string.js";
|
|
4
|
+
|
|
5
|
+
export const round = function(val, precision = 0) {
|
|
6
|
+
return Math.round(val * Math.pow(10, precision)) / Math.pow(10, precision);
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export const floorTo = function(n, precision) {
|
|
10
|
+
if (precision <= 0) throw new Error('Precision must be greater than 0');
|
|
11
|
+
|
|
12
|
+
return round(Math.floor(n / precision) * precision, 6);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export const plancher = floorTo
|
|
16
|
+
|
|
17
|
+
export const min = function(list, cmp_func)
|
|
18
|
+
{
|
|
19
|
+
if (isArray(list)) {
|
|
20
|
+
return Math.min.apply(null, list);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
let min;
|
|
24
|
+
|
|
25
|
+
cmp_func = isFunction(cmp_func)
|
|
26
|
+
? cmp_func
|
|
27
|
+
: function(a, b) {
|
|
28
|
+
return a < b ? -1 : 1;
|
|
29
|
+
}
|
|
30
|
+
;
|
|
31
|
+
|
|
32
|
+
if (isObject(list)) {
|
|
33
|
+
each(list, function(key, val, obj, index) {
|
|
34
|
+
if (index === 0) {
|
|
35
|
+
min = val;
|
|
36
|
+
} else {
|
|
37
|
+
min = cmp_func.call(null, min, val) > 0 ? val : min;
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
return min;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export const max = function(list, cmp_func)
|
|
46
|
+
{
|
|
47
|
+
if (isArray(list)) {
|
|
48
|
+
return Math.max.apply(null, list);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
let max;
|
|
52
|
+
|
|
53
|
+
cmp_func = isFunction(cmp_func)
|
|
54
|
+
? cmp_func
|
|
55
|
+
: function(a, b) {
|
|
56
|
+
return b - a;
|
|
57
|
+
}
|
|
58
|
+
;
|
|
59
|
+
|
|
60
|
+
if (isObject(list)) {
|
|
61
|
+
each(list, function(key, val, obj, index) {
|
|
62
|
+
if (index === 0) {
|
|
63
|
+
max = val;
|
|
64
|
+
} else {
|
|
65
|
+
max = cmp_func.call(null, max, val) > 0 ? val : max;
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
return max;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Converts a decimal number into hexadecimal
|
|
75
|
+
*
|
|
76
|
+
* @param {number} n
|
|
77
|
+
* @returns {string}
|
|
78
|
+
*/
|
|
79
|
+
export const dec2hex = function(n)
|
|
80
|
+
{
|
|
81
|
+
return n.toString(16);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Converts a hexadecimal into a decimal number
|
|
86
|
+
*
|
|
87
|
+
* @param {string} hex
|
|
88
|
+
* @returns {number}
|
|
89
|
+
*/
|
|
90
|
+
export const hex2dec = function(hex)
|
|
91
|
+
{
|
|
92
|
+
hex = reverse(hex + '').toUpperCase();
|
|
93
|
+
|
|
94
|
+
const c = '0123456789ABCDEF';
|
|
95
|
+
let value = 0;
|
|
96
|
+
|
|
97
|
+
each(hex, (i, char) => {
|
|
98
|
+
const index = (c.indexOf(char));
|
|
99
|
+
|
|
100
|
+
if (index === -1) {
|
|
101
|
+
value = 0;
|
|
102
|
+
return false;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
value += ((index) * Math.pow(2, 4 * i));
|
|
106
|
+
})
|
|
107
|
+
|
|
108
|
+
return value;
|
|
109
|
+
}
|
package/src/random.js
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
export const uniqid = function()
|
|
2
|
+
{
|
|
3
|
+
return randAlpha(10);
|
|
4
|
+
};
|
|
5
|
+
|
|
6
|
+
export const randAlpha = function(n)
|
|
7
|
+
{
|
|
8
|
+
return rand("a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z".split(','), n);
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export const randAlphaCs = function(n)
|
|
12
|
+
{
|
|
13
|
+
return rand("a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z".split(','), n);
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export const randAlphaNum = function(n)
|
|
17
|
+
{
|
|
18
|
+
return rand("0,1,2,3,4,5,6,7,8,9,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z".split(','), n);
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export const randAlphaNumCs = function(n)
|
|
22
|
+
{
|
|
23
|
+
return rand("0,1,2,3,4,5,6,7,8,9,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z".split(','), n);
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export const randNum = function(n)
|
|
27
|
+
{
|
|
28
|
+
return rand("0,1,2,3,4,5,6,7,8,9".split(','), n);
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
export const rand = function(range, n)
|
|
32
|
+
{
|
|
33
|
+
let rand = "";
|
|
34
|
+
|
|
35
|
+
for (let i=0; i<n; i++) {
|
|
36
|
+
rand += range[Math.floor(Math.random() * 1000) % range.length];
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
return rand;
|
|
40
|
+
};
|