You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+23-23Lines changed: 23 additions & 23 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,14 +1,14 @@
1
1
Serializable
2
2
=====
3
3
4
-
Small library for deserialization and serialization for javascript and typescript
4
+
Small library for deserialization and serialization for JavaScript and TypeScript
5
5
6
6
Description
7
7
------
8
8
9
-
- For working this library needed Metadata Reflection API. If your platform (browser/nodejs) don't support it you must use polifyll. Example: [reflect-metadata](https://www.npmjs.com/package/reflect-metadata)
9
+
- For working, this library needs the Metadata Reflection API. If your platform (browser/Node.js) doesn't support it, you must use a polyfill. Example: [reflect-metadata](https://www.npmjs.com/package/reflect-metadata)
10
10
11
-
- By defaultlibrary don't crash on wrong types in json and return default value on wrong property. If you need more secure behavior you must override method `onWrongType` on `Serializable` object and drop exception in this method, by your logic want.
11
+
- By default, the library doesn't crash on wrong types in JSON and returns the default value on the wrong property. If you need more secure behavior, you must override the method `onWrongType` on the `Serializable` object and throw an exception in this method, according to your logic.
12
12
13
13
Installation
14
14
------
@@ -22,36 +22,36 @@ npm install ts-serializable
22
22
Usage
23
23
------
24
24
25
-
This example writed on typescript, but if remove typing, then him will work and on javascript.
25
+
This example is written in TypeScript, but if you remove typing, it will also work in JavaScript.
// @jsonProperty parrameters is accepted types for json
33
-
// properties, if property in json will not by found or
34
-
//will have invalid type, then will return default value
32
+
// @jsonProperty parameters are accepted types for JSON
33
+
// properties. If a property in JSON is not found or
34
+
//has an invalid type, it will return the default value.
35
35
@jsonProperty(Number, null)
36
-
public id:number|null=null; // default value necessarily
36
+
public id:number|null=null; // default value is necessary
37
37
38
38
@jsonProperty(String)
39
-
public firstName:string=''; // default value necessarily
39
+
public firstName:string=''; // default value is necessary
40
40
41
41
@jsonProperty(String)
42
-
public familyName:string=''; // default value necessarily
42
+
public familyName:string=''; // default value is necessary
43
43
44
44
@jsonProperty(String, void0)
45
-
public lastName?:string=void0; // default value necessarily
45
+
public lastName?:string=void0; // default value is necessary
46
46
47
47
@jsonProperty(Date)
48
-
public birthdate:Date=newDate(); // default value necessarily
48
+
public birthdate:Date=newDate(); // default value is necessary
49
49
50
50
@jsonProperty([String])
51
-
public tags:string[] = []; // default value necessarily
51
+
public tags:string[] = []; // default value is necessary
52
52
53
53
@jsonProperty(OtherClassConstructor, null)
54
-
public other:OtherClassConstructor|null=null; // default value necessarily
54
+
public other:OtherClassConstructor|null=null; // default value is necessary
55
55
56
56
public getFullName():string {
57
57
return [
@@ -79,19 +79,19 @@ user.getAge();
79
79
* With Serializable
80
80
*/
81
81
const user:User=newUser().fromJSON(json);
82
-
user.getFullName(); //work fine and return string
83
-
user.getAge(); //work fine and return number
82
+
user.getFullName(); //works fine and returns a string
83
+
user.getAge(); //works fine and returns a number
84
84
85
85
// or
86
86
const user:User=User.fromJSON(json);
87
-
user.getFullName(); //work fine and return string
88
-
user.getAge(); //work fine and return number
87
+
user.getFullName(); //works fine and returns a string
88
+
user.getAge(); //works fine and returns a number
89
89
```
90
90
91
91
Naming strategies
92
92
------
93
93
94
-
Supported conversion between different naming cases, such as SnakeCase, KebabCase, PascalCase and CamelCase. Also you can set custom name for property of json object.
94
+
Supported conversion between different naming cases, such as SnakeCase, KebabCase, PascalCase and CamelCase. Also, you can set a custom name for a property of a JSON object.
95
95
96
96
```typescript
97
97
const json = {
@@ -157,18 +157,18 @@ Supported settings:
157
157
View-Models from Backend Models
158
158
------
159
159
160
-
If you need to create view-model from dto or entities model you can use same model. Just add VM property to dto or entities model and mark this property by @jsonIgnore() decorator and this property will not be serialized to json.
160
+
If you need to create a view-model from a DTO or entities model, you can use the same model. Just add a VM property to the DTO or entities model and mark this property with the @jsonIgnore() decorator, and this property will not be serialized to JSON.
public firstName:string=''; // default value necessarily
168
+
public firstName:string=''; // default value is necessary
169
169
170
170
@jsonProperty(String)
171
-
public familyName:string=''; // default value necessarily
171
+
public familyName:string=''; // default value is necessary
172
172
173
173
@jsonIgnore()
174
174
public isExpanded:boolean=false;
@@ -184,7 +184,7 @@ JSON.stringify(user);
184
184
Class to FormData
185
185
------
186
186
187
-
Sometimes classes contain properties with the File type. Sending such classes via json is a heavy task. Converting a file property to json can freeze the interface for a few seconds if the file is large. A much better solution is to send an Ajax form. Example:
187
+
Sometimes classes contain properties with the File type. Sending such classes via JSON is a heavy task. Converting a file property to JSON can freeze the interface for a few seconds if the file is large. A much better solution is to send an Ajax form. Example:
0 commit comments