@bun-win32/shell32 1.0.0

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/README.md ADDED
@@ -0,0 +1,60 @@
1
+ # @bun-win32/shell32
2
+
3
+ Zero-dependency, zero-overhead Win32 SHELL32 bindings for [Bun](https://bun.sh) on Windows.
4
+
5
+ ## Overview
6
+
7
+ `@bun-win32/shell32` exposes the `shell32.dll` exports using [Bun](https://bun.sh)'s FFI. It provides a single class, `Shell32`, which lazily binds native symbols on first use. You can optionally preload a subset or all symbols up-front via `Preload()`.
8
+
9
+ The bindings are strongly typed for a smooth DX in TypeScript.
10
+
11
+ ## Features
12
+
13
+ - [Bun](https://bun.sh)-first ergonomics on Windows 10/11.
14
+ - Direct FFI to `shell32.dll` (~250 bindings covering shell operations, file management, notifications, drag-and-drop, and more).
15
+ - In-source docs in `structs/Shell32.ts` with links to Microsoft Docs.
16
+ - Lazy binding on first call; optional eager preload (`Shell32.Preload()`).
17
+ - No wrapper overhead; calls map 1:1 to native APIs.
18
+ - Strongly-typed Win32 aliases (see `types/Shell32.ts`).
19
+
20
+ ## Requirements
21
+
22
+ - [Bun](https://bun.sh) runtime
23
+ - Windows 10 or later
24
+
25
+ ## Installation
26
+
27
+ ```sh
28
+ bun add @bun-win32/shell32
29
+ ```
30
+
31
+ ## Quick Start
32
+
33
+ ```ts
34
+ import Shell32 from '@bun-win32/shell32';
35
+
36
+ // Optionally bind a subset up-front
37
+ Shell32.Preload(['SHGetFolderPathW', 'IsUserAnAdmin', 'CommandLineToArgvW']);
38
+
39
+ // Check admin status
40
+ const isAdmin = Shell32.IsUserAnAdmin();
41
+ console.log('Admin:', !!isAdmin);
42
+
43
+ // Get APPDATA path (CSIDL_APPDATA = 0x001A)
44
+ const pathBuf = Buffer.alloc(520);
45
+ Shell32.SHGetFolderPathW(0n, 0x001a, 0n, 0, pathBuf.ptr);
46
+ console.log('APPDATA:', pathBuf.toString('utf16le').replace(/\0+$/, ''));
47
+ ```
48
+
49
+ ## Examples
50
+
51
+ Run the included example:
52
+
53
+ ```sh
54
+ bun run example # Admin check, folder paths, command-line parsing, recycle bin info
55
+ ```
56
+
57
+ ## Notes
58
+
59
+ - Either rely on lazy binding or call `Shell32.Preload()`.
60
+ - Windows only. Bun runtime required.
package/index.ts ADDED
@@ -0,0 +1,6 @@
1
+ import './runtime/extensions';
2
+
3
+ import Shell32 from './structs/Shell32';
4
+
5
+ export * from './types/Shell32';
6
+ export default Shell32;
package/package.json ADDED
@@ -0,0 +1,52 @@
1
+ {
2
+ "author": "Stev Peifer <stev@bell.net>",
3
+ "bugs": {
4
+ "url": "https://github.com/bun-win32/shell32/issues"
5
+ },
6
+ "description": "Zero-dependency, zero-overhead Win32 SHELL32 bindings for Bun (FFI) on Windows.",
7
+ "devDependencies": {
8
+ "@types/bun": "latest"
9
+ },
10
+ "exports": {
11
+ ".": "./index.ts"
12
+ },
13
+ "license": "MIT",
14
+ "module": "index.ts",
15
+ "name": "@bun-win32/shell32",
16
+ "peerDependencies": {
17
+ "typescript": "^5"
18
+ },
19
+ "private": false,
20
+ "homepage": "https://github.com/bun-win32/shell32#readme",
21
+ "repository": {
22
+ "type": "git",
23
+ "url": "git://github.com/bun-win32/shell32.git"
24
+ },
25
+ "type": "module",
26
+ "version": "1.0.0",
27
+ "main": "./index.ts",
28
+ "keywords": [
29
+ "bun",
30
+ "ffi",
31
+ "win32",
32
+ "windows",
33
+ "shell32",
34
+ "bindings",
35
+ "typescript",
36
+ "dll"
37
+ ],
38
+ "files": [
39
+ "index.ts",
40
+ "runtime/*.ts",
41
+ "structs/*.ts",
42
+ "types/*.ts",
43
+ "README.md"
44
+ ],
45
+ "sideEffects": false,
46
+ "engines": {
47
+ "bun": ">=1.1.0"
48
+ },
49
+ "scripts": {
50
+ "example": "bun ./example/shell32.ts"
51
+ }
52
+ }
@@ -0,0 +1,210 @@
1
+ import { type Pointer, ptr } from 'bun:ffi';
2
+
3
+ declare global {
4
+ /**
5
+ * Adds a native pointer property to all ArrayBuffer, Buffer, DataView, and TypedArray types.
6
+ *
7
+ * The `ptr` property returns a native pointer usable with Bun FFI.
8
+ *
9
+ * @example
10
+ * ```ts
11
+ * const arr = new Uint8Array([1, 2, 3]);
12
+ * nativeFunction(arr.ptr, arr.length);
13
+ * ```
14
+ */
15
+ interface ArrayBuffer {
16
+ /**
17
+ * Native pointer to ArrayBuffer memory for Bun FFI.
18
+ * @example
19
+ * ```ts
20
+ * const buf = new ArrayBuffer(8);
21
+ * nativeFunction(buf.ptr, buf.byteLength);
22
+ * ```
23
+ */
24
+ readonly ptr: Pointer;
25
+ }
26
+ interface BigInt64Array {
27
+ /**
28
+ * Native pointer to BigInt64Array memory for Bun FFI.
29
+ * @example
30
+ * ```ts
31
+ * const arr = new BigInt64Array([1n, 2n]);
32
+ * nativeFunction(arr.ptr, arr.length);
33
+ * ```
34
+ */
35
+ readonly ptr: Pointer;
36
+ }
37
+ interface BigUint64Array {
38
+ /**
39
+ * Native pointer to BigUint64Array memory for Bun FFI.
40
+ * @example
41
+ * ```ts
42
+ * const arr = new BigUint64Array([1n, 2n]);
43
+ * nativeFunction(arr.ptr, arr.length);
44
+ * ```
45
+ */
46
+ readonly ptr: Pointer;
47
+ }
48
+ interface Buffer {
49
+ /**
50
+ * Native pointer to Buffer memory for Bun FFI.
51
+ * @example
52
+ * ```ts
53
+ * const buf = Buffer.from([1, 2, 3]);
54
+ * nativeFunction(buf.ptr, buf.length);
55
+ * ```
56
+ */
57
+ readonly ptr: Pointer;
58
+ }
59
+ interface DataView {
60
+ /**
61
+ * Native pointer to DataView memory for Bun FFI.
62
+ * @example
63
+ * ```ts
64
+ * const view = new DataView(new ArrayBuffer(4));
65
+ * nativeFunction(view.ptr, view.byteLength);
66
+ * ```
67
+ */
68
+ readonly ptr: Pointer;
69
+ }
70
+ interface Float32Array {
71
+ /**
72
+ * Native pointer to Float32Array memory for Bun FFI.
73
+ * @example
74
+ * ```ts
75
+ * const arr = new Float32Array([1, 2, 3]);
76
+ * nativeFunction(arr.ptr, arr.length);
77
+ * ```
78
+ */
79
+ readonly ptr: Pointer;
80
+ }
81
+ interface Float64Array {
82
+ /**
83
+ * Native pointer to Float64Array memory for Bun FFI.
84
+ * @example
85
+ * ```ts
86
+ * const arr = new Float64Array([1, 2, 3]);
87
+ * nativeFunction(arr.ptr, arr.length);
88
+ * ```
89
+ */
90
+ readonly ptr: Pointer;
91
+ }
92
+ interface Int16Array {
93
+ /**
94
+ * Native pointer to Int16Array memory for Bun FFI.
95
+ * @example
96
+ * ```ts
97
+ * const arr = new Int16Array([1, 2, 3]);
98
+ * nativeFunction(arr.ptr, arr.length);
99
+ * ```
100
+ */
101
+ readonly ptr: Pointer;
102
+ }
103
+ interface Int32Array {
104
+ /**
105
+ * Native pointer to Int32Array memory for Bun FFI.
106
+ * @example
107
+ * ```ts
108
+ * const arr = new Int32Array([1, 2, 3]);
109
+ * nativeFunction(arr.ptr, arr.length);
110
+ * ```
111
+ */
112
+ readonly ptr: Pointer;
113
+ }
114
+ interface Int8Array {
115
+ /**
116
+ * Native pointer to Int8Array memory for Bun FFI.
117
+ * @example
118
+ * ```ts
119
+ * const arr = new Int8Array([1, 2, 3]);
120
+ * nativeFunction(arr.ptr, arr.length);
121
+ * ```
122
+ */
123
+ readonly ptr: Pointer;
124
+ }
125
+ interface SharedArrayBuffer {
126
+ /**
127
+ * Native pointer to SharedArrayBuffer memory for Bun FFI.
128
+ * @example
129
+ * ```ts
130
+ * const buf = new SharedArrayBuffer(8);
131
+ * nativeFunction(buf.ptr, buf.byteLength);
132
+ * ```
133
+ */
134
+ readonly ptr: Pointer;
135
+ }
136
+ interface Uint16Array {
137
+ /**
138
+ * Native pointer to Uint16Array memory for Bun FFI.
139
+ * @example
140
+ * ```ts
141
+ * const arr = new Uint16Array([1, 2, 3]);
142
+ * nativeFunction(arr.ptr, arr.length);
143
+ * ```
144
+ */
145
+ readonly ptr: Pointer;
146
+ }
147
+ interface Uint32Array {
148
+ /**
149
+ * Native pointer to Uint32Array memory for Bun FFI.
150
+ * @example
151
+ * ```ts
152
+ * const arr = new Uint32Array([1, 2, 3]);
153
+ * nativeFunction(arr.ptr, arr.length);
154
+ * ```
155
+ */
156
+ readonly ptr: Pointer;
157
+ }
158
+ interface Uint8Array {
159
+ /**
160
+ * Native pointer to Uint8Array memory for Bun FFI.
161
+ * @example
162
+ * ```ts
163
+ * const arr = new Uint8Array([1, 2, 3]);
164
+ * nativeFunction(arr.ptr, arr.length);
165
+ * ```
166
+ */
167
+ readonly ptr: Pointer;
168
+ }
169
+ interface Uint8ClampedArray {
170
+ /**
171
+ * Native pointer to Uint8ClampedArray memory for Bun FFI.
172
+ * @example
173
+ * ```ts
174
+ * const arr = new Uint8ClampedArray([1, 2, 3]);
175
+ * nativeFunction(arr.ptr, arr.length);
176
+ * ```
177
+ */
178
+ readonly ptr: Pointer;
179
+ }
180
+ }
181
+
182
+ /**
183
+ * Installs the `ptr` property on all supported binary view prototypes.
184
+ *
185
+ * The property is non-enumerable and non-configurable. The getter calls `ptr(this)`.
186
+ */
187
+ const constructors = [ArrayBuffer, BigInt64Array, BigUint64Array, Buffer, DataView, Float32Array, Float64Array, Int16Array, Int32Array, Int8Array, SharedArrayBuffer, Uint16Array, Uint32Array, Uint8Array, Uint8ClampedArray] as const;
188
+
189
+ constructors.forEach(
190
+ ({ prototype }) =>
191
+ !Object.getOwnPropertyDescriptor(prototype, 'ptr') &&
192
+ Object.defineProperty(prototype, 'ptr', {
193
+ configurable: false,
194
+ enumerable: false,
195
+ /**
196
+ * Returns a native pointer to the underlying memory.
197
+ * @returns Native pointer for Bun FFI.
198
+ * @example
199
+ * ```ts
200
+ * const arr = new Uint8Array([1, 2, 3]);
201
+ * nativeFunction(arr.ptr, arr.length);
202
+ * ```
203
+ */
204
+ get(this): Pointer {
205
+ return ptr(this);
206
+ },
207
+ })
208
+ );
209
+
210
+ export {};