ts-serializable 4.5.3 → 4.5.4
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/CHANGELOG.md +10 -0
- package/README.md +35 -35
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,16 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
|
|
5
|
+
## [4.5.4] - 2025-12-14
|
|
6
|
+
|
|
7
|
+
### 📚 Documentation
|
|
8
|
+
|
|
9
|
+
- *(README)* Remove emojis from section headers for consistency
|
|
10
|
+
|
|
11
|
+
# Changelog
|
|
12
|
+
|
|
13
|
+
All notable changes to this project will be documented in this file.
|
|
14
|
+
|
|
5
15
|
## [4.5.3] - 2025-12-13
|
|
6
16
|
|
|
7
17
|
### 🚜 Refactor
|
package/README.md
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
|
|
9
9
|
Powerful and flexible TypeScript/JavaScript library for serialization and deserialization with decorators
|
|
10
10
|
|
|
11
|
-
##
|
|
11
|
+
## Features
|
|
12
12
|
|
|
13
13
|
- 🎯 **Type-safe** - Convert JSON to strongly-typed class instances
|
|
14
14
|
- 🎨 **Decorator-based** - Clean and intuitive API using TypeScript decorators
|
|
@@ -19,49 +19,49 @@ Powerful and flexible TypeScript/JavaScript library for serialization and deseri
|
|
|
19
19
|
- 📝 **FormData Support** - Built-in conversion to FormData for file uploads
|
|
20
20
|
- ⚡ **Lightweight** - Minimal dependencies and small bundle size
|
|
21
21
|
|
|
22
|
-
##
|
|
22
|
+
## Table of Contents
|
|
23
23
|
|
|
24
24
|
- [ts-serializable](#ts-serializable)
|
|
25
|
-
- [
|
|
26
|
-
- [
|
|
27
|
-
- [
|
|
28
|
-
- [
|
|
25
|
+
- [Features](#features)
|
|
26
|
+
- [Table of Contents](#table-of-contents)
|
|
27
|
+
- [Installation](#installation)
|
|
28
|
+
- [Quick Start](#quick-start)
|
|
29
29
|
- [Why Use ts-serializable?](#why-use-ts-serializable)
|
|
30
|
-
- [
|
|
30
|
+
- [Core Concepts](#core-concepts)
|
|
31
31
|
- [Type Safety](#type-safety)
|
|
32
32
|
- [Default Values](#default-values)
|
|
33
33
|
- [Error Handling](#error-handling)
|
|
34
|
-
- [
|
|
34
|
+
- [Decorators](#decorators)
|
|
35
35
|
- [@jsonProperty](#jsonproperty)
|
|
36
36
|
- [@jsonIgnore](#jsonignore)
|
|
37
37
|
- [@jsonName](#jsonname)
|
|
38
38
|
- [@jsonObject](#jsonobject)
|
|
39
|
-
- [
|
|
40
|
-
- [
|
|
41
|
-
- [
|
|
42
|
-
- [
|
|
43
|
-
- [
|
|
44
|
-
- [
|
|
39
|
+
- [Advanced Usage](#advanced-usage)
|
|
40
|
+
- [Standalone Functions](#standalone-functions)
|
|
41
|
+
- [Naming Strategies](#naming-strategies)
|
|
42
|
+
- [Configuration Settings](#configuration-settings)
|
|
43
|
+
- [View Models and DTOs](#view-models-and-dtos)
|
|
44
|
+
- [FormData Conversion](#formdata-conversion)
|
|
45
45
|
- [Basic Usage](#basic-usage)
|
|
46
46
|
- [Complex Object Graphs](#complex-object-graphs)
|
|
47
47
|
- [With Custom Prefix](#with-custom-prefix)
|
|
48
48
|
- [Appending to Existing FormData](#appending-to-existing-formdata)
|
|
49
49
|
- [Special Type Handling](#special-type-handling)
|
|
50
|
-
- [
|
|
50
|
+
- [Additional Features](#additional-features)
|
|
51
51
|
- [Deep Copy](#deep-copy)
|
|
52
52
|
- [Nested Objects](#nested-objects)
|
|
53
53
|
- [Arrays of Objects](#arrays-of-objects)
|
|
54
|
-
- [
|
|
54
|
+
- [API Reference](#api-reference)
|
|
55
55
|
- [Serializable Class Methods](#serializable-class-methods)
|
|
56
56
|
- [Static Methods](#static-methods)
|
|
57
57
|
- [Instance Methods](#instance-methods)
|
|
58
|
-
- [Standalone Functions](#standalone-functions)
|
|
58
|
+
- [Standalone Functions](#standalone-functions-1)
|
|
59
59
|
- [Available Naming Strategies](#available-naming-strategies)
|
|
60
|
-
- [
|
|
61
|
-
- [
|
|
62
|
-
- [
|
|
60
|
+
- [Contributing](#contributing)
|
|
61
|
+
- [License](#license)
|
|
62
|
+
- [Acknowledgments](#acknowledgments)
|
|
63
63
|
|
|
64
|
-
##
|
|
64
|
+
## Installation
|
|
65
65
|
|
|
66
66
|
```bash
|
|
67
67
|
npm install ts-serializable reflect-metadata
|
|
@@ -74,7 +74,7 @@ npm install ts-serializable reflect-metadata
|
|
|
74
74
|
import "reflect-metadata";
|
|
75
75
|
```
|
|
76
76
|
|
|
77
|
-
##
|
|
77
|
+
## Quick Start
|
|
78
78
|
|
|
79
79
|
Here's a simple example to get you started:
|
|
80
80
|
|
|
@@ -124,7 +124,7 @@ const user: User = User.fromJSON(jsonString);
|
|
|
124
124
|
user.getFullName(); // ✅ Works perfectly and returns a string
|
|
125
125
|
```
|
|
126
126
|
|
|
127
|
-
##
|
|
127
|
+
## Core Concepts
|
|
128
128
|
|
|
129
129
|
### Type Safety
|
|
130
130
|
|
|
@@ -162,7 +162,7 @@ class StrictUser extends Serializable {
|
|
|
162
162
|
}
|
|
163
163
|
```
|
|
164
164
|
|
|
165
|
-
##
|
|
165
|
+
## Decorators
|
|
166
166
|
|
|
167
167
|
### @jsonProperty
|
|
168
168
|
|
|
@@ -252,7 +252,7 @@ class User extends Serializable {
|
|
|
252
252
|
}
|
|
253
253
|
```
|
|
254
254
|
|
|
255
|
-
##
|
|
255
|
+
## Advanced Usage
|
|
256
256
|
|
|
257
257
|
This example is written in TypeScript, but it also works in JavaScript (without type annotations).
|
|
258
258
|
|
|
@@ -320,7 +320,7 @@ user.getFullName(); // works fine and returns a string
|
|
|
320
320
|
user.getAge(); // works fine and returns a number
|
|
321
321
|
```
|
|
322
322
|
|
|
323
|
-
##
|
|
323
|
+
## Standalone Functions
|
|
324
324
|
|
|
325
325
|
The library provides standalone utility functions `fromJSON` and `toJSON` that can be used with any objects, not just classes that extend `Serializable`. This is useful when you want to use the serialization features without inheritance.
|
|
326
326
|
|
|
@@ -486,7 +486,7 @@ console.log(jsonToSend);
|
|
|
486
486
|
// }
|
|
487
487
|
```
|
|
488
488
|
|
|
489
|
-
##
|
|
489
|
+
## Naming Strategies
|
|
490
490
|
|
|
491
491
|
The library supports automatic conversion between different naming conventions, making it easy to work with APIs that use different naming styles. Supported strategies include:
|
|
492
492
|
|
|
@@ -531,7 +531,7 @@ user.dateOfBirth?.toISOString() === json.date_of_birth; // true
|
|
|
531
531
|
user.veryStrangePropertyName === json["very::strange::json:name"]; // true
|
|
532
532
|
```
|
|
533
533
|
|
|
534
|
-
##
|
|
534
|
+
## Configuration Settings
|
|
535
535
|
|
|
536
536
|
You can customize serialization behavior at three levels:
|
|
537
537
|
|
|
@@ -557,7 +557,7 @@ Supported settings:
|
|
|
557
557
|
- **defaultValueHandling**, enum, default Ignore - ...coming soon.
|
|
558
558
|
- **logLevel**, enum, default Warning - ...coming soon.
|
|
559
559
|
|
|
560
|
-
##
|
|
560
|
+
## View Models and DTOs
|
|
561
561
|
|
|
562
562
|
If you need to create view-models from DTO or entity models, you can add view-specific properties and mark them with `@jsonIgnore()` to exclude them from serialization.
|
|
563
563
|
|
|
@@ -583,7 +583,7 @@ JSON.stringify(user);
|
|
|
583
583
|
// Result: {"firstName":"","familyName":""}
|
|
584
584
|
```
|
|
585
585
|
|
|
586
|
-
##
|
|
586
|
+
## FormData Conversion
|
|
587
587
|
|
|
588
588
|
When working with file uploads, converting files to JSON (base64) can freeze the UI for large files. The library provides built-in FormData conversion as a more efficient alternative.
|
|
589
589
|
|
|
@@ -774,7 +774,7 @@ The FormData conversion handles different types intelligently:
|
|
|
774
774
|
|
|
775
775
|
**Note:** All decorators (`@jsonIgnore`, `@jsonName`, naming strategies) are respected during FormData conversion.
|
|
776
776
|
|
|
777
|
-
##
|
|
777
|
+
## Additional Features
|
|
778
778
|
|
|
779
779
|
### Deep Copy
|
|
780
780
|
|
|
@@ -845,7 +845,7 @@ const team = Team.fromJSON(json);
|
|
|
845
845
|
console.log(team.members[0] instanceof User); // true
|
|
846
846
|
```
|
|
847
847
|
|
|
848
|
-
##
|
|
848
|
+
## API Reference
|
|
849
849
|
|
|
850
850
|
### Serializable Class Methods
|
|
851
851
|
|
|
@@ -919,14 +919,14 @@ console.log(team.members[0] instanceof User); // true
|
|
|
919
919
|
- `PascalCaseNamingStrategy` - Converts to PascalCase
|
|
920
920
|
- `KebabCaseNamingStrategy` - Converts to kebab-case
|
|
921
921
|
|
|
922
|
-
##
|
|
922
|
+
## Contributing
|
|
923
923
|
|
|
924
924
|
Contributions are welcome! Please feel free to submit a Pull Request.
|
|
925
925
|
|
|
926
|
-
##
|
|
926
|
+
## License
|
|
927
927
|
|
|
928
928
|
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
|
|
929
929
|
|
|
930
|
-
##
|
|
930
|
+
## Acknowledgments
|
|
931
931
|
|
|
932
932
|
Special thanks to all contributors and users of this library.
|