Skip to content

Commit

Permalink
v1.0.11 (#21)
Browse files Browse the repository at this point in the history
* More fixes to serialization

* Update changelog, bump version

* Remove console.log
  • Loading branch information
rolandzwaga authored Oct 29, 2022
1 parent f859bb8 commit 6d07ca5
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 4 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Change Log

## 1.0.11
- Extra check for controller instance serialization

## 1.0.10
- Don't serialize controllers in diagnostic messages.
- Several fixes in json schema generator
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "1.0.10",
"version": "1.0.11",
"license": "MIT",
"main": "dist/index.js",
"homepage": "https://rolandzwaga.github.io/eligius/",
Expand Down
10 changes: 9 additions & 1 deletion src/test/unit/util/prepare-value-for-serialization.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,14 @@ import { prepareValueForSerialization } from '../../../util/prepare-value-for-se

const PrepareValueForSerializationSuite = suite('prepareValueForSerialization');

function SimpleClass(this: any) {
this.i = 0;
return this;
}

PrepareValueForSerializationSuite('should seriaize the given object', () => {
// given

const object = {
a: 1,
b: $('body'),
Expand All @@ -19,6 +25,7 @@ PrepareValueForSerializationSuite('should seriaize the given object', () => {
f: undefined,
controllerInstance: new LabelController(),
someObject: { prop: true },
simpleClass: new (SimpleClass as any)(),
};

// test
Expand All @@ -31,8 +38,9 @@ PrepareValueForSerializationSuite('should seriaize the given object', () => {
expect(result.d).to.eql([1, 'a', 'jQuery object', '(i) => i']);
expect(result.e).to.be.null;
expect(result.f).to.be.undefined;
expect(result.controllerInstance).to.equal('Complex object');
expect(result.controllerInstance).to.equal('class LabelController {');
expect(result.someObject.prop).to.be.true;
expect(result.simpleClass).to.equal('function SimpleClass() {');
});

PrepareValueForSerializationSuite.run();
8 changes: 6 additions & 2 deletions src/util/prepare-value-for-serialization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,12 @@ export function prepareValueForSerialization(value: any): any {
} else if (value instanceof jQuery) {
return 'jQuery object';
} else if (value !== null && typeof value === 'object') {
if (value.constructor.toString().substring(0, 5) === 'class') {
return 'Complex object';
if (
value.constructor.toString().substring(0, 5) === 'class' ||
!value.constructor.toString().startsWith('function Object()')
) {
const funcString: string = value.constructor.toString();
return funcString.substring(0, funcString.indexOf('{') + 1);
}
return Object.fromEntries(
Object.entries(value).map(([propName, propValue]) => [
Expand Down

0 comments on commit 6d07ca5

Please sign in to comment.