jsquery_node 1.0.12 → 1.0.14

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.
Files changed (2) hide show
  1. package/jsquery.ts +156 -170
  2. package/package.json +1 -1
package/jsquery.ts CHANGED
@@ -1,72 +1,51 @@
1
- export const { $, JSQuery } = (() => {
2
- class ElementArray extends Array<Element> {
3
- on<K extends keyof DocumentEventMap>(e: K, func: (this: HTMLElement, ev: DocumentEventMap[K])=>any, s?: boolean | AddEventListenerOptions) {
4
- this.forEach((v) => v.on(e, func, s));
5
- return this;
6
- }
7
- rect() {
8
- return this.map((v) => v.rect());
9
- }
10
- hasClass(c:string) {
11
- return this.map((v) => v.hasClass(c));
12
- }
13
- is(q:string) {
14
- return this.map((v) => v.is(q));
15
- }
16
- checked(): boolean[];
17
- checked(val: boolean): this;
18
- checked(val?: boolean): this | boolean[] {
19
- if (val !== undefined) {
20
- this.forEach((v) => v.checked(val));
21
- return this;
1
+ export namespace JSQuery {
2
+ function toArray(elt: NodeList | HTMLCollection | HTMLElement) {
3
+ return elt instanceof NodeList || elt instanceof HTMLCollection;
4
+ }
5
+ function toElt(elt: Element): HTMLElement {
6
+ if (elt instanceof Element) return elt.elt;
7
+ return elt;
8
+ }
9
+ export class Extension {
10
+ constructor() {
11
+ if (this.constructor === Extension) {
12
+ throw new Error(
13
+ "you can't make an instance of class: JSQuery.Extension"
14
+ );
22
15
  }
23
- return this.map((v) => v.checked()) as any;
24
16
  }
25
- trigger(e: any) {
26
- this.forEach((v) => v.trigger(e));
27
- return this;
28
- }
29
- css(styles: Record<string, any>) {
30
- this.forEach((v) => v.css(styles));
31
- return this;
32
- }
33
- props(props: Record<string, any>) {
34
- this.forEach((v) => v.props(props));
35
- return this;
36
- }
37
- class(names: string | string[]) {
38
- this.forEach((v) => v.class(names));
39
- return this;
17
+ get() {
18
+ return {
19
+ $: this.$(),
20
+ Element: this.Element(),
21
+ static_Element: this.static_Element(),
22
+ static_ElementArray: this.static_ElementArray(),
23
+ ElementArray: this.ElementArray(),
24
+ JSQuery: this.JSQuery(),
25
+ };
40
26
  }
41
- removeClass(names: string | string[]) {
42
- this.forEach((v) => v.removeClass(names));
43
- return this;
27
+ $() {
28
+ return {};
44
29
  }
45
- toggleClass(names: string | string[]) {
46
- this.forEach((v) => v.toggleClass(names));
47
- return this;
30
+ Element() {
31
+ return {};
48
32
  }
49
- remove() {
50
- this.forEach((v) => v.remove());
51
- return this;
33
+ ElementArray() {
34
+ return {};
52
35
  }
53
- new() {
54
- const temp = new ElementArray();
55
- this.forEach((v) => temp.push(v.new() as any));
56
- return temp;
36
+
37
+ static_Element() {
38
+ return {};
57
39
  }
58
- //events
59
- click(func: (this:HTMLElement, ev: any) => any, s?: boolean | AddEventListenerOptions) {
60
- this.forEach((v) => v.click(func, s));
61
- return this;
40
+ static_ElementArray() {
41
+ return {};
62
42
  }
63
- }
64
43
 
65
- function toArray(elt: NodeList | HTMLCollection | HTMLElement) {
66
- return elt instanceof NodeList || elt instanceof HTMLCollection;
44
+ JSQuery() {
45
+ return {};
46
+ }
67
47
  }
68
-
69
- class Element {
48
+ export class Element {
70
49
  elt: HTMLElement;
71
50
  #TriggerEvent(e: any, func: (this:HTMLElement, ev: any) => any, s?: boolean | AddEventListenerOptions) {
72
51
  if (!func) {
@@ -221,136 +200,143 @@ export const { $, JSQuery } = (() => {
221
200
  return this;
222
201
  }
223
202
  }
224
-
225
- function toElt(elt: Element): HTMLElement {
226
- if (elt instanceof Element) return elt.elt;
227
- return elt;
203
+ export class Caching extends Extension {
204
+ $() {
205
+ return {
206
+ cache<T extends (...args:any[])=>any>(func: T): T {
207
+ const f = (...args: Parameters<T>): ReturnType<T> => {
208
+ const val = JSON.stringify(args);
209
+ if (f.cache.hasOwnProperty(val)) {
210
+ return f.cache[val];
211
+ }
212
+ const temp = func(...args);
213
+ f.cache[val] = temp;
214
+ return temp;
215
+ };
216
+ f.cache = {};
217
+ return f as any;
218
+ },
219
+ };
220
+ }
228
221
  }
229
-
230
- class Extension {
231
- constructor() {
232
- if (this.constructor === Extension) {
233
- throw new Error(
234
- "you can't make an instance of class: JSQuery.Extension"
235
- );
222
+ export class ElementArray extends Array<Element> {
223
+ on<K extends keyof DocumentEventMap>(e: K, func: (this: HTMLElement, ev: DocumentEventMap[K])=>any, s?: boolean | AddEventListenerOptions) {
224
+ this.forEach((v) => v.on(e, func, s));
225
+ return this;
226
+ }
227
+ rect() {
228
+ return this.map((v) => v.rect());
229
+ }
230
+ hasClass(c:string) {
231
+ return this.map((v) => v.hasClass(c));
232
+ }
233
+ is(q:string) {
234
+ return this.map((v) => v.is(q));
235
+ }
236
+ checked(): boolean[];
237
+ checked(val: boolean): this;
238
+ checked(val?: boolean): this | boolean[] {
239
+ if (val !== undefined) {
240
+ this.forEach((v) => v.checked(val));
241
+ return this;
236
242
  }
243
+ return this.map((v) => v.checked()) as any;
237
244
  }
238
- get() {
239
- return {
240
- $: this.$(),
241
- Element: this.Element(),
242
- static_Element: this.static_Element(),
243
- static_ElementArray: this.static_ElementArray(),
244
- ElementArray: this.ElementArray(),
245
- JSQuery: this.JSQuery(),
246
- };
245
+ trigger(e: any) {
246
+ this.forEach((v) => v.trigger(e));
247
+ return this;
247
248
  }
248
- $() {
249
- return {};
249
+ css(styles: Record<string, any>) {
250
+ this.forEach((v) => v.css(styles));
251
+ return this;
250
252
  }
251
- Element() {
252
- return {};
253
+ props(props: Record<string, any>) {
254
+ this.forEach((v) => v.props(props));
255
+ return this;
253
256
  }
254
- ElementArray() {
255
- return {};
257
+ class(names: string | string[]) {
258
+ this.forEach((v) => v.class(names));
259
+ return this;
256
260
  }
257
-
258
- static_Element() {
259
- return {};
261
+ removeClass(names: string | string[]) {
262
+ this.forEach((v) => v.removeClass(names));
263
+ return this;
260
264
  }
261
- static_ElementArray() {
262
- return {};
265
+ toggleClass(names: string | string[]) {
266
+ this.forEach((v) => v.toggleClass(names));
267
+ return this;
263
268
  }
264
-
265
- JSQuery() {
266
- return {};
269
+ remove() {
270
+ this.forEach((v) => v.remove());
271
+ return this;
272
+ }
273
+ new() {
274
+ const temp = new ElementArray();
275
+ this.forEach((v) => temp.push(v.new() as any));
276
+ return temp;
277
+ }
278
+ //events
279
+ click(func: (this:HTMLElement, ev: any) => any, s?: boolean | AddEventListenerOptions) {
280
+ this.forEach((v) => v.click(func, s));
281
+ return this;
267
282
  }
268
283
  }
284
+ export const Plugin = Extension;
285
+ export type Plugin = Extension;
286
+ }
269
287
 
270
- function J(q: any): Element | null {
271
- return Element.from(document.querySelector(q)) as any;
272
- }
273
-
274
- J.from = ((elt:any) => {
275
- return Element.from(elt);
276
- }) as typeof Element.from;
277
-
278
- J.all = (q: any): ElementArray => {
279
- return Element.from(document.querySelectorAll(q)) as any;
280
- };
281
288
 
282
- let head: Element;
283
- J.head = () => {
284
- if (!head) head = Element.from(document.head) as Element;
285
- return head;
286
- };
289
+ function J(q: any): JSQuery.Element | null {
290
+ return JSQuery.Element.from(document.querySelector(q)) as any;
291
+ };
287
292
 
288
- let body: Element;
289
- J.body = () => {
290
- if (!body) body = Element.from(document.body) as Element;
291
- return body;
292
- };
293
+ J.from = ((elt:any) => {
294
+ return JSQuery.Element.from(elt);
295
+ }) as typeof JSQuery.Element.from;
293
296
 
294
- let doc: Element;
295
- J.doc = () => {
296
- if (!doc) doc = Element.from(document as any) as Element;
297
- return doc;
298
- };
297
+ J.all = (q: any): JSQuery.ElementArray => {
298
+ return JSQuery.Element.from(document.querySelectorAll(q)) as any;
299
+ };
299
300
 
300
- J.create = (t: any): Element => {
301
- return Element.from(document.createElement(t)) as any;
302
- };
301
+ let head: JSQuery.Element;
302
+ J.head = () => {
303
+ if (!head) head = JSQuery.Element.from(document.head) as JSQuery.Element;
304
+ return head;
305
+ };
303
306
 
304
- const JSQuery = {
305
- Element,
306
- ElementArray,
307
- Extension,
308
- Plugin: Extension,
309
- Caching: class Caching extends Extension {
310
- $() {
311
- return {
312
- cache<T extends (...args:any[])=>any>(func: T): T {
313
- const f = (...args: Parameters<T>): ReturnType<T> => {
314
- const val = JSON.stringify(args);
315
- if (f.cache.hasOwnProperty(val)) {
316
- return f.cache[val];
317
- }
318
- const temp = func(...args);
319
- f.cache[val] = temp;
320
- return temp;
321
- };
322
- f.cache = {};
323
- return f as any;
324
- },
325
- };
326
- }
327
- },
328
- };
307
+ let body: JSQuery.Element;
308
+ J.body = () => {
309
+ if (!body) body = JSQuery.Element.from(document.body) as JSQuery.Element;
310
+ return body;
311
+ };
329
312
 
330
- J.loadExtension = (extend: new()=>Extension) => {
331
- if (Object.getPrototypeOf(extend) !== Extension) {
332
- throw new Error(
333
- "the class is not a child of JSQuery.Extension or the inputed class is an instance"
334
- );
335
- }
336
- body = undefined;
337
- head = undefined;
338
- const items = new extend().get();
339
- Object.assign(J, items.$);
340
- Object.assign(JSQuery, items.JSQuery);
341
- Object.assign(Element.prototype, items.Element);
342
- Object.assign(ElementArray.prototype, items.ElementArray);
343
- Object.assign(Element, items.static_Element);
344
- Object.assign(ElementArray, items.static_ElementArray);
345
- }
313
+ let doc: JSQuery.Element;
314
+ J.doc = () => {
315
+ if (!doc) doc = JSQuery.Element.from(document as any) as JSQuery.Element;
316
+ return doc;
317
+ };
346
318
 
347
- J.loadPlugin = J.loadExtension;
319
+ J.create = (t: any): JSQuery.Element => {
320
+ return JSQuery.Element.from(document.createElement(t)) as any;
321
+ };
348
322
 
349
- return { $: J, JSQuery };
350
- })();
323
+ J.loadExtension = (extend: new()=>JSQuery.Extension) => {
324
+ if (Object.getPrototypeOf(extend) !== JSQuery.Extension) {
325
+ throw new Error(
326
+ "the class is not a child of JSQuery.Extension or the inputed class is an instance"
327
+ );
328
+ }
329
+ body = undefined;
330
+ head = undefined;
331
+ const items = new extend().get();
332
+ Object.assign(J, items.$);
333
+ Object.assign(JSQuery, items.JSQuery);
334
+ Object.assign(JSQuery.Element.prototype, items.Element);
335
+ Object.assign(JSQuery.ElementArray.prototype, items.ElementArray);
336
+ Object.assign(JSQuery.Element, items.static_Element);
337
+ Object.assign(JSQuery.ElementArray, items.static_ElementArray);
338
+ }
351
339
 
352
- export type ElementArray = typeof JSQuery.ElementArray;
353
- export type Element = typeof JSQuery.Element;
354
- export type Extension = typeof JSQuery.Extension;
355
- export type Plugin = typeof JSQuery.Extension;
340
+ J.loadPlugin = J.loadExtension;
341
+ export const $ = J;
356
342
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jsquery_node",
3
- "version": "1.0.12",
3
+ "version": "1.0.14",
4
4
  "description": "jsquery",
5
5
  "homepage": "https://github.com/chickencuber/jsquery_node#readme",
6
6
  "bugs": {