@asamuzakjp/dom-selector 7.0.8 → 7.0.9
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/package.json +2 -2
- package/src/index.js +1 -45
- package/src/js/cache.js +77 -0
- package/types/index.d.ts +0 -11
- package/types/js/cache.d.ts +12 -0
package/package.json
CHANGED
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
"eslint-plugin-regexp": "^3.1.0",
|
|
44
44
|
"eslint-plugin-unicorn": "^64.0.0",
|
|
45
45
|
"globals": "^17.4.0",
|
|
46
|
-
"jsdom": "^29.0.
|
|
46
|
+
"jsdom": "^29.0.2",
|
|
47
47
|
"mocha": "^11.7.5",
|
|
48
48
|
"neostandard": "^0.13.0",
|
|
49
49
|
"prettier": "^3.8.1",
|
|
@@ -71,5 +71,5 @@
|
|
|
71
71
|
"engines": {
|
|
72
72
|
"node": "^20.19.0 || ^22.12.0 || >=24.0.0"
|
|
73
73
|
},
|
|
74
|
-
"version": "7.0.
|
|
74
|
+
"version": "7.0.9"
|
|
75
75
|
}
|
package/src/index.js
CHANGED
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
8
|
/* import */
|
|
9
|
+
import { GenerationalCache } from './js/cache.js';
|
|
9
10
|
import { Finder } from './js/finder.js';
|
|
10
11
|
import { filterSelector, getType, initNwsapi } from './js/utility.js';
|
|
11
12
|
|
|
@@ -21,50 +22,6 @@ import {
|
|
|
21
22
|
} from './js/constant.js';
|
|
22
23
|
const MAX_CACHE = 1024;
|
|
23
24
|
|
|
24
|
-
/* Generational Cache */
|
|
25
|
-
export class GenerationalCache {
|
|
26
|
-
constructor(max) {
|
|
27
|
-
this.max = Math.ceil(max / 2);
|
|
28
|
-
this.current = new Map();
|
|
29
|
-
this.old = new Map();
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
get(key) {
|
|
33
|
-
let value = this.current.get(key);
|
|
34
|
-
if (value !== undefined) {
|
|
35
|
-
return value;
|
|
36
|
-
}
|
|
37
|
-
value = this.old.get(key);
|
|
38
|
-
if (value !== undefined) {
|
|
39
|
-
this.set(key, value);
|
|
40
|
-
return value;
|
|
41
|
-
}
|
|
42
|
-
return undefined;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
set(key, value) {
|
|
46
|
-
this.current.set(key, value);
|
|
47
|
-
if (this.current.size >= this.max) {
|
|
48
|
-
this.old = this.current;
|
|
49
|
-
this.current = new Map();
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
has(key) {
|
|
54
|
-
return this.current.has(key) || this.old.has(key);
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
delete(key) {
|
|
58
|
-
this.current.delete(key);
|
|
59
|
-
this.old.delete(key);
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
clear() {
|
|
63
|
-
this.current.clear();
|
|
64
|
-
this.old.clear();
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
|
|
68
25
|
/**
|
|
69
26
|
* @typedef {object} CheckResult
|
|
70
27
|
* @property {boolean} match - The match result.
|
|
@@ -104,7 +61,6 @@ export class DOMSelector {
|
|
|
104
61
|
*/
|
|
105
62
|
clear = () => {
|
|
106
63
|
this.#finder.clearResults(true);
|
|
107
|
-
// this.#cache.clear();
|
|
108
64
|
};
|
|
109
65
|
|
|
110
66
|
/**
|
package/src/js/cache.js
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* cache.js
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
/* Generational Cache */
|
|
6
|
+
export class GenerationalCache {
|
|
7
|
+
#max;
|
|
8
|
+
#boundary;
|
|
9
|
+
#current;
|
|
10
|
+
#old;
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* constructor
|
|
14
|
+
* @param {number} max - max cache size
|
|
15
|
+
*/
|
|
16
|
+
constructor(max) {
|
|
17
|
+
this.#current = new Map();
|
|
18
|
+
this.#old = new Map();
|
|
19
|
+
this.max = max;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
get size() {
|
|
23
|
+
return this.#current.size + this.#old.size;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* @returns {number} max cache size
|
|
28
|
+
*/
|
|
29
|
+
get max() {
|
|
30
|
+
return this.#max;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
set max(value) {
|
|
34
|
+
if (Number.isFinite(value) && value > 4) {
|
|
35
|
+
this.#max = value;
|
|
36
|
+
this.#boundary = Math.ceil(value / 2);
|
|
37
|
+
} else {
|
|
38
|
+
this.#max = 4;
|
|
39
|
+
this.#boundary = 2;
|
|
40
|
+
}
|
|
41
|
+
this.clear();
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
get(key) {
|
|
45
|
+
if (this.#current.has(key)) {
|
|
46
|
+
return this.#current.get(key);
|
|
47
|
+
}
|
|
48
|
+
const value = this.#old.get(key);
|
|
49
|
+
if (value !== undefined) {
|
|
50
|
+
this.set(key, value);
|
|
51
|
+
return value;
|
|
52
|
+
}
|
|
53
|
+
return undefined;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
set(key, value) {
|
|
57
|
+
this.#current.set(key, value);
|
|
58
|
+
if (this.#current.size >= this.#boundary) {
|
|
59
|
+
this.#old = this.#current;
|
|
60
|
+
this.#current = new Map();
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
has(key) {
|
|
65
|
+
return this.#current.has(key) || this.#old.has(key);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
delete(key) {
|
|
69
|
+
this.#current.delete(key);
|
|
70
|
+
this.#old.delete(key);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
clear() {
|
|
74
|
+
this.#current.clear();
|
|
75
|
+
this.#old.clear();
|
|
76
|
+
}
|
|
77
|
+
}
|
package/types/index.d.ts
CHANGED
|
@@ -1,14 +1,3 @@
|
|
|
1
|
-
export class GenerationalCache {
|
|
2
|
-
constructor(max: any);
|
|
3
|
-
max: number;
|
|
4
|
-
current: Map<any, any>;
|
|
5
|
-
old: Map<any, any>;
|
|
6
|
-
get(key: any): any;
|
|
7
|
-
set(key: any, value: any): void;
|
|
8
|
-
has(key: any): boolean;
|
|
9
|
-
delete(key: any): void;
|
|
10
|
-
clear(): void;
|
|
11
|
-
}
|
|
12
1
|
export class DOMSelector {
|
|
13
2
|
constructor(window: Window, document: Document, opt?: object);
|
|
14
3
|
clear: () => void;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export class GenerationalCache {
|
|
2
|
+
constructor(max: number);
|
|
3
|
+
set max(value: number);
|
|
4
|
+
get max(): number;
|
|
5
|
+
get size(): number;
|
|
6
|
+
get(key: any): any;
|
|
7
|
+
set(key: any, value: any): void;
|
|
8
|
+
has(key: any): boolean;
|
|
9
|
+
delete(key: any): void;
|
|
10
|
+
clear(): void;
|
|
11
|
+
#private;
|
|
12
|
+
}
|