Socket
Socket
Sign inDemoInstall

ts-json-serializer

Package Overview
Dependencies
71
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.1.0 to 1.2.0

tsconfig.json

7

CHANGELOG.md

@@ -7,2 +7,6 @@ # Change Log

## [1.2.0]
#### Added
- Possibility to serialize / deserialize `null`.
## [1.1.0]

@@ -28,3 +32,4 @@ #### Added

[Unreleased]: https://github.com/buehler/ts-json-serializer/compare/v1.1.0...master
[Unreleased]: https://github.com/buehler/ts-json-serializer/compare/v1.2.0...master
[1.2.0]: https://github.com/buehler/ts-json-serializer/compare/v1.1.0...v1.2.0
[1.1.0]: https://github.com/buehler/ts-json-serializer/compare/v1.0.1...v1.1.0

@@ -31,0 +36,0 @@ [1.0.1]: https://github.com/buehler/ts-json-serializer/compare/v1.0.0...v1.0.1

@@ -54,1 +54,11 @@ /**

}
/**
* Error that is thrown when an input to deserialize or serialize is undefined.
*
* @export
* @class UndefinedInputError
*/
export declare class UndefinedInputError {
message: string;
constructor(functionname: string);
}
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
/**

@@ -72,1 +73,14 @@ * Error that is thrown when a class has a constructor with parameters. So you need to provide a factory

exports.ReferenceObjectNotFoundError = ReferenceObjectNotFoundError;
/**
* Error that is thrown when an input to deserialize or serialize is undefined.
*
* @export
* @class UndefinedInputError
*/
var UndefinedInputError = (function () {
function UndefinedInputError(functionname) {
this.message = "The input of your '" + functionname + "' call was undefined.\n Undefined can't be serlialized or deserialized.";
}
return UndefinedInputError;
}());
exports.UndefinedInputError = UndefinedInputError;

@@ -5,2 +5,3 @@ "use strict";

}
Object.defineProperty(exports, "__esModule", { value: true });
require("reflect-metadata");

@@ -7,0 +8,0 @@ __export(require("./Serializable"));

5

package.json
{
"name": "ts-json-serializer",
"version": "1.1.0",
"version": "1.2.0",
"description": "Object serialization made easy with decorators.",

@@ -13,3 +13,3 @@ "main": "index.js",

"predevelop": "npm run clean",
"develop": "tsc -p ./tsconfig/develop.json",
"develop": "tsc -p .",
"prebuild": "npm run clean",

@@ -50,2 +50,3 @@ "build": "tsc -p ./tsconfig/build.json"

"dependencies": {
"coveralls": "^2.11.9",
"reflect-metadata": "^0.1.9",

@@ -52,0 +53,0 @@ "tslib": "^1.5.0"

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var errors_1 = require("./errors");

@@ -3,0 +4,0 @@ /**

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var SerializableType_1 = require("./SerializableType");

@@ -3,0 +4,0 @@ var Resolver_1 = require("./Resolver");

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
/**

@@ -3,0 +4,0 @@ * Instance of a serializable type. Contains the necessary information for the system to serialize

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var errors_1 = require("./errors");

@@ -53,6 +54,9 @@ var Resolver_1 = require("./Resolver");

var _this = this;
if (objectOrArray === undefined) {
throw new errors_1.UndefinedInputError('serialize');
}
this.references = {};
var serialized;
if (objectOrArray.constructor === Array) {
serialized = objectOrArray.map(function (o) { return _this.serializeObject(o); });
if (objectOrArray !== null && objectOrArray.constructor === Array) {
serialized = objectOrArray.filter(function (o) { return o !== undefined; }).map(function (o) { return _this.serializeObject(o); });
}

@@ -76,6 +80,9 @@ else {

var _this = this;
if (json === undefined) {
throw new errors_1.UndefinedInputError('deserialize');
}
this.references = {};
var parsed = JSON.parse(json);
var deserialized;
if (parsed.constructor === Array) {
if (parsed !== null && parsed.constructor === Array) {
deserialized = parsed.map(function (o) { return _this.deserializeObject(o); });

@@ -101,4 +108,10 @@ }

var _this = this;
if (obj.constructor === Date) {
if (obj === null) {
return {
__type: 'null',
__value: null
};
}
else if (obj.constructor === Date) {
return {
__type: 'Date',

@@ -164,2 +177,4 @@ __value: obj

switch (obj.__type) {
case 'null':
return null;
case 'Date':

@@ -207,2 +222,5 @@ return new Date(obj.__value);

TsSerializer.prototype.resolveReferences = function (obj) {
if (obj === null) {
return;
}
for (var _i = 0, _a = Object.keys(obj); _i < _a.length; _i++) {

@@ -209,0 +227,0 @@ var property = _a[_i];

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc