@vope/utils 1.4.9 → 1.4.10
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/cjs/index.js +35 -0
- package/lib/index.js +2 -0
- package/lib/subscriber.js +35 -0
- package/package.json +57 -57
- package/types/index.d.ts +1 -0
- package/types/subscriber.d.ts +9 -0
package/cjs/index.js
CHANGED
|
@@ -24,6 +24,7 @@ __export(src_exports, {
|
|
|
24
24
|
MemoryBasic: () => MemoryBasic,
|
|
25
25
|
MemoryList: () => MemoryList,
|
|
26
26
|
MemoryPower: () => MemoryPower,
|
|
27
|
+
Subscriber: () => Subscriber,
|
|
27
28
|
Union: () => Union,
|
|
28
29
|
clamp: () => clamp,
|
|
29
30
|
classnames: () => classnames,
|
|
@@ -523,6 +524,40 @@ var css = (...args) => {
|
|
|
523
524
|
return list.join(";");
|
|
524
525
|
};
|
|
525
526
|
|
|
527
|
+
// src/subscriber.ts
|
|
528
|
+
var Subscriber = class {
|
|
529
|
+
#listeners = {};
|
|
530
|
+
$on(name, listener) {
|
|
531
|
+
const listeners = this.#listeners;
|
|
532
|
+
if (name in listeners) {
|
|
533
|
+
listeners[name].push(listener);
|
|
534
|
+
} else {
|
|
535
|
+
listeners[name] = [listener];
|
|
536
|
+
}
|
|
537
|
+
return this;
|
|
538
|
+
}
|
|
539
|
+
$emit(name, ...args) {
|
|
540
|
+
this.#listeners[name]?.forEach((listener) => listener(...args));
|
|
541
|
+
return this;
|
|
542
|
+
}
|
|
543
|
+
$off(name, listener) {
|
|
544
|
+
const listeners = this.#listeners;
|
|
545
|
+
if (name in listeners === false)
|
|
546
|
+
return this;
|
|
547
|
+
if (listener) {
|
|
548
|
+
listeners[name].some((value, index) => {
|
|
549
|
+
if (value === listener) {
|
|
550
|
+
listeners[name].splice(index, 1);
|
|
551
|
+
return true;
|
|
552
|
+
}
|
|
553
|
+
});
|
|
554
|
+
} else {
|
|
555
|
+
delete listeners[name];
|
|
556
|
+
}
|
|
557
|
+
return this;
|
|
558
|
+
}
|
|
559
|
+
};
|
|
560
|
+
|
|
526
561
|
// src/table/flex.ts
|
|
527
562
|
var FlexTable = class {
|
|
528
563
|
#data = [];
|
package/lib/index.js
CHANGED
|
@@ -21,6 +21,7 @@ import { deconPowersSum } from "./power/decon";
|
|
|
21
21
|
import { rotateAngle } from "./rotate/angle";
|
|
22
22
|
import { rotateRad } from "./rotate/rad";
|
|
23
23
|
import { css } from "./style/css";
|
|
24
|
+
import { default as default2 } from "./subscriber";
|
|
24
25
|
import { FlexTable } from "./table/flex";
|
|
25
26
|
import { Union } from "./union";
|
|
26
27
|
import { joinPaths } from "./url/join";
|
|
@@ -31,6 +32,7 @@ export {
|
|
|
31
32
|
MemoryBasic,
|
|
32
33
|
MemoryList,
|
|
33
34
|
MemoryPower,
|
|
35
|
+
default2 as Subscriber,
|
|
34
36
|
Union,
|
|
35
37
|
clamp,
|
|
36
38
|
classnames,
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
class Subscriber {
|
|
2
|
+
#listeners = {};
|
|
3
|
+
$on(name, listener) {
|
|
4
|
+
const listeners = this.#listeners;
|
|
5
|
+
if (name in listeners) {
|
|
6
|
+
listeners[name].push(listener);
|
|
7
|
+
} else {
|
|
8
|
+
listeners[name] = [listener];
|
|
9
|
+
}
|
|
10
|
+
return this;
|
|
11
|
+
}
|
|
12
|
+
$emit(name, ...args) {
|
|
13
|
+
this.#listeners[name]?.forEach((listener) => listener(...args));
|
|
14
|
+
return this;
|
|
15
|
+
}
|
|
16
|
+
$off(name, listener) {
|
|
17
|
+
const listeners = this.#listeners;
|
|
18
|
+
if (name in listeners === false)
|
|
19
|
+
return this;
|
|
20
|
+
if (listener) {
|
|
21
|
+
listeners[name].some((value, index) => {
|
|
22
|
+
if (value === listener) {
|
|
23
|
+
listeners[name].splice(index, 1);
|
|
24
|
+
return true;
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
} else {
|
|
28
|
+
delete listeners[name];
|
|
29
|
+
}
|
|
30
|
+
return this;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
export {
|
|
34
|
+
Subscriber as default
|
|
35
|
+
};
|
package/package.json
CHANGED
|
@@ -1,57 +1,57 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@vope/utils",
|
|
3
|
-
"version": "1.4.
|
|
4
|
-
"description": "",
|
|
5
|
-
"type": "module",
|
|
6
|
-
"publishConfig": {
|
|
7
|
-
"access": "public",
|
|
8
|
-
"registry": "https://registry.npmjs.org/"
|
|
9
|
-
},
|
|
10
|
-
"types": "./types/index.d.ts",
|
|
11
|
-
"typings": "./types/index.d.ts",
|
|
12
|
-
"module": "./lib/index.js",
|
|
13
|
-
"main": "./cjs/index.js",
|
|
14
|
-
"scripts": {
|
|
15
|
-
"start": "esbuild ./pre.ts --outfile=pre.cjs --format=cjs & node ./pre.cjs",
|
|
16
|
-
"prebuild": "npm run start & esbuild ./build.ts --outfile=build.cjs --format=cjs",
|
|
17
|
-
"build": "node ./build.cjs",
|
|
18
|
-
"premocha": "node ./build.cjs --type=test",
|
|
19
|
-
"mocha": "mocha __tests/**/*.js",
|
|
20
|
-
"test": "npm run mocha",
|
|
21
|
-
"prepublishOnly": "npm run build & npm run test"
|
|
22
|
-
},
|
|
23
|
-
"exports": {
|
|
24
|
-
".": {
|
|
25
|
-
"import": "./lib/index.js",
|
|
26
|
-
"require": "./cjs/index.js"
|
|
27
|
-
}
|
|
28
|
-
},
|
|
29
|
-
"author": "vope",
|
|
30
|
-
"license": "ISC",
|
|
31
|
-
"files": [
|
|
32
|
-
"cjs",
|
|
33
|
-
"lib",
|
|
34
|
-
"types"
|
|
35
|
-
],
|
|
36
|
-
"devDependencies": {
|
|
37
|
-
"@babel/parser": "^7.23.4",
|
|
38
|
-
"@babel/traverse": "^7.23.4",
|
|
39
|
-
"@babel/types": "^7.23.4",
|
|
40
|
-
"@types/babel__traverse": "^7.20.4",
|
|
41
|
-
"@types/mocha": "^10.0.6",
|
|
42
|
-
"@types/node": "^20.4.5",
|
|
43
|
-
"esbuild": "^0.19.4",
|
|
44
|
-
"glob": "^10.3.10",
|
|
45
|
-
"iconv-lite": "^0.6.3",
|
|
46
|
-
"mocha": "^10.2.0",
|
|
47
|
-
"rimraf": "^5.0.5",
|
|
48
|
-
"tslib": "^2.6.1",
|
|
49
|
-
"typescript": "^5.3.2"
|
|
50
|
-
},
|
|
51
|
-
"dependencies": {
|
|
52
|
-
"@types/lodash-es": "^4.17.9",
|
|
53
|
-
"@vope/types": "^1.0.
|
|
54
|
-
"csstype": "^3.1.3",
|
|
55
|
-
"lodash-es": "^4.17.21"
|
|
56
|
-
}
|
|
57
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@vope/utils",
|
|
3
|
+
"version": "1.4.10",
|
|
4
|
+
"description": "",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"publishConfig": {
|
|
7
|
+
"access": "public",
|
|
8
|
+
"registry": "https://registry.npmjs.org/"
|
|
9
|
+
},
|
|
10
|
+
"types": "./types/index.d.ts",
|
|
11
|
+
"typings": "./types/index.d.ts",
|
|
12
|
+
"module": "./lib/index.js",
|
|
13
|
+
"main": "./cjs/index.js",
|
|
14
|
+
"scripts": {
|
|
15
|
+
"start": "esbuild ./pre.ts --outfile=pre.cjs --format=cjs & node ./pre.cjs",
|
|
16
|
+
"prebuild": "npm run start & esbuild ./build.ts --outfile=build.cjs --format=cjs",
|
|
17
|
+
"build": "node ./build.cjs",
|
|
18
|
+
"premocha": "node ./build.cjs --type=test",
|
|
19
|
+
"mocha": "mocha __tests/**/*.js",
|
|
20
|
+
"test": "npm run mocha",
|
|
21
|
+
"prepublishOnly": "npm run build & npm run test"
|
|
22
|
+
},
|
|
23
|
+
"exports": {
|
|
24
|
+
".": {
|
|
25
|
+
"import": "./lib/index.js",
|
|
26
|
+
"require": "./cjs/index.js"
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
"author": "vope",
|
|
30
|
+
"license": "ISC",
|
|
31
|
+
"files": [
|
|
32
|
+
"cjs",
|
|
33
|
+
"lib",
|
|
34
|
+
"types"
|
|
35
|
+
],
|
|
36
|
+
"devDependencies": {
|
|
37
|
+
"@babel/parser": "^7.23.4",
|
|
38
|
+
"@babel/traverse": "^7.23.4",
|
|
39
|
+
"@babel/types": "^7.23.4",
|
|
40
|
+
"@types/babel__traverse": "^7.20.4",
|
|
41
|
+
"@types/mocha": "^10.0.6",
|
|
42
|
+
"@types/node": "^20.4.5",
|
|
43
|
+
"esbuild": "^0.19.4",
|
|
44
|
+
"glob": "^10.3.10",
|
|
45
|
+
"iconv-lite": "^0.6.3",
|
|
46
|
+
"mocha": "^10.2.0",
|
|
47
|
+
"rimraf": "^5.0.5",
|
|
48
|
+
"tslib": "^2.6.1",
|
|
49
|
+
"typescript": "^5.3.2"
|
|
50
|
+
},
|
|
51
|
+
"dependencies": {
|
|
52
|
+
"@types/lodash-es": "^4.17.9",
|
|
53
|
+
"@vope/types": "^1.0.11",
|
|
54
|
+
"csstype": "^3.1.3",
|
|
55
|
+
"lodash-es": "^4.17.21"
|
|
56
|
+
}
|
|
57
|
+
}
|
package/types/index.d.ts
CHANGED
|
@@ -21,6 +21,7 @@ export { deconPowersSum } from './power/decon';
|
|
|
21
21
|
export { rotateAngle } from './rotate/angle';
|
|
22
22
|
export { rotateRad } from './rotate/rad';
|
|
23
23
|
export { type CSSProperties, type StyleValue, css } from './style/css';
|
|
24
|
+
export { default as Subscriber } from './subscriber';
|
|
24
25
|
export { FlexTable } from './table/flex';
|
|
25
26
|
export { Union } from './union';
|
|
26
27
|
export { joinPaths } from './url/join';
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 订阅
|
|
3
|
+
*/
|
|
4
|
+
export default class Subscriber<T extends Record<string, (...args: any[]) => void>> {
|
|
5
|
+
#private;
|
|
6
|
+
$on<K extends keyof T>(name: K, listener: T[K]): this;
|
|
7
|
+
$emit<K extends keyof T>(name: K, ...args: Parameters<T[K]>): this;
|
|
8
|
+
$off<K extends keyof T>(name: K, listener?: T[K]): this;
|
|
9
|
+
}
|