singleton-pattern 1.1.2 → 1.2.2
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/dist/index.d.ts +4 -6
- package/dist/index.mjs +1 -1
- package/package.json +41 -61
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
// # from: global.d.ts
|
|
2
1
|
type Class = new (...args: any[]) => any;
|
|
3
|
-
type ProxiedClass = new (...args: any[]) => any;
|
|
4
2
|
|
|
5
3
|
interface SingletonifyOptions {
|
|
6
4
|
/**
|
|
@@ -25,7 +23,6 @@ interface SingletonifyOptions {
|
|
|
25
23
|
onlyOnce?: boolean;
|
|
26
24
|
}
|
|
27
25
|
|
|
28
|
-
// # index.d.ts
|
|
29
26
|
/**
|
|
30
27
|
* ## Usage
|
|
31
28
|
* Just wrap your class with this function to create a new class that always returns the same instance
|
|
@@ -37,13 +34,14 @@ interface SingletonifyOptions {
|
|
|
37
34
|
* ## About
|
|
38
35
|
* @package SingletonPattern
|
|
39
36
|
* @author Kasukabe Tsumugi <futami16237@gmail.com>
|
|
40
|
-
* @version 1.
|
|
37
|
+
* @version 1.2.2 (Last Update: 2026.02.13 17:55:24.162)
|
|
41
38
|
* @license MIT
|
|
42
39
|
* @link https://github.com/baendlorel/singleton-pattern
|
|
40
|
+
* @link https://baendlorel.github.io/ Welcome to my site!
|
|
43
41
|
* @description Wrap a class with proxy to make it a safe singleton constructor. Using new Class() will return the same instance.
|
|
44
|
-
* @copyright Copyright (c)
|
|
42
|
+
* @copyright Copyright (c) 2026 Kasukabe Tsumugi. All rights reserved.
|
|
45
43
|
*/
|
|
46
|
-
declare
|
|
44
|
+
declare function singletonify<T extends Class>(target: T, options?: SingletonifyOptions): T;
|
|
47
45
|
/**
|
|
48
46
|
* Retrieves the original class from the singletonified class
|
|
49
47
|
* @param singleton The singletonified class
|
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
const
|
|
1
|
+
const n=new WeakMap,t=new WeakMap;function e(e,c){const o=Object(c),r=o.changeProtoConstructor??!0,s=o.onlyOnce??!0;if(s){const n=t.get(e);if(n)return n}let a;const u=new Proxy(e,{construct:(n,t)=>(a||(a=new n(...t)),a)});return r&&(u.prototype.constructor=u),s&&(n.set(u,e),t.set(e,u)),u}const c=t=>n.get(t);export{c as getSingletonTarget,e as singletonify};
|
package/package.json
CHANGED
|
@@ -1,63 +1,43 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
"@babel/plugin-proposal-decorators": "^7.28.0",
|
|
44
|
-
"@babel/preset-env": "^7.28.3",
|
|
45
|
-
"@rollup/plugin-alias": "^5.1.1",
|
|
46
|
-
"@rollup/plugin-babel": "^6.0.4",
|
|
47
|
-
"@rollup/plugin-commonjs": "^28.0.6",
|
|
48
|
-
"@rollup/plugin-node-resolve": "^16.0.1",
|
|
49
|
-
"@rollup/plugin-replace": "^6.0.2",
|
|
50
|
-
"@rollup/plugin-terser": "^0.4.4",
|
|
51
|
-
"@rollup/plugin-typescript": "^12.1.4",
|
|
52
|
-
"@types/node": "^24.2.1",
|
|
53
|
-
"@vitest/coverage-v8": "^3.2.4",
|
|
54
|
-
"oxlint": "^1.11.2",
|
|
55
|
-
"prettier": "^3.6.2",
|
|
56
|
-
"rimraf": "^6.0.1",
|
|
57
|
-
"rollup": "^4.46.2",
|
|
58
|
-
"rollup-plugin-dts": "^6.2.1",
|
|
59
|
-
"tslib": "^2.8.1",
|
|
60
|
-
"typescript": "^5.9.2",
|
|
61
|
-
"vitest": "^3.2.4"
|
|
62
|
-
}
|
|
2
|
+
"name": "singleton-pattern",
|
|
3
|
+
"version": "1.2.2",
|
|
4
|
+
"author": {
|
|
5
|
+
"name": "Kasukabe Tsumugi",
|
|
6
|
+
"email": "futami16237@gmail.com"
|
|
7
|
+
},
|
|
8
|
+
"description": "Wrap a class with proxy to make it a safe singleton constructor. Using new Class() will return the same instance.",
|
|
9
|
+
"description_zh": "使用代理包装类以使其成为安全的单例构造函数(原型的构造函数也将被修改)。使用 new Class() 将返回相同的实例",
|
|
10
|
+
"type": "module",
|
|
11
|
+
"exports": {
|
|
12
|
+
"import": "./dist/index.mjs",
|
|
13
|
+
"default": "./dist/index.mjs",
|
|
14
|
+
"types": "./dist/index.d.ts"
|
|
15
|
+
},
|
|
16
|
+
"files": [
|
|
17
|
+
"dist"
|
|
18
|
+
],
|
|
19
|
+
"homepage": "https://github.com/baendlorel/singleton-pattern#readme",
|
|
20
|
+
"repository": {
|
|
21
|
+
"type": "git",
|
|
22
|
+
"url": "https://github.com/baendlorel/singleton-pattern"
|
|
23
|
+
},
|
|
24
|
+
"keywords": [
|
|
25
|
+
"deep",
|
|
26
|
+
"clone",
|
|
27
|
+
"reflect",
|
|
28
|
+
"property",
|
|
29
|
+
"path",
|
|
30
|
+
"object",
|
|
31
|
+
"nested",
|
|
32
|
+
"typescript",
|
|
33
|
+
"javascript"
|
|
34
|
+
],
|
|
35
|
+
"scripts": {
|
|
36
|
+
"test": "clear & vitest",
|
|
37
|
+
"lint": "oxlint .",
|
|
38
|
+
"cover": "clear & vitest --coverage",
|
|
39
|
+
"build": "rimraf dist && rollup -c"
|
|
40
|
+
},
|
|
41
|
+
"license": "MIT",
|
|
42
|
+
"devDependencies": {}
|
|
63
43
|
}
|