@tsonic/globals 0.1.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.
Files changed (4) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +76 -0
  3. package/index.d.ts +212 -0
  4. package/package.json +30 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 tsoniclang
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,76 @@
1
+ # @tsonic/globals
2
+
3
+ Global type definitions for Tsonic.
4
+
5
+ This package provides:
6
+ 1. **Base types** required by TypeScript (Array, String, Object, Function, etc.)
7
+ 2. **Shared types** used by both modes (utility types, iterators, Promise, Symbol)
8
+
9
+ ## Usage
10
+
11
+ ### Dotnet mode (use this package alone)
12
+
13
+ ```bash
14
+ npm install @tsonic/globals
15
+ ```
16
+
17
+ ```json
18
+ {
19
+ "compilerOptions": {
20
+ "noLib": true,
21
+ "typeRoots": ["node_modules/@tsonic/globals"]
22
+ }
23
+ }
24
+ ```
25
+
26
+ Arrays use LINQ, strings use BCL methods.
27
+
28
+ ### JS mode (use with @tsonic/js-globals)
29
+
30
+ ```bash
31
+ npm install @tsonic/globals @tsonic/js-globals
32
+ ```
33
+
34
+ ```json
35
+ {
36
+ "compilerOptions": {
37
+ "noLib": true,
38
+ "typeRoots": [
39
+ "node_modules/@tsonic/globals",
40
+ "node_modules/@tsonic/js-globals"
41
+ ]
42
+ }
43
+ }
44
+ ```
45
+
46
+ Arrays have `.map`, `.filter`, `.length`, etc. Strings have `.slice`, `.indexOf`, etc.
47
+
48
+ ## What's included
49
+
50
+ ### Base types (minimal definitions)
51
+ - `Array<T>`, `ReadonlyArray<T>` - indexer and iterator only
52
+ - `String`, `Number`, `Boolean` - empty base
53
+ - `Object`, `Function` - minimal
54
+ - `RegExp`, `IArguments`, `CallableFunction`, `NewableFunction`
55
+
56
+ ### Utility types
57
+ - `Partial`, `Required`, `Readonly`, `Pick`, `Omit`
58
+ - `Record`, `Exclude`, `Extract`, `NonNullable`
59
+ - `Parameters`, `ReturnType`, `InstanceType`, `ConstructorParameters`
60
+
61
+ ### Iterator/Generator types
62
+ - `Iterator`, `IteratorResult`, `Iterable`, `IterableIterator`
63
+ - `AsyncIterator`, `AsyncIterable`, `AsyncIterableIterator`
64
+ - `Generator`, `AsyncGenerator`
65
+
66
+ ### Promise types
67
+ - `Promise`, `PromiseLike`, `PromiseConstructor`
68
+
69
+ ### Other
70
+ - `Symbol`, `SymbolConstructor`
71
+ - `PropertyKey`
72
+ - Template literal utilities: `Uppercase`, `Lowercase`, `Capitalize`, `Uncapitalize`
73
+
74
+ ## License
75
+
76
+ MIT
package/index.d.ts ADDED
@@ -0,0 +1,212 @@
1
+ /**
2
+ * @tsonic/globals
3
+ *
4
+ * Global type definitions for Tsonic.
5
+ *
6
+ * This package provides:
7
+ * 1. Base types required by TypeScript (Array, String, Object, Function, etc.)
8
+ * 2. Shared types used by both modes (utility types, iterators, Promise, Symbol)
9
+ *
10
+ * For dotnet mode: Use this package alone. Arrays use LINQ, strings use BCL.
11
+ * For JS mode: Use with @tsonic/js-globals which extends base types with JS methods.
12
+ */
13
+
14
+ declare global {
15
+ /**
16
+ * Array type - minimal base definition
17
+ * In dotnet mode, use List<T> methods or LINQ
18
+ * In JS mode, @tsonic/js-globals extends this with .map, .filter, etc.
19
+ */
20
+ interface Array<T> {
21
+ [n: number]: T;
22
+ [Symbol.iterator](): IterableIterator<T>;
23
+ }
24
+
25
+ interface ReadonlyArray<T> {
26
+ readonly [n: number]: T;
27
+ [Symbol.iterator](): IterableIterator<T>;
28
+ }
29
+
30
+ /**
31
+ * String - minimal base definition
32
+ * In dotnet mode, use System.String BCL methods
33
+ * In JS mode, @tsonic/js-globals extends this with .length, .slice, etc.
34
+ */
35
+ interface String {}
36
+
37
+ interface Number {}
38
+
39
+ interface Boolean {}
40
+
41
+ /**
42
+ * Object - minimal base definition
43
+ */
44
+ interface Object {
45
+ constructor: Function;
46
+ }
47
+
48
+ /**
49
+ * Function - minimal base definition
50
+ */
51
+ interface Function {
52
+ prototype: any;
53
+ }
54
+
55
+ /**
56
+ * Required TypeScript compiler internals
57
+ */
58
+ interface CallableFunction extends Function {}
59
+ interface NewableFunction extends Function {}
60
+ interface IArguments {}
61
+
62
+ /**
63
+ * RegExp - minimal base definition
64
+ */
65
+ interface RegExp {}
66
+
67
+ /**
68
+ * Symbol
69
+ */
70
+ interface SymbolConstructor {
71
+ readonly iterator: symbol;
72
+ readonly asyncIterator: symbol;
73
+ readonly hasInstance: symbol;
74
+ readonly isConcatSpreadable: symbol;
75
+ readonly species: symbol;
76
+ readonly toPrimitive: symbol;
77
+ readonly toStringTag: symbol;
78
+ }
79
+
80
+ const Symbol: SymbolConstructor;
81
+
82
+ /**
83
+ * PropertyKey - required for index signatures
84
+ */
85
+ type PropertyKey = string | number | symbol;
86
+
87
+ /**
88
+ * Utility types
89
+ */
90
+ type Partial<T> = { [P in keyof T]?: T[P] };
91
+ type Required<T> = { [P in keyof T]-?: T[P] };
92
+ type Readonly<T> = { readonly [P in keyof T]: T[P] };
93
+ type Pick<T, K extends keyof T> = { [P in K]: T[P] };
94
+ type Record<K extends keyof any, T> = { [P in K]: T };
95
+ type Exclude<T, U> = T extends U ? never : T;
96
+ type Extract<T, U> = T extends U ? T : never;
97
+ type Omit<T, K extends keyof any> = Pick<T, Exclude<keyof T, K>>;
98
+ type NonNullable<T> = T extends null | undefined ? never : T;
99
+ type Parameters<T extends (...args: any) => any> = T extends (...args: infer P) => any ? P : never;
100
+ type ConstructorParameters<T extends new (...args: any) => any> = T extends new (...args: infer P) => any ? P : never;
101
+ type ReturnType<T extends (...args: any) => any> = T extends (...args: any) => infer R ? R : any;
102
+ type InstanceType<T extends new (...args: any) => any> = T extends new (...args: any) => infer R ? R : any;
103
+
104
+ /**
105
+ * Promise types
106
+ */
107
+ interface Promise<T> {
108
+ then<TResult1 = T, TResult2 = never>(
109
+ onfulfilled?: ((value: T) => TResult1 | PromiseLike<TResult1>) | undefined | null,
110
+ onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | undefined | null
111
+ ): Promise<TResult1 | TResult2>;
112
+ catch<TResult = never>(
113
+ onrejected?: ((reason: any) => TResult | PromiseLike<TResult>) | undefined | null
114
+ ): Promise<T | TResult>;
115
+ finally(onfinally?: (() => void) | undefined | null): Promise<T>;
116
+ }
117
+
118
+ interface PromiseLike<T> {
119
+ then<TResult1 = T, TResult2 = never>(
120
+ onfulfilled?: ((value: T) => TResult1 | PromiseLike<TResult1>) | undefined | null,
121
+ onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | undefined | null
122
+ ): PromiseLike<TResult1 | TResult2>;
123
+ }
124
+
125
+ interface PromiseConstructor {
126
+ new <T>(executor: (resolve: (value: T | PromiseLike<T>) => void, reject: (reason?: any) => void) => void): Promise<T>;
127
+ resolve(): Promise<void>;
128
+ resolve<T>(value: T | PromiseLike<T>): Promise<T>;
129
+ reject<T = never>(reason?: any): Promise<T>;
130
+ all<T>(values: readonly (T | PromiseLike<T>)[]): Promise<T[]>;
131
+ race<T>(values: readonly (T | PromiseLike<T>)[]): Promise<T>;
132
+ }
133
+
134
+ const Promise: PromiseConstructor;
135
+
136
+ /**
137
+ * Iterator types
138
+ */
139
+ interface Iterator<T, TReturn = any, TNext = undefined> {
140
+ next(...args: [] | [TNext]): IteratorResult<T, TReturn>;
141
+ return?(value?: TReturn): IteratorResult<T, TReturn>;
142
+ throw?(e?: any): IteratorResult<T, TReturn>;
143
+ }
144
+
145
+ interface IteratorResult<T, TReturn = any> {
146
+ done: boolean;
147
+ value: T | TReturn;
148
+ }
149
+
150
+ interface IteratorYieldResult<T> {
151
+ done: false;
152
+ value: T;
153
+ }
154
+
155
+ interface IteratorReturnResult<TReturn> {
156
+ done: true;
157
+ value: TReturn;
158
+ }
159
+
160
+ interface Iterable<T, TReturn = any, TNext = undefined> {
161
+ [Symbol.iterator](): Iterator<T, TReturn, TNext>;
162
+ }
163
+
164
+ interface IterableIterator<T, TReturn = any, TNext = undefined> extends Iterator<T, TReturn, TNext> {
165
+ [Symbol.iterator](): IterableIterator<T, TReturn, TNext>;
166
+ }
167
+
168
+ /**
169
+ * Async Iterator types
170
+ */
171
+ interface AsyncIterator<T, TReturn = any, TNext = undefined> {
172
+ next(...args: [] | [TNext]): Promise<IteratorResult<T, TReturn>>;
173
+ return?(value?: TReturn | PromiseLike<TReturn>): Promise<IteratorResult<T, TReturn>>;
174
+ throw?(e?: any): Promise<IteratorResult<T, TReturn>>;
175
+ }
176
+
177
+ interface AsyncIterable<T, TReturn = any, TNext = undefined> {
178
+ [Symbol.asyncIterator](): AsyncIterator<T, TReturn, TNext>;
179
+ }
180
+
181
+ interface AsyncIterableIterator<T, TReturn = any, TNext = undefined> extends AsyncIterator<T, TReturn, TNext> {
182
+ [Symbol.asyncIterator](): AsyncIterableIterator<T, TReturn, TNext>;
183
+ }
184
+
185
+ /**
186
+ * Generator types
187
+ */
188
+ interface Generator<T = unknown, TReturn = any, TNext = unknown> extends Iterator<T, TReturn, TNext> {
189
+ next(...args: [] | [TNext]): IteratorResult<T, TReturn>;
190
+ return(value: TReturn): IteratorResult<T, TReturn>;
191
+ throw(e: any): IteratorResult<T, TReturn>;
192
+ [Symbol.iterator](): Generator<T, TReturn, TNext>;
193
+ }
194
+
195
+ interface AsyncGenerator<T = unknown, TReturn = any, TNext = unknown> extends AsyncIterator<T, TReturn, TNext> {
196
+ next(...args: [] | [TNext]): Promise<IteratorResult<T, TReturn>>;
197
+ return(value: TReturn | PromiseLike<TReturn>): Promise<IteratorResult<T, TReturn>>;
198
+ throw(e: any): Promise<IteratorResult<T, TReturn>>;
199
+ [Symbol.asyncIterator](): AsyncGenerator<T, TReturn, TNext>;
200
+ }
201
+
202
+ /**
203
+ * Template literal type utilities
204
+ */
205
+ type Uppercase<S extends string> = intrinsic;
206
+ type Lowercase<S extends string> = intrinsic;
207
+ type Capitalize<S extends string> = intrinsic;
208
+ type Uncapitalize<S extends string> = intrinsic;
209
+ }
210
+
211
+ // This export is required to make this file a module
212
+ export {};
package/package.json ADDED
@@ -0,0 +1,30 @@
1
+ {
2
+ "name": "@tsonic/globals",
3
+ "version": "0.1.0",
4
+ "description": "Shared global type definitions for Tsonic (utility types, iterators, Promise, Symbol)",
5
+ "main": "index.d.ts",
6
+ "types": "index.d.ts",
7
+ "files": [
8
+ "index.d.ts",
9
+ "README.md"
10
+ ],
11
+ "scripts": {
12
+ "typecheck": "tsc --noEmit"
13
+ },
14
+ "devDependencies": {
15
+ "typescript": "^5.0.0"
16
+ },
17
+ "keywords": [
18
+ "tsonic",
19
+ "typescript",
20
+ "types",
21
+ "globals",
22
+ "utility-types"
23
+ ],
24
+ "author": "Tsonic Team",
25
+ "license": "MIT",
26
+ "repository": {
27
+ "type": "git",
28
+ "url": "https://github.com/tsoniclang/globals.git"
29
+ }
30
+ }