@webalternatif/js-core 1.2.1 → 1.3.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.
package/types/dom.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  export function isWindow(o: any): boolean;
2
+ export function isDocument(o: any): boolean;
2
3
  export function isDomElement(o: any): boolean;
3
- export function getStyle(elem: any, cssRule: any): any;
4
+ export function getStyle(el: Element, cssRule: string): string;
4
5
  declare namespace _default {
5
6
  /**
6
7
  * @param {Element} el
@@ -15,17 +16,31 @@ declare namespace _default {
15
16
  */
16
17
  function child(el: Element, selector?: string): Element | null;
17
18
  /**
18
- * @param {Element|Document} refEl
19
- * @param {string|Element|NodeList|Array<Element>} [selector]
20
- * @returns {Element|null}
19
+ * @param {Element|Document|string} refEl
20
+ * @param {string|Element|NodeList|Array<Element>} selector
21
+ * @returns {Element}
21
22
  */
22
- function findOne(refEl: Element | Document, selector?: string | Element | NodeList | Array<Element>): Element | null;
23
+ function findOne(refEl: Element | Document | string, selector: string | Element | NodeList | Array<Element>): Element;
23
24
  /**
24
- * @param {Element|Document} refEl
25
+ * @param {Element|Document|string} refEl
25
26
  * @param {string|Element|NodeList|Array<Element>} selector
26
27
  * @returns {Array<Element>}
27
28
  */
28
- function find(refEl: Element | Document, selector: string | Element | NodeList | Array<Element>): Array<Element>;
29
+ function find(refEl: Element | Document | string, selector: string | Element | NodeList | Array<Element>): Array<Element>;
30
+ /**
31
+ * @param {Element|string} el
32
+ * @param {string} data
33
+ * @param {string} [value]
34
+ * @returns {Element|null}
35
+ */
36
+ function findOneByData(el: Element | string, data: string, value?: string): Element | null;
37
+ /**
38
+ * @param {Element|string} el
39
+ * @param {string} data
40
+ * @param {string} [value]
41
+ * @returns {Element[]}
42
+ */
43
+ function findByData(el: Element | string, data: string, value?: string): Element[];
29
44
  /**
30
45
  * @param {Element|NodeList|Array<Element>} el
31
46
  * @param {string} className
@@ -53,16 +68,16 @@ declare namespace _default {
53
68
  function hasClass(el: Element, classNames: string): boolean;
54
69
  /**
55
70
  * @param {Node} node
56
- * @param {...Node} children
71
+ * @param {...(Node|string)} children
57
72
  * @returns {Node}
58
73
  */
59
- function append(node: Node, ...children: Node[]): Node;
74
+ function append(node: Node, ...children: (Node | string)[]): Node;
60
75
  /**
61
76
  * @param {Node} node
62
- * @param {...Node} children
77
+ * @param {...(Node|string)} children
63
78
  * @returns {Node}
64
79
  */
65
- function prepend(node: Node, ...children: Node[]): Node;
80
+ function prepend(node: Node, ...children: (Node | string)[]): Node;
66
81
  /**
67
82
  * @param {Element|NodeList|Array<Element>|string} els
68
83
  * @returns {void}
@@ -70,10 +85,10 @@ declare namespace _default {
70
85
  function remove(...els: Element | NodeList | Array<Element> | string): void;
71
86
  /**
72
87
  * @param {Element} el
73
- * @param {string|Element} selector
88
+ * @param {string|Element} [selector]
74
89
  * @returns {Element|null}
75
90
  */
76
- function closest(el: Element, selector: string | Element): Element | null;
91
+ function closest(el: Element, selector?: string | Element): Element | null;
77
92
  /**
78
93
  * @param {Element} el
79
94
  * @param {string} [selector]
@@ -174,20 +189,22 @@ declare namespace _default {
174
189
  function removeData(el: Element, name: string): Element | any;
175
190
  /**
176
191
  * @param {Element|Document|Window} el
177
- * @param {string} event
178
- * @param {function} handler
179
- * @param {AddEventListenerOptions|false} options
192
+ * @param {string} events
193
+ * @param {string|Element|function} selector
194
+ * @param {function|AddEventListenerOptions|boolean} [handler]
195
+ * @param {AddEventListenerOptions|boolean} [options]
180
196
  * @returns {Element}
181
197
  */
182
- function on(el: Element | Document | Window, event: string, handler: Function, options?: AddEventListenerOptions | false): Element;
198
+ function on(el: Element | Document | Window, events: string, selector: string | Element | Function, handler?: Function | AddEventListenerOptions | boolean, options?: AddEventListenerOptions | boolean): Element;
183
199
  /**
184
200
  * @param {Element|Document|Window} el
185
- * @param {string} event
186
- * @param {function} handler
187
- * @param {Object} options
201
+ * @param {string} [events]
202
+ * @param {string|Element|function} selector
203
+ * @param {function|AddEventListenerOptions|boolean} [handler]
204
+ * @param {AddEventListenerOptions|boolean} [options]
188
205
  * @returns {Element}
189
206
  */
190
- function off(el: Element | Document | Window, event: string, handler: Function, options: Object): Element;
207
+ function off(el: Element | Document | Window, events?: string, selector: string | Element | Function, handler?: Function | AddEventListenerOptions | boolean, options?: AddEventListenerOptions | boolean): Element;
191
208
  /**
192
209
  * @param {HTMLElement} el
193
210
  * @param {Object<string, string>|string} style
@@ -227,23 +244,23 @@ declare namespace _default {
227
244
  */
228
245
  function create(html: string): Element | null;
229
246
  /**
230
- * @param {NodeList} nodeList
247
+ * @param {NodeList|Array<Element>} nodeList
231
248
  * @param {number} [index=0]
232
249
  * @returns {Element|null}
233
250
  */
234
- function eq(nodeList: NodeList, index?: number): Element | null;
251
+ function eq(nodeList: NodeList | Array<Element>, index?: number): Element | null;
235
252
  /**
236
253
  * @param {Element} el
237
- * @param {Element} newEl
238
- * @returns {Element}
254
+ * @param {Element|string} newEl
255
+ * @returns {Element|null}
239
256
  */
240
- function after(el: Element, newEl: Element): Element;
257
+ function after(el: Element, newEl: Element | string): Element | null;
241
258
  /**
242
259
  * @param {Element} el
243
- * @param {Element} newEl
244
- * @returns {Element}
260
+ * @param {Element|string} newEl
261
+ * @returns {Element|null}
245
262
  */
246
- function before(el: Element, newEl: Element): Element;
263
+ function before(el: Element, newEl: Element | string): Element | null;
247
264
  /**
248
265
  * @param {Element} el
249
266
  * @returns {Element}
@@ -255,6 +272,17 @@ declare namespace _default {
255
272
  * @return {Element[]}
256
273
  */
257
274
  function not(el: Element | NodeList, selector: string | Element): Element[];
275
+ /**
276
+ * @param {Element} elem1
277
+ * @param {Element} elem2
278
+ * @returns {boolean}
279
+ */
280
+ function collide(elem1: Element, elem2: Element): boolean;
281
+ /**
282
+ * @param {Element} el
283
+ * @param {string|Element} selector
284
+ */
285
+ function matches(el: Element, selector: string | Element): boolean;
258
286
  /**
259
287
  * @param {Element} el
260
288
  * @param {Element} child
@@ -267,5 +295,13 @@ declare namespace _default {
267
295
  * @returns {Element}
268
296
  */
269
297
  function replaceChildren(el: Element, ...children: Element[]): Element;
298
+ /**
299
+ * @param {Element|Document|Window} el
300
+ * @returns {{top: number, left: number}}
301
+ */
302
+ function offset(el: Element | Document | Window): {
303
+ top: number;
304
+ left: number;
305
+ };
270
306
  }
