ktfile 1.2.0 → 1.2.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/CONTRIBUTING.md CHANGED
@@ -1,291 +1,291 @@
1
- # Contributing to KTFile
2
-
3
- Thank you for your interest in contributing to KTFile! This document provides guidelines and information for
4
- contributors.
5
-
6
- ## Table of Contents
7
-
8
- - [Getting Started](#getting-started)
9
- - [Development Setup](#development-setup)
10
- - [Project Structure](#project-structure)
11
- - [Development Workflow](#development-workflow)
12
- - [Code Style Guidelines](#code-style-guidelines)
13
- - [Testing](#testing)
14
- - [Submitting Changes](#submitting-changes)
15
-
16
- ## Getting Started
17
-
18
- ### Prerequisites
19
-
20
- - Node.js (version 14 or higher recommended)
21
- - npm or yarn package manager
22
- - Git
23
-
24
- ### Fork and Clone
25
-
26
- 1. Fork the repository on GitHub
27
- 2. Clone your fork locally:
28
- ```bash
29
- git clone https://github.com/YOUR_USERNAME/ktfile.git
30
- cd ktfile
31
- ```
32
- 3. Add the original repository as upstream:
33
- ```bash
34
- git remote add upstream https://github.com/OguzhanUmutlu/ktfile.git
35
- ```
36
-
37
- ## Development Setup
38
-
39
- 1. Install dependencies:
40
- ```bash
41
- npm install
42
- ```
43
-
44
- 2. Build the project:
45
- ```bash
46
- npm run build
47
- ```
48
-
49
- 3. Run tests:
50
- ```bash
51
- npm test
52
- ```
53
-
54
- ## Project Structure
55
-
56
- ```
57
- ktfile/
58
- ├── src/ # TypeScript source files
59
- │ ├── async/ # Async file system implementations
60
- │ │ ├── FileAsync.ts # Main async file class
61
- │ │ └── IAsyncFS.ts # Async file system interface
62
- │ ├── sync/ # Sync file system implementations
63
- │ │ ├── FileSync.ts # Main sync file class
64
- │ │ └── ISyncFS.ts # Sync file system interface
65
- │ ├── IFile.ts # Base file interface
66
- │ ├── Utils.ts # Utility functions
67
- │ └── ktfile.ts # Main entry point
68
- ├── types/ # Generated TypeScript declarations
69
- ├── dist/ # Compiled JavaScript output
70
- ├── tests/ # Test files
71
- │ ├── test.ts # Main test suite
72
- │ ├── test.html # Browser tests
73
- │ └── clean.js # Test cleanup utility
74
- ├── rollup.config.mjs # Build configuration
75
- ├── tsconfig.json # TypeScript configuration
76
- ├── index.min.js # Minified distribution file
77
- └── package.json # Project metadata
78
- ```
79
-
80
- ### Key Files
81
-
82
- - **`src/ktfile.ts`**: Main entry point, exports public API
83
- - **`src/sync/FileSync.ts`**: Synchronous file operations implementation
84
- - **`src/async/FileAsync.ts`**: Asynchronous file operations implementation
85
- - **`src/IFile.ts`**: Base interface shared by both sync and async implementations
86
- - **`src/Utils.ts`**: Shared utility functions
87
-
88
- ## Development Workflow
89
-
90
- ### Branch Strategy
91
-
92
- 1. Create a feature branch from `main`:
93
- ```bash
94
- git checkout -b feature/your-feature-name
95
- ```
96
-
97
- 2. Make your changes and commit them with descriptive messages
98
-
99
- 3. Keep your branch up to date with upstream:
100
- ```bash
101
- git fetch upstream
102
- git rebase upstream/main
103
- ```
104
-
105
- 4. Push your branch and create a pull request
106
-
107
- ### Building
108
-
109
- The project uses Rollup for building. Available scripts:
110
-
111
- ```bash
112
- npm run build # Build TypeScript and create distributions
113
- npm run build:types # Generate type declarations only
114
- npm run dev # Watch mode for development
115
- ```
116
-
117
- ### File System Abstractions
118
-
119
- KTFile uses interface-based abstractions to support different environments:
120
-
121
- - **`ISyncFS`**: Interface for synchronous file system operations
122
- - **`IAsyncFS`**: Interface for asynchronous file system operations
123
-
124
- When adding new functionality:
125
-
126
- 1. Add the method signature to the appropriate interface
127
- 2. Implement it in both sync and async file classes
128
- 3. Ensure cross-platform compatibility
129
-
130
- ## Code Style Guidelines
131
-
132
- ### TypeScript Standards
133
-
134
- - Use TypeScript strict mode
135
- - Provide explicit type annotations for public APIs
136
- - Use meaningful variable and function names
137
- - Follow existing naming conventions:
138
- - Classes: `PascalCase`
139
- - Methods/properties: `camelCase`
140
- - Constants: `UPPER_SNAKE_CASE`
141
-
142
- ### Code Formatting
143
-
144
- - Use 4 spaces for indentation
145
- - Use semicolons
146
- - Use double quotes for strings
147
- - Maximum line length: 120 characters
148
-
149
- ### Error Handling
150
-
151
- - Methods should return `null` on failure rather than throwing exceptions
152
- - Use `| null` return types for operations that can fail
153
- - Document when methods can return `null` and why
154
-
155
- ### Example Code Style
156
-
157
- ```typescript
158
- export class FileSync extends IFile<ISyncFS> {
159
- /**
160
- * Reads file content as string or Buffer
161
- * @param encoding Optional text encoding
162
- * @returns File content or null if read fails
163
- */
164
- read(encoding?: BufferEncoding): string | null;
165
- read(): Buffer | null;
166
- read(encoding?: BufferEncoding): string | Buffer | null {
167
- try {
168
- // Implementation here
169
- return this.fs.readFileSync(this.path, encoding);
170
- } catch {
171
- return null;
172
- }
173
- }
174
- }
175
- ```
176
-
177
- ## Testing
178
-
179
- ### Running Tests
180
-
181
- ```bash
182
- npm test # Run all tests
183
- npm run test:node # Run Node.js tests only
184
- npm run test:browser # Run browser tests only
185
- ```
186
-
187
- ### Test Structure
188
-
189
- - Tests are located in the `tests/` directory
190
- - Main test suite: `tests/test.ts`
191
- - Browser compatibility tests: `tests/test.html`
192
- - Test cleanup utility: `tests/clean.js`
193
-
194
- ### Writing Tests
195
-
196
- When adding new features:
197
-
198
- 1. Add tests for both sync and async implementations
199
- 2. Test error conditions (methods returning `null`)
200
- 3. Test cross-platform behavior where applicable
201
- 4. Include edge cases and boundary conditions
202
-
203
- Example test pattern:
204
-
205
- ```typescript
206
- // Test successful operation
207
- const file = fileSync('./test-file.txt');
208
- file.write('test content');
209
- assert.strictEqual(file.read(), 'test content');
210
-
211
- // Test error condition
212
- const nonexistent = fileSync('./nonexistent.txt');
213
- assert.strictEqual(nonexistent.read(), null);
214
-
215
- // Test async equivalent
216
- const asyncFile = fileAsync('./test-file.txt');
217
- await asyncFile.write('test content');
218
- assert.strictEqual(await asyncFile.read(), 'test content');
219
- ```
220
-
221
- ## Submitting Changes
222
-
223
- ### Pull Request Guidelines
224
-
225
- 1. **Clear Title**: Use a descriptive title that summarizes the change
226
- 2. **Description**: Include:
227
- - What the change does
228
- - Why it's needed
229
- - Any breaking changes
230
- - Testing performed
231
-
232
- 3. **Code Quality**:
233
- - Ensure all tests pass
234
- - Follow coding standards
235
- - Update documentation if needed
236
- - Add tests for new functionality
237
-
238
- 4. **Commit Messages**:
239
- - Use clear, descriptive commit messages
240
- - Reference issue numbers when applicable
241
- - Use imperative mood: "Add feature" not "Added feature"
242
-
243
- ### Pull Request Template
244
-
245
- ```markdown
246
- ## Description
247
-
248
- Brief description of changes
249
-
250
- ## Type of Change
251
-
252
- - [ ] Bug fix
253
- - [ ] New feature
254
- - [ ] Breaking change
255
- - [ ] Documentation update
256
-
257
- ## Testing
258
-
259
- - [ ] Tests pass locally
260
- - [ ] Added tests for new functionality
261
- - [ ] Tested on multiple platforms (if applicable)
262
-
263
- ## Checklist
264
-
265
- - [ ] Code follows project style guidelines
266
- - [ ] Self-review completed
267
- - [ ] Documentation updated (if needed)
268
- - [ ] No breaking changes (or breaking changes documented)
269
- ```
270
-
271
- ## Debugging
272
-
273
- - Test both sync and async implementations
274
- - Verify behavior in both Node.js and browser environments
275
-
276
- ## Getting Help
277
-
278
- - **Documentation**: Check the README and inline code documentation
279
- - **Issues**: Search existing issues for similar problems
280
- - **Discussions**: Use GitHub Discussions for questions and ideas
281
- - **Contact**: Reach out to maintainers through GitHub
282
-
283
- ## Recognition
284
-
285
- Contributors will be recognized in:
286
-
287
- - GitHub contributors list
288
- - Release notes (for significant contributions)
289
- - Documentation acknowledgments
290
-
1
+ # Contributing to KTFile
2
+
3
+ Thank you for your interest in contributing to KTFile! This document provides guidelines and information for
4
+ contributors.
5
+
6
+ ## Table of Contents
7
+
8
+ - [Getting Started](#getting-started)
9
+ - [Development Setup](#development-setup)
10
+ - [Project Structure](#project-structure)
11
+ - [Development Workflow](#development-workflow)
12
+ - [Code Style Guidelines](#code-style-guidelines)
13
+ - [Testing](#testing)
14
+ - [Submitting Changes](#submitting-changes)
15
+
16
+ ## Getting Started
17
+
18
+ ### Prerequisites
19
+
20
+ - Node.js (version 14 or higher recommended)
21
+ - npm or yarn package manager
22
+ - Git
23
+
24
+ ### Fork and Clone
25
+
26
+ 1. Fork the repository on GitHub
27
+ 2. Clone your fork locally:
28
+ ```bash
29
+ git clone https://github.com/YOUR_USERNAME/ktfile.git
30
+ cd ktfile
31
+ ```
32
+ 3. Add the original repository as upstream:
33
+ ```bash
34
+ git remote add upstream https://github.com/OguzhanUmutlu/ktfile.git
35
+ ```
36
+
37
+ ## Development Setup
38
+
39
+ 1. Install dependencies:
40
+ ```bash
41
+ npm install
42
+ ```
43
+
44
+ 2. Build the project:
45
+ ```bash
46
+ npm run build
47
+ ```
48
+
49
+ 3. Run tests:
50
+ ```bash
51
+ npm test
52
+ ```
53
+
54
+ ## Project Structure
55
+
56
+ ```
57
+ ktfile/
58
+ ├── src/ # TypeScript source files
59
+ │ ├── async/ # Async file system implementations
60
+ │ │ ├── FileAsync.ts # Main async file class
61
+ │ │ └── IAsyncFS.ts # Async file system interface
62
+ │ ├── sync/ # Sync file system implementations
63
+ │ │ ├── FileSync.ts # Main sync file class
64
+ │ │ └── ISyncFS.ts # Sync file system interface
65
+ │ ├── IFile.ts # Base file interface
66
+ │ ├── Utils.ts # Utility functions
67
+ │ └── ktfile.ts # Main entry point
68
+ ├── types/ # Generated TypeScript declarations
69
+ ├── dist/ # Compiled JavaScript output
70
+ ├── tests/ # Test files
71
+ │ ├── test.ts # Main test suite
72
+ │ ├── test.html # Browser tests
73
+ │ └── clean.js # Test cleanup utility
74
+ ├── rollup.config.mjs # Build configuration
75
+ ├── tsconfig.json # TypeScript configuration
76
+ ├── index.min.js # Minified distribution file
77
+ └── package.json # Project metadata
78
+ ```
79
+
80
+ ### Key Files
81
+
82
+ - **`src/ktfile.ts`**: Main entry point, exports public API
83
+ - **`src/sync/FileSync.ts`**: Synchronous file operations implementation
84
+ - **`src/async/FileAsync.ts`**: Asynchronous file operations implementation
85
+ - **`src/IFile.ts`**: Base interface shared by both sync and async implementations
86
+ - **`src/Utils.ts`**: Shared utility functions
87
+
88
+ ## Development Workflow
89
+
90
+ ### Branch Strategy
91
+
92
+ 1. Create a feature branch from `main`:
93
+ ```bash
94
+ git checkout -b feature/your-feature-name
95
+ ```
96
+
97
+ 2. Make your changes and commit them with descriptive messages
98
+
99
+ 3. Keep your branch up to date with upstream:
100
+ ```bash
101
+ git fetch upstream
102
+ git rebase upstream/main
103
+ ```
104
+
105
+ 4. Push your branch and create a pull request
106
+
107
+ ### Building
108
+
109
+ The project uses Rollup for building. Available scripts:
110
+
111
+ ```bash
112
+ npm run build # Build TypeScript and create distributions
113
+ npm run build:types # Generate type declarations only
114
+ npm run dev # Watch mode for development
115
+ ```
116
+
117
+ ### File System Abstractions
118
+
119
+ KTFile uses interface-based abstractions to support different environments:
120
+
121
+ - **`ISyncFS`**: Interface for synchronous file system operations
122
+ - **`IAsyncFS`**: Interface for asynchronous file system operations
123
+
124
+ When adding new functionality:
125
+
126
+ 1. Add the method signature to the appropriate interface
127
+ 2. Implement it in both sync and async file classes
128
+ 3. Ensure cross-platform compatibility
129
+
130
+ ## Code Style Guidelines
131
+
132
+ ### TypeScript Standards
133
+
134
+ - Use TypeScript strict mode
135
+ - Provide explicit type annotations for public APIs
136
+ - Use meaningful variable and function names
137
+ - Follow existing naming conventions:
138
+ - Classes: `PascalCase`
139
+ - Methods/properties: `camelCase`
140
+ - Constants: `UPPER_SNAKE_CASE`
141
+
142
+ ### Code Formatting
143
+
144
+ - Use 4 spaces for indentation
145
+ - Use semicolons
146
+ - Use double quotes for strings
147
+ - Maximum line length: 120 characters
148
+
149
+ ### Error Handling
150
+
151
+ - Methods should return `null` on failure rather than throwing exceptions
152
+ - Use `| null` return types for operations that can fail
153
+ - Document when methods can return `null` and why
154
+
155
+ ### Example Code Style
156
+
157
+ ```typescript
158
+ export class FileSync extends IFile<ISyncFS> {
159
+ /**
160
+ * Reads file content as string or Buffer
161
+ * @param encoding Optional text encoding
162
+ * @returns File content or null if read fails
163
+ */
164
+ read(encoding?: BufferEncoding): string | null;
165
+ read(): Buffer | null;
166
+ read(encoding?: BufferEncoding): string | Buffer | null {
167
+ try {
168
+ // Implementation here
169
+ return this.fs.readFileSync(this.path, encoding);
170
+ } catch {
171
+ return null;
172
+ }
173
+ }
174
+ }
175
+ ```
176
+
177
+ ## Testing
178
+
179
+ ### Running Tests
180
+
181
+ ```bash
182
+ npm test # Run all tests
183
+ npm run test:node # Run Node.js tests only
184
+ npm run test:browser # Run browser tests only
185
+ ```
186
+
187
+ ### Test Structure
188
+
189
+ - Tests are located in the `tests/` directory
190
+ - Main test suite: `tests/test.ts`
191
+ - Browser compatibility tests: `tests/test.html`
192
+ - Test cleanup utility: `tests/clean.js`
193
+
194
+ ### Writing Tests
195
+
196
+ When adding new features:
197
+
198
+ 1. Add tests for both sync and async implementations
199
+ 2. Test error conditions (methods returning `null`)
200
+ 3. Test cross-platform behavior where applicable
201
+ 4. Include edge cases and boundary conditions
202
+
203
+ Example test pattern:
204
+
205
+ ```typescript
206
+ // Test successful operation
207
+ const file = fileSync('./test-file.txt');
208
+ file.write('test content');
209
+ assert.strictEqual(file.read(), 'test content');
210
+
211
+ // Test error condition
212
+ const nonexistent = fileSync('./nonexistent.txt');
213
+ assert.strictEqual(nonexistent.read(), null);
214
+
215
+ // Test async equivalent
216
+ const asyncFile = fileAsync('./test-file.txt');
217
+ await asyncFile.write('test content');
218
+ assert.strictEqual(await asyncFile.read(), 'test content');
219
+ ```
220
+
221
+ ## Submitting Changes
222
+
223
+ ### Pull Request Guidelines
224
+
225
+ 1. **Clear Title**: Use a descriptive title that summarizes the change
226
+ 2. **Description**: Include:
227
+ - What the change does
228
+ - Why it's needed
229
+ - Any breaking changes
230
+ - Testing performed
231
+
232
+ 3. **Code Quality**:
233
+ - Ensure all tests pass
234
+ - Follow coding standards
235
+ - Update documentation if needed
236
+ - Add tests for new functionality
237
+
238
+ 4. **Commit Messages**:
239
+ - Use clear, descriptive commit messages
240
+ - Reference issue numbers when applicable
241
+ - Use imperative mood: "Add feature" not "Added feature"
242
+
243
+ ### Pull Request Template
244
+
245
+ ```markdown
246
+ ## Description
247
+
248
+ Brief description of changes
249
+
250
+ ## Type of Change
251
+
252
+ - [ ] Bug fix
253
+ - [ ] New feature
254
+ - [ ] Breaking change
255
+ - [ ] Documentation update
256
+
257
+ ## Testing
258
+
259
+ - [ ] Tests pass locally
260
+ - [ ] Added tests for new functionality
261
+ - [ ] Tested on multiple platforms (if applicable)
262
+
263
+ ## Checklist
264
+
265
+ - [ ] Code follows project style guidelines
266
+ - [ ] Self-review completed
267
+ - [ ] Documentation updated (if needed)
268
+ - [ ] No breaking changes (or breaking changes documented)
269
+ ```
270
+
271
+ ## Debugging
272
+
273
+ - Test both sync and async implementations
274
+ - Verify behavior in both Node.js and browser environments
275
+
276
+ ## Getting Help
277
+
278
+ - **Documentation**: Check the README and inline code documentation
279
+ - **Issues**: Search existing issues for similar problems
280
+ - **Discussions**: Use GitHub Discussions for questions and ideas
281
+ - **Contact**: Reach out to maintainers through GitHub
282
+
283
+ ## Recognition
284
+
285
+ Contributors will be recognized in:
286
+
287
+ - GitHub contributors list
288
+ - Release notes (for significant contributions)
289
+ - Documentation acknowledgments
290
+
291
291
  Thank you for contributing to KTFile! 🎉
package/LICENSE CHANGED
@@ -1,21 +1,21 @@
1
- MIT License
2
-
3
- Copyright (c) 2025 Oğuzhan
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.
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Oğuzhan
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.