@webalternatif/js-core 1.1.0 → 1.1.2

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/dist/esm/i18n.js CHANGED
@@ -1,16 +1,9 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.translate = exports.setLang = exports.getLang = exports._ = void 0;
7
- var i18n = _interopRequireWildcard(require("../i18n/index.js"));
8
- var _is = require("./is.js");
9
- function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
10
- const translate = function (lang, ns, label) {
1
+ import * as i18n from "../i18n/index.js";
2
+ import { isFunction, isUndefined } from "./is.js";
3
+ export const translate = function (lang, ns, label) {
11
4
  let language = lang;
12
- if ((0, _is.isUndefined)(label)) {
13
- if ((0, _is.isUndefined)(ns)) {
5
+ if (isUndefined(label)) {
6
+ if (isUndefined(ns)) {
14
7
  label = lang;
15
8
  ns = 'core';
16
9
  } else {
@@ -19,25 +12,23 @@ const translate = function (lang, ns, label) {
19
12
  }
20
13
  language = getLang();
21
14
  }
22
- const translationExists = !(0, _is.isUndefined)(i18n[ns]) && !(0, _is.isUndefined)(i18n[ns][language]) && !(0, _is.isUndefined)(i18n[ns][language][label]);
15
+ const translationExists = !isUndefined(i18n[ns]) && !isUndefined(i18n[ns][language]) && !isUndefined(i18n[ns][language][label]);
23
16
  if (translationExists) {
24
17
  const tr = i18n[ns][language][label];
25
- return (0, _is.isFunction)(tr) ? tr() : tr;
18
+ return isFunction(tr) ? tr() : tr;
26
19
  }
27
20
  if (lang !== 'en') {
28
21
  return translate('en', ns, label);
29
22
  }
30
23
  return label;
31
24
  };
32
- exports.translate = translate;
33
- const _ = exports._ = translate;
25
+ export const _ = translate;
34
26
  let _lang;
35
- const getLang = () => {
27
+ export const getLang = () => {
36
28
  if (!_lang) setLang();
37
29
  return _lang;
38
30
  };
39
- exports.getLang = getLang;
40
- const setLang = lang => {
31
+ export const setLang = lang => {
41
32
  if (!lang) {
42
33
  if (typeof navigator !== 'undefined' && navigator.language) {
43
34
  lang = navigator.language;
@@ -46,5 +37,4 @@ const setLang = lang => {
46
37
  }
47
38
  }
48
39
  _lang = (lang || 'en').trim().toLowerCase().slice(0, 2);
49
- };
50
- exports.setLang = setLang;
40
+ };
package/dist/esm/index.js CHANGED
@@ -1,55 +1,24 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = exports.arrayFunctions = void 0;
7
- Object.defineProperty(exports, "dom", {
8
- enumerable: true,
9
- get: function () {
10
- return _dom.default;
11
- }
12
- });
13
- Object.defineProperty(exports, "eventDispatcher", {
14
- enumerable: true,
15
- get: function () {
16
- return _eventDispatcher.default;
17
- }
18
- });
19
- Object.defineProperty(exports, "getStyle", {
20
- enumerable: true,
21
- get: function () {
22
- return _dom.getStyle;
23
- }
24
- });
25
- exports.utils = exports.traversal = exports.stringFunctions = exports.math = void 0;
26
- var stringFunctions = _interopRequireWildcard(require("./string.js"));
27
- exports.stringFunctions = stringFunctions;
28
- require("./stringPrototype.js");
29
- var arrayFunctions = _interopRequireWildcard(require("./array.js"));
30
- exports.arrayFunctions = arrayFunctions;
31
- var traversal = _interopRequireWildcard(require("./traversal.js"));
32
- exports.traversal = traversal;
33
- var _dom = _interopRequireWildcard(require("./dom.js"));
34
- var math = _interopRequireWildcard(require("./math.js"));
35
- exports.math = math;
36
- var utils = _interopRequireWildcard(require("./utils.js"));
37
- exports.utils = utils;
38
- var i18n = _interopRequireWildcard(require("./i18n.js"));
39
- var _eventDispatcher = _interopRequireDefault(require("./eventDispatcher.js"));
40
- function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
41
- function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
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';
42
10
  const webf = {
43
11
  ...stringFunctions,
44
12
  ...arrayFunctions,
45
13
  ...traversal,
46
- dom: _dom.default,
47
- isWindow: _dom.isWindow,
48
- isDomElement: _dom.isDomElement,
49
- getStyle: _dom.getStyle,
14
+ dom,
15
+ isWindow,
16
+ isDomElement,
17
+ getStyle,
50
18
  ...math,
51
19
  ...utils,
52
20
  ...i18n,
53
- eventDispatcher: _eventDispatcher.default
21
+ eventDispatcher
54
22
  };
55
- var _default = exports.default = webf;
23
+ export default webf;
24
+ export { stringFunctions, arrayFunctions, traversal, getStyle, dom, math, utils, eventDispatcher };
package/dist/esm/is.js CHANGED
@@ -1,66 +1,51 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.isUndefined = exports.isTouchDevice = exports.isString = exports.isScalar = exports.isPlainObject = exports.isObject = exports.isInteger = exports.isInt = exports.isFunction = exports.isFloat = exports.isEventSupported = exports.isEvent = exports.isDate = exports.isBoolean = exports.isBool = exports.isArray = void 0;
7
- var _array = require("./array.js");
8
- const isString = function (str) {
1
+ import { inArray } from "./array.js";
2
+ export const isString = function (str) {
9
3
  return typeof str == 'string' || Object.prototype.toString.call(str) === '[object String]';
10
4
  };
11
- exports.isString = isString;
12
- const isObject = function (o) {
5
+ export const isObject = function (o) {
13
6
  return !!o && !isArray(o) && typeof o === 'object';
14
7
  };
15
- exports.isObject = isObject;
16
- const isFunction = function (f) {
8
+ export const isFunction = function (f) {
17
9
  return !!f && typeof f === 'function';
18
10
  };
19
- exports.isFunction = isFunction;
20
- const isPlainObject = function (o) {
11
+ export const isPlainObject = function (o) {
21
12
  if (false === isObject(o)) return false;
22
13
  if (undefined === o.constructor) return true;
23
14
  if (false === isObject(o.constructor.prototype)) return false;
24
15
  if (o.constructor.prototype.hasOwnProperty('isPrototypeOf') === false) return false;
25
16
  return true;
26
17
  };
27
- exports.isPlainObject = isPlainObject;
28
- const isBoolean = function (b) {
18
+ export const isBoolean = function (b) {
29
19
  return b === true || b === false;
30
20
  };
31
- exports.isBoolean = isBoolean;
32
- const isBool = exports.isBool = isBoolean;
33
- const isUndefined = function (v) {
21
+ export const isBool = isBoolean;
22
+ export const isUndefined = function (v) {
34
23
  return typeof v === 'undefined';
35
24
  };
36
- exports.isUndefined = isUndefined;
37
- const isArray = function (a) {
25
+ export const isArrayLike = function (o) {
26
+ return null !== o && !isString(o) && !isFunction(o) && isInt(o.length) && o.length >= 0 && Number.isFinite(o.length);
27
+ };
28
+ export const isArray = function (a) {
38
29
  return Array.isArray(a);
39
30
  };
40
- exports.isArray = isArray;
41
- const isDate = function (o) {
31
+ export const isDate = function (o) {
42
32
  return !!o && Object.prototype.toString.call(o) === '[object Date]';
43
33
  };
44
- exports.isDate = isDate;
45
- const isEvent = function (o) {
34
+ export const isEvent = function (o) {
46
35
  return isObject(o) && (!!o.preventDefault || /\[object Event\]/.test(o.constructor.toString()));
47
36
  };
48
- exports.isEvent = isEvent;
49
- const isInteger = function (n) {
37
+ export const isInteger = function (n) {
50
38
  return /^[\-]?\d+$/.test(n + '');
51
39
  };
52
- exports.isInteger = isInteger;
53
- const isInt = exports.isInt = isInteger;
54
- const isFloat = function (n) {
40
+ export const isInt = isInteger;
41
+ export const isFloat = function (n) {
55
42
  return /^[\-]?\d+(\.\d+)?$/.test(n + '');
56
43
  };
57
- exports.isFloat = isFloat;
58
- const isScalar = value => {
44
+ export const isScalar = value => {
59
45
  const type = typeof value;
60
- return value === null || (0, _array.inArray)(type, ['string', 'number', 'bigint', 'symbol', 'boolean']);
46
+ return value === null || inArray(type, ['string', 'number', 'bigint', 'symbol', 'boolean']);
61
47
  };
62
- exports.isScalar = isScalar;
63
- const isEventSupported = exports.isEventSupported = function () {
48
+ export const isEventSupported = function () {
64
49
  const TAGNAMES = {
65
50
  select: 'input',
66
51
  change: 'input',
@@ -79,7 +64,6 @@ const isEventSupported = exports.isEventSupported = function () {
79
64
  }
80
65
  return isEventSupported;
81
66
  }();
82
- const isTouchDevice = function () {
67
+ export const isTouchDevice = function () {
83
68
  return isEventSupported('touchstart');
84
- };
85
- exports.isTouchDevice = isTouchDevice;
69
+ };
package/dist/esm/math.js CHANGED
@@ -1,32 +1,24 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.round = exports.plancher = exports.min = exports.max = exports.hex2dec = exports.floorTo = exports.dec2hex = void 0;
7
- var _traversal = require("./traversal.js");
8
- var _is = require("./is.js");
9
- var _string = require("./string.js");
10
- const round = function (val, precision = 0) {
1
+ import { each } from "./traversal.js";
2
+ import { isArray, isFunction, isObject } from "./is.js";
3
+ import { reverse } from "./string.js";
4
+ export const round = function (val, precision = 0) {
11
5
  return Math.round(val * Math.pow(10, precision)) / Math.pow(10, precision);
12
6
  };
13
- exports.round = round;
14
- const floorTo = function (n, precision) {
7
+ export const floorTo = function (n, precision) {
15
8
  if (precision <= 0) throw new Error('Precision must be greater than 0');
16
9
  return round(Math.floor(n / precision) * precision, 6);
17
10
  };
18
- exports.floorTo = floorTo;
19
- const plancher = exports.plancher = floorTo;
20
- const min = function (list, cmp_func) {
21
- if ((0, _is.isArray)(list)) {
11
+ export const plancher = floorTo;
12
+ export const min = function (list, cmp_func) {
13
+ if (isArray(list)) {
22
14
  return Math.min.apply(null, list);
23
15
  }
24
16
  let min;
25
- cmp_func = (0, _is.isFunction)(cmp_func) ? cmp_func : function (a, b) {
17
+ cmp_func = isFunction(cmp_func) ? cmp_func : function (a, b) {
26
18
  return a < b ? -1 : 1;
27
19
  };
28
- if ((0, _is.isObject)(list)) {
29
- (0, _traversal.each)(list, function (key, val, obj, index) {
20
+ if (isObject(list)) {
21
+ each(list, function (key, val, obj, index) {
30
22
  if (index === 0) {
31
23
  min = val;
32
24
  } else {
@@ -36,17 +28,16 @@ const min = function (list, cmp_func) {
36
28
  }
37
29
  return min;
38
30
  };
39
- exports.min = min;
40
- const max = function (list, cmp_func) {
41
- if ((0, _is.isArray)(list)) {
31
+ export const max = function (list, cmp_func) {
32
+ if (isArray(list)) {
42
33
  return Math.max.apply(null, list);
43
34
  }
44
35
  let max;
45
- cmp_func = (0, _is.isFunction)(cmp_func) ? cmp_func : function (a, b) {
36
+ cmp_func = isFunction(cmp_func) ? cmp_func : function (a, b) {
46
37
  return b - a;
47
38
  };
48
- if ((0, _is.isObject)(list)) {
49
- (0, _traversal.each)(list, function (key, val, obj, index) {
39
+ if (isObject(list)) {
40
+ each(list, function (key, val, obj, index) {
50
41
  if (index === 0) {
51
42
  max = val;
52
43
  } else {
@@ -63,8 +54,7 @@ const max = function (list, cmp_func) {
63
54
  * @param {number} n
64
55
  * @returns {string}
65
56
  */
66
- exports.max = max;
67
- const dec2hex = function (n) {
57
+ export const dec2hex = function (n) {
68
58
  return n.toString(16);
69
59
  };
70
60
 
@@ -74,12 +64,11 @@ const dec2hex = function (n) {
74
64
  * @param {string} hex
75
65
  * @returns {number}
76
66
  */
77
- exports.dec2hex = dec2hex;
78
- const hex2dec = function (hex) {
79
- hex = (0, _string.reverse)(hex + '').toUpperCase();
67
+ export const hex2dec = function (hex) {
68
+ hex = reverse(hex + '').toUpperCase();
80
69
  const c = '0123456789ABCDEF';
81
70
  let value = 0;
82
- (0, _traversal.each)(hex, (i, char) => {
71
+ each(hex, (i, char) => {
83
72
  const index = c.indexOf(char);
84
73
  if (index === -1) {
85
74
  value = 0;
@@ -88,5 +77,4 @@ const hex2dec = function (hex) {
88
77
  value += index * Math.pow(2, 4 * i);
89
78
  });
90
79
  return value;
91
- };
92
- exports.hex2dec = hex2dec;
80
+ };
@@ -1,38 +1,25 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.uniqid = exports.randNum = exports.randAlphaNumCs = exports.randAlphaNum = exports.randAlphaCs = exports.randAlpha = exports.rand = void 0;
7
- const uniqid = function () {
1
+ export const uniqid = function () {
8
2
  return randAlpha(10);
9
3
  };
10
- exports.uniqid = uniqid;
11
- const randAlpha = function (n) {
4
+ export const randAlpha = function (n) {
12
5
  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);
13
6
  };
14
- exports.randAlpha = randAlpha;
15
- const randAlphaCs = function (n) {
7
+ export const randAlphaCs = function (n) {
16
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,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);
17
9
  };
18
- exports.randAlphaCs = randAlphaCs;
19
- const randAlphaNum = function (n) {
10
+ export const randAlphaNum = function (n) {
20
11
  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);
21
12
  };
22
- exports.randAlphaNum = randAlphaNum;
23
- const randAlphaNumCs = function (n) {
13
+ export const randAlphaNumCs = function (n) {
24
14
  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);
25
15
  };
26
- exports.randAlphaNumCs = randAlphaNumCs;
27
- const randNum = function (n) {
16
+ export const randNum = function (n) {
28
17
  return rand("0,1,2,3,4,5,6,7,8,9".split(','), n);
29
18
  };
30
- exports.randNum = randNum;
31
- const rand = function (range, n) {
19
+ export const rand = function (range, n) {
32
20
  let rand = "";
33
21
  for (let i = 0; i < n; i++) {
34
22
  rand += range[Math.floor(Math.random() * 1000) % range.length];
35
23
  }
36
24
  return rand;
37
- };
38
- exports.rand = rand;
25
+ };