ts-serializable 3.0.56 → 3.0.59

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 (3) hide show
  1. package/LICENSE +0 -0
  2. package/README.md +31 -22
  3. package/package.json +54 -38
package/LICENSE CHANGED
File without changes
package/README.md CHANGED
@@ -3,13 +3,16 @@ Serializable
3
3
 
4
4
  Small library for deserialization and serialization for javascript and typescript
5
5
 
6
- Description:
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)
10
+
9
11
  - By default library 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.
10
12
 
11
- Usage:
13
+ Usage
12
14
  ------
15
+
13
16
  This example writed on typescript, but if remove typing, then him will work and on javascript.
14
17
 
15
18
  ```typescript
@@ -22,25 +25,25 @@ export class User extends Serializable {
22
25
  // will have invalid type, then will return default value
23
26
  @jsonProperty(Number, null)
24
27
  public id: number | null = null; // default value necessarily
25
-
28
+
26
29
  @jsonProperty(String)
27
30
  public firstName: string = ''; // default value necessarily
28
-
31
+
29
32
  @jsonProperty(String)
30
33
  public familyName: string = ''; // default value necessarily
31
-
34
+
32
35
  @jsonProperty(String, void 0)
33
36
  public lastName?: string = void 0; // default value necessarily
34
-
37
+
35
38
  @jsonProperty(Date)
36
39
  public birthdate: Date = new Date(); // default value necessarily
37
-
40
+
38
41
  @jsonProperty([String])
39
42
  public tags: string[] = []; // default value necessarily
40
-
43
+
41
44
  @jsonProperty(OtherClassConstructor, null)
42
45
  public other: OtherClassConstructor | null = null; // default value necessarily
43
-
46
+
44
47
  public getFullName(): string {
45
48
  return [
46
49
  this.firstName,
@@ -76,8 +79,9 @@ user.getFullName(); // work fine and return string
76
79
  user.getAge(); // work fine and return number
77
80
  ```
78
81
 
79
- Naming strategies:
82
+ Naming strategies
80
83
  ------
84
+
81
85
  Supported conversion between different naming cases, such as SnakeCase, KebabCase, PascalCase and CamelCase. Also you can set custom name for property of json object.
82
86
 
83
87
  ```typescript
@@ -114,8 +118,9 @@ user.dateOfBirth?.toISOString() === json.date_of_birth; // true
114
118
  user.veryStrangePropertyName === json["very::strange::json:name"]; // true
115
119
  ```
116
120
 
117
- Settings:
121
+ Settings
118
122
  ------
123
+
119
124
  How to specify settings:
120
125
 
121
126
  ```typescript
@@ -131,16 +136,18 @@ new User().fromJSON(json: object, settings?: Partial<SerializationSettings>);
131
136
  ```
132
137
 
133
138
  Supported settings:
134
- - **namingStrategy**, INamingStrategy, default null - property name conversion strategies.
135
- - **dateFormatHandling**, enum, default IsoDateFormat - ...coming soon.
136
- - **missingMemberHandling**, enum, default Ignore - ...coming soon.
137
- - **referenceLoopHandling**, enum, default Serialize - ...coming soon.
138
- - **nullValueHandling**, enum, default Include - ...coming soon.
139
- - **defaultValueHandling**, enum, default Ignore - ...coming soon.
140
- - **logLevel**, enum, default Warning - ...coming soon.
141
-
142
- View-Models from Backend Models:
139
+
140
+ - **namingStrategy**, INamingStrategy, default null - property name conversion strategies.
141
+ - **dateFormatHandling**, enum, default IsoDateFormat - ...coming soon.
142
+ - **missingMemberHandling**, enum, default Ignore - ...coming soon.
143
+ - **referenceLoopHandling**, enum, default Serialize - ...coming soon.
144
+ - **nullValueHandling**, enum, default Include - ...coming soon.
145
+ - **defaultValueHandling**, enum, default Ignore - ...coming soon.
146
+ - **logLevel**, enum, default Warning - ...coming soon.
147
+
148
+ View-Models from Backend Models
143
149
  ------
150
+
144
151
  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.
145
152
 
146
153
  ```typescript
@@ -150,7 +157,7 @@ export class User extends Serializable {
150
157
 
151
158
  @jsonProperty(String)
152
159
  public firstName: string = ''; // default value necessarily
153
-
160
+
154
161
  @jsonProperty(String)
155
162
  public familyName: string = ''; // default value necessarily
156
163
 
@@ -165,9 +172,11 @@ JSON.stringify(user);
165
172
  // Result: {"firstName":"","familyName":""}
166
173
  ```