271
307
  export default _default;
package/types/index.d.ts CHANGED
@@ -31,16 +31,18 @@ declare const webf: {
31
31
  dom: {
32
32
  children(el: Element, selector?: string): NodeList;
33
33
  child(el: Element, selector?: string): Element | null;
34
- findOne(refEl: Element | Document, selector?: string | Element | NodeList | Array<Element>): Element | null;
35
- find(refEl: Element | Document, selector: string | Element | NodeList | Array<Element>): Array<Element>;
34
+ findOne(refEl: Element | Document | string, selector: string | Element | NodeList | Array<Element>): Element;
35
+ find(refEl: Element | Document | string, selector: string | Element | NodeList | Array<Element>): Array<Element>;
36
+ findOneByData(el: Element | string, data: string, value?: string): Element | null;
37
+ findByData(el: Element | string, data: string, value?: string): Element[];
36
38
  addClass(el: Element | NodeList | Array<Element>, className: string): Element | NodeList | Array<Element>;
37
39
  removeClass(el: Element | NodeList | Array<Element>, className: string): Element | NodeList | Array<Element>;
38
40
  toggleClass(el: Element, classNames: string, force?: boolean): Element;
39
41
  hasClass(el: Element, classNames: string): boolean;
40
- append(node: Node, ...children: Node[]): Node;
41
- prepend(node: Node, ...children: Node[]): Node;
42
+ append(node: Node, ...children: (Node | string)[]): Node;
43
+ prepend(node: Node, ...children: (Node | string)[]): Node;
42
44
  remove(...els: Element | NodeList | Array<Element> | string): void;
43
- closest(el: Element, selector: string | Element): Element | null;
45
+ closest(el: Element, selector?: string | Element): Element | null;
44
46
  next(el: Element, selector?: string): Element | null;
45
47
  prev(el: Element, selector?: string | null): Element | null;
46
48
  nextAll(el: Element, selector?: string): Element[];
@@ -59,8 +61,8 @@ declare const webf: {
59
61
  [x: string]: string;
60
62
  } | string, value?: string): Element | DOMStringMap;
61
63
  removeData(el: Element, name: string): Element | any;
62
- on(el: Element | Document | Window, event: string, handler: Function, options?: AddEventListenerOptions | false): Element;
63
- off(el: Element | Document | Window, event: string, handler: Function, options: Object): Element;
64
+ 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;
64
66
  css(el: HTMLElement, style: {
65
67
  [x: string]: string;
66
68
  } | string, value?: string): Element;
@@ -69,20 +71,51 @@ declare const webf: {
69
71
  first(nodeList: NodeList | Element | Array<Element>): Element | null;
70
72
  last(nodeList: NodeList | Array<Element>): Element | null;
71
73
  create(html: string): Element | null;
72
- eq(nodeList: NodeList, index?: number): Element | null;
73
- after(el: Element, newEl: Element): Element;
74
- before(el: Element, newEl: Element): Element;
74
+ eq(nodeList: NodeList | Array<Element>, index?: number): Element | null;
75
+ after(el: Element, newEl: Element | string): Element | null;
76
+ before(el: Element, newEl: Element | string): Element | null;
75
77
  empty(el: Element): Element;
76
78
  not(el: Element | NodeList, selector: string | Element): Element[];
79
+ collide(elem1: Element, elem2: Element): boolean;
80
+ matches(el: Element, selector: string | Element): boolean;
77
81
  replaceChild(el: Element, child: Element, oldChild: Element): Element;
78
82
  replaceChildren(el: Element, ...children: Element[]): Element;
83
+ offset(el: Element | Document | Window): {
84
+ top: number;
85
+ left: number;
86
+ };
79
87
  };
80
88
  isWindow: (o: any) => boolean;
89
+ isDocument: (o: any) => boolean;
81
90
  isDomElement: (o: any) => boolean;
82
- getStyle: (elem: any, cssRule: any) => any;
91
+ getStyle: (el: Element, cssRule: string) => string;
92
+ randAlpha: (n: any) => string;
93
+ randAlphaCs: (n: any) => string;
94
+ randAlphaNum: (n: any) => string;
95
+ randAlphaNumCs: (n: any) => string;
96
+ randNum: (n: any) => string;
97
+ rand: (range: any, n: any) => string;
98
+ uniqid: (prefix?: string) => string;
99
+ isString: (str: any) => boolean;
100
+ isObject: (o: any) => boolean;
101
+ isFunction: (f: any) => boolean;
102
+ isPlainObject: (o: any) => boolean;
103
+ isBoolean: (b: any) => boolean;
104
+ isBool: (b: any) => boolean;
105
+ isUndefined: (v: any) => v is undefined;
106
+ isArrayLike: (o: any) => boolean;
107
+ isArray: (a: any) => a is any[];
108
+ isDate: (o: any) => boolean;
109
+ isEvent: (o: any) => boolean;
110
+ isInteger: (n: any) => boolean;
111
+ isInt: (n: any) => boolean;
112
+ isFloat: (n: any) => boolean;
113
+ isScalar: (value: any) => boolean;
114
+ isEventSupported: (eventName: any) => boolean;
115
+ isTouchDevice: () => boolean;
83
116
  each: <T>(o: Collection<T>, callback: (key: number | string, value: T, o: Collection<T>, index: number) => (void | boolean), context?: any) => typeof o;
84
117
  foreach: <T>(o: Collection<T>, callback: (value: T, key: number | string, o: Collection<T>, index: number) => (void | boolean), context?: any) => typeof o;
85
- map: <T, R>(o: Collection<T>, callback: (key: number | string, value: T, o: Collection<T>, index: number) => (R | null | false), context?: any) => any[];
118
+ map: <T, R>(o: Collection<T>, callback: (key: number | string, value: T, o: Collection<T>, index: number) => (R | null | false), context?: any) => Array<R>;
86
119
  reduce: <T, R>(o: Collection<T>, callback: (accumulator: R | T, value: T, key: any, index: number, o: Collection<T>) => R, initialValue?: R) => R;
87
120
  extend: <T>(...args: (boolean | T)[]) => T;
88
121
  clone: <T>(o: T) => T;
@@ -125,7 +158,7 @@ declare const webf: {
125
158
  stripTags: (str: any, tag: any) => any;
126
159
  toUrl: (str: any) => any;
127
160
  escapeRegex: (str: any) => any;
128
- camelCase: (str: any) => any;
161
+ camelCase: (str: any) => string;
129
162
  format: (str: any, ...args: any[]) => any;
130
163
  f: (str: any, ...args: any[]) => any;
131
164
  toCssClassName: (str: any) => any;
@@ -136,9 +169,11 @@ declare const webf: {
136
169
  import * as stringFunctions from './string.js';
137
170
  import * as arrayFunctions from './array.js';
138
171
  import * as traversal from './traversal.js';
172
+ import * as is from './is.js';
173
+ import * as random from './random.js';
139
174
  import { getStyle } from './dom.js';
140
175
  import dom from './dom.js';
141
176
  import * as math from './math.js';
142
177
  import * as utils from './utils.js';
143
178
  import eventDispatcher from './eventDispatcher.js';
144
- export { stringFunctions, arrayFunctions, traversal, getStyle, dom, math, utils, eventDispatcher };
179
+ export { stringFunctions, arrayFunctions, traversal, is, random, getStyle, dom, math, utils, eventDispatcher };
package/types/random.d.ts CHANGED
@@ -1,7 +1,7 @@
1
- export function uniqid(): string;
2
1
  export function randAlpha(n: any): string;
3
2
  export function randAlphaCs(n: any): string;
4
3
  export function randAlphaNum(n: any): string;
5
4
  export function randAlphaNumCs(n: any): string;
6
5
  export function randNum(n: any): string;
7
6
  export function rand(range: any, n: any): string;
7
+ export function uniqid(prefix?: string): string;
package/types/string.d.ts CHANGED
@@ -28,7 +28,7 @@ export function repeat(str: any, n: any): string;
28
28
  export function stripTags(str: any, tag: any): any;
29
29
  export function toUrl(str: any): any;
30
30
  export function escapeRegex(str: any): any;
31
- export function camelCase(str: any): any;
31
+ export function camelCase(str: any): string;
32
32
  export function format(str: any, ...args: any[]): any;
33
33
  export function f(str: any, ...args: any[]): any;
34
34
  export function toCssClassName(str: any): any;
@@ -1,6 +1,6 @@
1
1
  export function each<T>(o: Collection<T>, callback: (key: number | string, value: T, o: Collection<T>, index: number) => (void | boolean), context?: any): typeof o;
2
2
  export function foreach<T>(o: Collection<T>, callback: (value: T, key: number | string, o: Collection<T>, index: number) => (void | boolean), context?: any): typeof o;
3
- export function map<T, R>(o: Collection<T>, callback: (key: number | string, value: T, o: Collection<T>, index: number) => (R | null | false), context?: any): any[];
3
+ export function map<T, R>(o: Collection<T>, callback: (key: number | string, value: T, o: Collection<T>, index: number) => (R | null | false), context?: any): Array<R>;
4
4
  export function reduce<T, R>(o: Collection<T>, callback: (accumulator: R | T, value: T, key: any, index: number, o: Collection<T>) => R, initialValue?: R): R;
5
5
  export function extend<T>(...args: (boolean | T)[]): T;
6
6
  export function clone<T>(o: T): T;