@cspell/cspell-performance-monitor 9.6.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Jason Dent
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,7 @@
1
+ # CSpell Performance Monitor
2
+
3
+ Package: `@cspell/cspell-performance-monitor`
4
+
5
+ This is a library of methods used to measure performance within CSpell.
6
+
7
+ It uses the standard [Performance API - Web APIs](https://developer.mozilla.org/en-US/docs/Web/API/Performance_API)
@@ -0,0 +1,18 @@
1
+ //#region src/performance.d.ts
2
+ declare function measurePerfStart(name: string): void;
3
+ declare function measurePerfEnd(name: string): void;
4
+ type DisposableFunction = (() => void) & Disposable & AsyncDisposable;
5
+ /**
6
+ * Creates performance marks and measures the time taken between them.
7
+ * @param name - name of the performance entry
8
+ * @returns a function to stop the timer.
9
+ */
10
+ declare function measurePerf(name: string): DisposableFunction;
11
+ /**
12
+ * Enable or disable performance measurements.
13
+ * @param enable - true to enable, false to disable. Default is true.
14
+ */
15
+ declare function enablePerformanceMeasurements(enable?: boolean): void;
16
+ //#endregion
17
+ export { enablePerformanceMeasurements, measurePerf, measurePerfEnd, measurePerfStart };
18
+ //# sourceMappingURL=index.d.ts.map
package/dist/index.js ADDED
@@ -0,0 +1,51 @@
1
+ //#region src/performance.ts
2
+ const symbolCSpell = Symbol.for("cspell");
3
+ const globalThisCSpell = globalThis;
4
+ function measurePerfStart(name) {
5
+ _measurePerfStart(name, isEnabledPerformanceMeasurements());
6
+ }
7
+ function measurePerfEnd(name) {
8
+ _measurePerfEnd(name, isEnabledPerformanceMeasurements());
9
+ }
10
+ function _measurePerfStart(name, enabled) {
11
+ if (!enabled) return;
12
+ performance.mark(name + "-start");
13
+ }
14
+ function _measurePerfEnd(name, enabled) {
15
+ if (!enabled) return;
16
+ performance.mark(name + "-end");
17
+ performance.measure(name, name + "-start", name + "-end");
18
+ }
19
+ /**
20
+ * Creates performance marks and measures the time taken between them.
21
+ * @param name - name of the performance entry
22
+ * @returns a function to stop the timer.
23
+ */
24
+ function measurePerf(name) {
25
+ const enabled = isEnabledPerformanceMeasurements();
26
+ _measurePerfStart(name, enabled);
27
+ return makeDisposableFunction(() => {
28
+ _measurePerfEnd(name, enabled);
29
+ });
30
+ }
31
+ function makeDisposableFunction(fn) {
32
+ const disposableFn = fn;
33
+ disposableFn[Symbol.dispose] = fn;
34
+ disposableFn[Symbol.asyncDispose] = () => (fn(), Promise.resolve());
35
+ return disposableFn;
36
+ }
37
+ /**
38
+ * Enable or disable performance measurements.
39
+ * @param enable - true to enable, false to disable. Default is true.
40
+ */
41
+ function enablePerformanceMeasurements(enable = true) {
42
+ globalThisCSpell[symbolCSpell] ??= {};
43
+ globalThisCSpell[symbolCSpell].enablePerformanceMeasurements = enable;
44
+ }
45
+ function isEnabledPerformanceMeasurements() {
46
+ return !!globalThisCSpell[symbolCSpell]?.enablePerformanceMeasurements;
47
+ }
48
+
49
+ //#endregion
50
+ export { enablePerformanceMeasurements, measurePerf, measurePerfEnd, measurePerfStart };
51
+ //# sourceMappingURL=index.js.map
package/package.json ADDED
@@ -0,0 +1,54 @@
1
+ {
2
+ "name": "@cspell/cspell-performance-monitor",
3
+ "publishConfig": {
4
+ "access": "public",
5
+ "provenance": true
6
+ },
7
+ "version": "9.6.1",
8
+ "description": "A performance monitor library for cspell.",
9
+ "keywords": [
10
+ "cspell",
11
+ "performance",
12
+ "monitoring"
13
+ ],
14
+ "author": "Jason Dent <jason@streetsidesoftware.nl>",
15
+ "homepage": "https://github.com/streetsidesoftware/cspell/tree/main/packages/cspell-performance-monitor#readme",
16
+ "license": "MIT",
17
+ "type": "module",
18
+ "sideEffects": false,
19
+ "exports": {
20
+ ".": "./dist/index.js"
21
+ },
22
+ "directories": {
23
+ "dist": "dist"
24
+ },
25
+ "typings": "dist/index.d.ts",
26
+ "files": [
27
+ "dist",
28
+ "!**/*.tsbuildInfo",
29
+ "!**/__mocks__",
30
+ "!**/*.test.*",
31
+ "!**/*.spec.*",
32
+ "!**/*.map"
33
+ ],
34
+ "scripts": {
35
+ "build": "tsdown && tsc -p .",
36
+ "watch": "tsdown --watch",
37
+ "clean": "shx rm -rf dist temp coverage \"*.tsbuildInfo\"",
38
+ "clean-build": "pnpm run clean && pnpm run build",
39
+ "coverage": "vitest run --coverage --pool=forks",
40
+ "test": "vitest run --pool=forks"
41
+ },
42
+ "repository": {
43
+ "type": "git",
44
+ "url": "https://github.com/streetsidesoftware/cspell.git",
45
+ "directory": "packages/cspell-performance-monitor"
46
+ },
47
+ "bugs": {
48
+ "url": "https://github.com/streetsidesoftware/cspell"
49
+ },
50
+ "engines": {
51
+ "node": ">=20.18"
52
+ },
53
+ "gitHead": "666fb79096d25c53af9519cad07030e7aca597e1"
54
+ }