167
174
 
168
- Bonus:
175
+ Bonus
169
176
  ------
177
+
170
178
  Deep copy
179
+
171
180
  ```typescript
172
181
  const newUser: User = new User().fromJSON(oldUser);
173
182
  ```
package/package.json CHANGED
@@ -1,38 +1,54 @@
1
- {
2
- "name": "ts-serializable",
3
- "version": "3.0.56",
4
- "description": "Serialization and deserializtion for classes",
5
- "main": "./dist/index.js",
6
- "type": "module",
7
- "typings": "./dist/index.d.ts",
8
- "dependencies": {},
9
- "peerDependencies": {
10
- "reflect-metadata": ">=0.1.0"
11
- },
12
- "devDependencies": {
13
- "@labeg/code-style": "^4.0.7",
14
- "@types/chai": "^4.3.14",
15
- "@types/mocha": "^10.0.6",
16
- "chai": "^5.1.0",
17
- "mocha": "^10.4.0",
18
- "reflect-metadata": "^0.2.2",
19
- "ts-node": "^10.9.2",
20
- "typescript": "^5.4.5"
21
- },
22
- "scripts": {
23
- "cs:eslint": "eslint --fix -c .eslintrc.cjs --ext .tsx,.ts,.jsx,.js ./src/ ./tests/",
24
- "test": "mocha --reporter spec --require ts-node/register tests/*.test.ts",
25
- "build": "rm -rf dist/ && tsc --project tsconfig.build.json && node ./dist/index.js",
26
- "prepublishOnly": "npm run cs:eslint && npm run build && npm run test && npm version patch"
27
- },
28
- "repository": {
29
- "type": "git",
30
- "url": " git@github.com:LabEG/Serializable.git"
31
- },
32
- "keywords": [
33
- "serialization",
34
- "deserialization"
35
- ],
36
- "author": "LabEG",
37
- "license": "MIT"
38
- }
1
+ {
2
+ "name": "ts-serializable",
3
+ "version": "3.0.59",
4
+ "author": "Eugene Labutin",
5
+ "license": "MIT",
6
+ "homepage": "https://github.com/LabEG/Serializable#readme",
7
+ "description": "Serialization and deserializtion for classes",
8
+ "main": "./dist/index.js",
9
+ "type": "module",
10
+ "typings": "./dist/index.d.ts",
11
+ "repository": {
12
+ "type": "git",
13
+ "url": " git@github.com:LabEG/Serializable.git"
14
+ },
15
+ "bugs": {
16
+ "url": "https://github.com/LabEG/Serializable/issues"
17
+ },
18
+ "lint-staged": {
19
+ "./(src|tests)/**/*.(ts|tsx|js|jsx)": [
20
+ "eslint --fix -c .eslintrc.cjs --ext .tsx,.ts,.jsx,.js"
21
+ ]
22
+ },
23
+ "scripts": {
24
+ "lint": "eslint --fix -c .eslintrc.cjs --ext .tsx,.ts,.jsx,.js ./src/ ./tests/",
25
+ "test": "mocha",
26
+ "build": "tsc --project tsconfig.build.json && node ./dist/index.js",
27
+ "prepublishOnly": "npm run lint && npm run build && npm run test",
28
+ "release": "standard-version",
29
+ "prepare": "husky install"
30
+ },
31
+ "peerDependencies": {
32
+ "reflect-metadata": ">=0.1.0"
33
+ },
34
+ "devDependencies": {
35
+ "@labeg/code-style": "^4.1.0",
36
+ "@types/chai": "^4.3.16",
37
+ "@types/mocha": "^10.0.6",
38
+ "chai": "^5.1.1",
39
+ "mocha": "^10.4.0",
40
+ "reflect-metadata": "^0.2.2",
41
+ "ts-node": "^10.9.2",
42
+ "tsx": "^4.11.0",
43
+ "typescript": "^5.4.5",
44
+ "@commitlint/cli": "^19.3.0",
45
+ "@commitlint/config-conventional": "^19.2.2",
46
+ "husky": "^9.0.11",
47
+ "lint-staged": "^15.2.5",
48
+ "standard-version": "^9.5.0"
49
+ },
50
+ "keywords": [
51
+ "serialization",
52
+ "deserialization"
53
+ ]
54
+ }