@webalternatif/js-core 1.3.1 → 1.4.1

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,6 +1,6 @@
1
- import { each } from "./traversal.js";
1
+ import { foreach } from "./traversal.js";
2
2
  import * as stringFunctions from "./string.js";
3
- each(Object.keys(stringFunctions), function (i, name) {
3
+ foreach(Object.keys(stringFunctions), function (name) {
4
4
  var f = stringFunctions[name],
5
5
  p = String.prototype;
6
6
  var origSF = p[name];
@@ -11,7 +11,7 @@ import { sizeOf } from "./utils.js";
11
11
 
12
12
  /**
13
13
  * @template T
14
- * @typedef {Array<T> | Set<T> | Map<any, T> | Object<string, T> | string} Collection
14
+ * @typedef {Array<T> | Set<T> | Map<any, T> | Object<string, T> | string | string[]} Collection
15
15
  */
16
16
 
17
17
  /**
@@ -34,9 +34,9 @@ export var each = function each(o, callback, context) {
34
34
  for (var i in o) if (o.hasOwnProperty(i) && false === callback.call(context !== null && context !== void 0 ? context : o[i], i, o[i], o, ++index)) return;
35
35
  } else if (isString(o)) {
36
36
  var arr = o.split('');
37
- for (var _i = 0; _i < arr.length; _i++) if (false === callback.call(context !== null && context !== void 0 ? context : arr[_i], _i, arr[_i], o, _i)) return;
37
+ for (var _i = 0; _i < arr.length; _i++) if (false === callback.call(context !== null && context !== void 0 ? context : arr[_i], _i, arr[_i], o, _i)) return o;
38
38
  return o;
39
- } else if (o instanceof Map || o instanceof WeakMap) {
39
+ } else if (o instanceof Map) {
40
40
  var _index = 0;
41
41
  var _iterator = _createForOfIteratorHelper(o.entries()),
42
42
  _step;
@@ -45,7 +45,7 @@ export var each = function each(o, callback, context) {
45
45
  var _step$value = _slicedToArray(_step.value, 2),
46
46
  key = _step$value[0],
47
47
  value = _step$value[1];
48
- if (false === callback.call(context !== null && context !== void 0 ? context : value, key, value, o, _index++)) return;
48
+ if (false === callback.call(context !== null && context !== void 0 ? context : value, key, value, o, _index++)) return o;
49
49
  }
50
50
  } catch (err) {
51
51
  _iterator.e(err);
@@ -59,7 +59,7 @@ export var each = function each(o, callback, context) {
59
59
  try {
60
60
  for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
61
61
  var _value = _step2.value;
62
- if (false === callback.call(context !== null && context !== void 0 ? context : _value, _index2, _value, o, _index2)) return;
62
+ if (false === callback.call(context !== null && context !== void 0 ? context : _value, _index2, _value, o, _index2)) return o;
63
63
  _index2++;
64
64
  }
65
65
  } catch (err) {
@@ -69,7 +69,7 @@ export var each = function each(o, callback, context) {
69
69
  }
70
70
  } else if (isArrayLike(o)) {
71
71
  var _arr = Array.from(o);
72
- for (var _i2 = 0; _i2 < _arr.length; _i2++) if (false === callback.call(context || _arr[_i2], _i2, _arr[_i2], _arr, _i2)) return;
72
+ for (var _i2 = 0; _i2 < _arr.length; _i2++) if (false === callback.call(context || _arr[_i2], _i2, _arr[_i2], _arr, _i2)) return o;
73
73
  }
74
74
  return o;
75
75
  };
@@ -111,7 +111,8 @@ export var map = function map(o, callback, context) {
111
111
  var results = [];
112
112
  each(o, function (index, value, o, i) {
113
113
  var response = callback.call(context, index, value, o, i);
114
- if (false === response) return false;
114
+
115
+ // if (false === response) return false;
115
116
  if (null !== response) results.push(response);
116
117
  });
117
118
  return results;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webalternatif/js-core",
3
- "version": "1.3.1",
3
+ "version": "1.4.1",
4
4
  "type": "module",
5
5
  "types": "types/index.d.ts",
6
6
  "main": "dist/cjs/index.js",
@@ -0,0 +1,13 @@
1
+ export default Mouse;
2
+ declare class Mouse {
3
+ static getPosition(ev: any, element: any): {
4
+ x: number;
5
+ y: number;
6
+ };
7
+ static getViewportPosition(ev: any): {
8
+ x: any;
9
+ y: any;
10
+ };
11
+ static getElement(ev: any): Element | null;
12
+ static "__#1@#getEvent"(ev: any): any;
13
+ }
@@ -0,0 +1,34 @@
1
+ /**
2
+ * @typedef {string | (() => string)} TranslatorValue
3
+ */
4
+ /**
5
+ * @typedef {Record<string, Record<string, Record<string, TranslatorValue>>>} TranslatorNsMapping
6
+ */
7
+ /**
8
+ * @typedef {Record<string, Record<string, TranslatorValue>>} TranslatorCoreMapping
9
+ */
10
+ /**
11
+ * @typedef {TranslatorNsMapping | TranslatorCoreMapping} TranslatorMapping
12
+ */
13
+ export default class Translator {
14
+ /**
15
+ * @param {TranslatorMapping} mapping
16
+ * @param {string} [defaultLang]
17
+ */
18
+ constructor(mapping: TranslatorMapping, defaultLang?: string);
19
+ /**
20
+ * @param {string} label
21
+ * @param {string} [namespace]
22
+ * @param {string} [lang]
23
+ * @returns {string}
24
+ */
25
+ translate(label: string, namespace?: string, lang?: string): string;
26
+ _(...args: any[]): string;
27
+ getLang(): string;
28
+ setLang(lang: any): void;
29
+ #private;
30
+ }
31
+ export type TranslatorValue = string | (() => string);
32
+ export type TranslatorNsMapping = Record<string, Record<string, Record<string, TranslatorValue>>>;
33
+ export type TranslatorCoreMapping = Record<string, Record<string, TranslatorValue>>;
34
+ export type TranslatorMapping = TranslatorNsMapping | TranslatorCoreMapping;
package/types/dom.d.ts CHANGED
@@ -2,7 +2,8 @@ export function isWindow(o: any): boolean;
2
2
  export function isDocument(o: any): boolean;
3
3
  export function isDomElement(o: any): boolean;
4
4
  export function getStyle(el: Element, cssRule: string): string;
5
- declare namespace _default {
5
+ export default dom;
6
+ declare namespace dom {
6
7
  /**
7
8
  * @param {Element} el
8
9
  * @param {string} [selector]
@@ -199,12 +200,12 @@ declare namespace _default {
199
200
  /**
200
201
  * @param {Element|Document|Window} el
201
202
  * @param {string} [events]
202
- * @param {string|Element|function} selector
203
+ * @param {string|Element|function} [selector]
203
204
  * @param {function|AddEventListenerOptions|boolean} [handler]
204
205
  * @param {AddEventListenerOptions|boolean} [options]
205
206
  * @returns {Element}
206
207
  */
207
- function off(el: Element | Document | Window, events?: string, selector: string | Element | Function, handler?: Function | AddEventListenerOptions | boolean, options?: AddEventListenerOptions | boolean): Element;
208
+ function off(el: Element | Document | Window, events?: string, selector?: string | Element | Function, handler?: Function | AddEventListenerOptions | boolean, options?: AddEventListenerOptions | boolean): Element;
208
209
  /**
209
210
  * @param {HTMLElement} el
210
211
  * @param {Object<string, string>|string} style
@@ -218,9 +219,9 @@ declare namespace _default {
218
219
  * @param {Element} el
219
220
  * @param {string} selectorClosest
220
221
  * @param {string} selectorFind
221
- * @returns {NodeList|null}
222
+ * @returns {Array<Element>}
222
223
  */
223
- function closestFind(el: Element, selectorClosest: string, selectorFind: string): NodeList | null;
224
+ function closestFind(el: Element, selectorClosest: string, selectorFind: string): Array<Element>;
224
225
  /**
225
226
  * @param {Element} el
226
227
  * @param {string} selectorClosest
@@ -240,9 +241,9 @@ declare namespace _default {
240
241
  function last(nodeList: NodeList | Array<Element>): Element | null;
241
242
  /**
242
243
  * @param {string} html
243
- * @returns {Element|null}
244
+ * @returns {Element|DocumentFragment|null}
244
245
  */
245
- function create(html: string): Element | null;
246
+ function create(html: string): Element | DocumentFragment | null;
246
247
  /**
247
248
  * @param {NodeList|Array<Element>} nodeList
248
249
  * @param {number} [index=0]
@@ -267,11 +268,11 @@ declare namespace _default {
267
268
  */
268
269
  function empty(el: Element): Element;
269
270
  /**
270
- * @param {Element|NodeList} el
271
+ * @param {Element|NodeList|Array<Element>} el
271
272
  * @param {string|Element} selector
272
- * @return {Element[]}
273
+ * @return {Array<Element>}
273
274
  */
274
- function not(el: Element | NodeList, selector: string | Element): Element[];
275
+ function not(el: Element | NodeList | Array<Element>, selector: string | Element): Array<Element>;
275
276
  /**
276
277
  * @param {Element} elem1
277
278
  * @param {Element} elem2
@@ -291,10 +292,10 @@ declare namespace _default {
291
292
  function replaceChild(el: Element, child: Element, oldChild: Element): Element;
292
293
  /**
293
294
  * @param {Element} el
294
- * @param {Element[]} children
295
+ * @param {NodeList|Array<Element>|string[]} children
295
296
  * @returns {Element}
296
297
  */
297
- function replaceChildren(el: Element, ...children: Element[]): Element;
298
+ function replaceChildren(el: Element, ...children: NodeList | Array<Element> | string[]): Element;
298
299
  /**
299
300
  * @param {Element|Document|Window} el
300
301
  * @returns {{top: number, left: number}}
@@ -304,4 +305,3 @@ declare namespace _default {
304
305
  left: number;
305
306
  };
306
307
  }
307
- export default _default;
package/types/index.d.ts CHANGED
@@ -1,19 +1,6 @@
1
1
  export default webf;
2
2
  declare const webf: {
3
- eventDispatcher: {
4
- "__#1@#listeners": {};
5
- addListener(eventsName: any, callback: any, context: any, ...args: any[]): /*elided*/ any;
6
- addListenerOnce(eventsName: any, callback: any, context: any, ...listenerArgs: any[]): /*elided*/ any;
7
- dispatch(eventsName: any, ...args: any[]): /*elided*/ any;
8
- hasListener(eventName: any, callback: any, context: any): boolean;
9
- removeListener(eventName: any, callback: any, context: any): /*elided*/ any;
10
- getListeners(eventName: any): any;
11
- reset(): void;
12
- };
13
- translate: (lang: any, ns: any, label: any) => any;
14
- _: (lang: any, ns: any, label: any) => any;
15
- getLang: () => any;
16
- setLang: (lang: any) => void;
3
+ default: typeof i18n.default;
17
4
  equals: (o1: any, o2: any, seen?: WeakMap<WeakKey, any>) => any;
18
5
  noop: () => void;
19
6
  sizeOf: (o: any) => number;
@@ -62,24 +49,24 @@ declare const webf: {
62
49
  } | string, value?: string): Element | DOMStringMap;
63
50
  removeData(el: Element, name: string): Element | any;
64
51
  on(el: Element | Document | Window, events: string, selector: string | Element | Function, handler?: Function | AddEventListenerOptions | boolean, options?: AddEventListenerOptions | boolean): Element;
65
- off(el: Element | Document | Window, events?: string, selector: string | Element | Function, handler?: Function | AddEventListenerOptions | boolean, options?: AddEventListenerOptions | boolean): Element;
52
+ off(el: Element | Document | Window, events?: string, selector?: string | Element | Function, handler?: Function | AddEventListenerOptions | boolean, options?: AddEventListenerOptions | boolean): Element;
66
53
  css(el: HTMLElement, style: {
67
54
  [x: string]: string;
68
55
  } | string, value?: string): Element;
69
- closestFind(el: Element, selectorClosest: string, selectorFind: string): NodeList | null;
56
+ closestFind(el: Element, selectorClosest: string, selectorFind: string): Array<Element>;
70
57
  closestFindOne(el: Element, selectorClosest: string, selectorFindOne: string): Element | null;
71
58
  first(nodeList: NodeList | Element | Array<Element>): Element | null;
72
59
  last(nodeList: NodeList | Array<Element>): Element | null;
73
- create(html: string): Element | null;
60
+ create(html: string): Element | DocumentFragment | null;
74
61
  eq(nodeList: NodeList | Array<Element>, index?: number): Element | null;
75
62
  after(el: Element, newEl: Element | string): Element | null;
76
63
  before(el: Element, newEl: Element | string): Element | null;
77
64
  empty(el: Element): Element;
78
- not(el: Element | NodeList, selector: string | Element): Element[];
65
+ not(el: Element | NodeList | Array<Element>, selector: string | Element): Array<Element>;
79
66
  collide(elem1: Element, elem2: Element): boolean;
80
67
  matches(el: Element, selector: string | Element): boolean;
81
68
  replaceChild(el: Element, child: Element, oldChild: Element): Element;
82
- replaceChildren(el: Element, ...children: Element[]): Element;
69
+ replaceChildren(el: Element, ...children: NodeList | Array<Element> | string[]): Element;
83
70
  offset(el: Element | Document | Window): {
84
71
  top: number;
85
72
  left: number;
@@ -176,4 +163,7 @@ import dom from './dom.js';
176
163
  import * as math from './math.js';
177
164
  import * as utils from './utils.js';
178
165
  import eventDispatcher from './eventDispatcher.js';
179
- export { stringFunctions, arrayFunctions, traversal, is, random, getStyle, dom, math, utils, eventDispatcher };
166
+ import Mouse from './Mouse.js';
167
+ import Translator from './Translator.js';
168
+ import * as i18n from './Translator.js';
169
+ export { stringFunctions, arrayFunctions, traversal, is, random, getStyle, dom, math, utils, eventDispatcher, Mouse, Translator };
@@ -7,4 +7,4 @@ export function clone<T>(o: T): T;
7
7
  export function merge<T>(first: Collection<T>, second?: Collection<T>, ...args: Collection<T>[]): Array<T>;
8
8
  export type Collection<T> = Array<T> | Set<T> | Map<any, T> | {
9
9
  [x: string]: T;
10
- } | string;
10
+ } | string | string[];