From 5956fc175132df746c18332e0e953858f2626e26 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Lemaire?= Date: Sun, 30 Dec 2018 18:12:21 +0100 Subject: [PATCH] 1.0.0 version --- README.md | 37 +++++++++++++++++++++++++++++++++++++ activate_node | 6 ++++-- package-lock.json | 30 ++++++++++++++++++++++-------- package.json | 18 +++++++++++++----- src/main.ts | 6 +++--- tsconfig.json | 5 +++-- 6 files changed, 82 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index e69de29..466e377 100644 --- a/README.md +++ b/README.md @@ -0,0 +1,37 @@ +tk-serializer +============= + +About +----- + +This library offers a generic serialization system for Javascript. + +Deep objects state may be serialized to a string, and reconstructed back. + +Class instances are reconstructed properly, as long as they are in the provided namespace. Circular references are handled. + +Usage example +------------- + +```typescript +const namespace = { + Class1, + Class2 +}; +const obj = { + a: [1, "a", new Class1()], + b: new Class2("x"), + c: new Class3() +}; + +let serializer = new Serializer(namespace); + +// Optionally, some class instances may be ignored (they will be replaced by *undefined*) +serializer.addIgnoredClass("Class3"); + +// Serialize the object to a string +let state: string = serializer.serialize(obj); + +// Reconstruct the object back (*c* will be undefined) +let nobj = serializer.unserialize(state); +``` \ No newline at end of file diff --git a/activate_node b/activate_node index 966625f..1cf49b6 100644 --- a/activate_node +++ b/activate_node @@ -2,13 +2,15 @@ # Usage: # source activate_node +vdir="./.venv" +expected="10.15.0" + if [ \! -f "./activate_node" ] then echo "Not in project directory" exit 1 fi -vdir="./.venv" test -x "${vdir}/bin/nodeenv" || ( python3 -m venv "${vdir}" && "${vdir}/bin/pip" install --upgrade nodeenv ) -test -e "${vdir}/node/bin/activate" || "${vdir}/bin/nodeenv" --node=10.15.0 --force "${vdir}/node" +test "$(${vdir}/node/bin/nodejs --version)" = "v${expected}" || "${vdir}/bin/nodeenv" --node=${expected} --force "${vdir}/node" source "${vdir}/node/bin/activate" diff --git a/package-lock.json b/package-lock.json index fe8b0a9..1310bd4 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "tk-serializer", - "version": "1.0.0", + "version": "0.1.32", "lockfileVersion": 1, "requires": true, "dependencies": { @@ -1636,12 +1636,14 @@ "balanced-match": { "version": "1.0.0", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "brace-expansion": { "version": "1.1.11", "bundled": true, "dev": true, + "optional": true, "requires": { "balanced-match": "^1.0.0", "concat-map": "0.0.1" @@ -1656,17 +1658,20 @@ "code-point-at": { "version": "1.1.0", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "concat-map": { "version": "0.0.1", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "console-control-strings": { "version": "1.1.0", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "core-util-is": { "version": "1.0.2", @@ -1783,7 +1788,8 @@ "inherits": { "version": "2.0.3", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "ini": { "version": "1.3.5", @@ -1795,6 +1801,7 @@ "version": "1.0.0", "bundled": true, "dev": true, + "optional": true, "requires": { "number-is-nan": "^1.0.0" } @@ -1809,6 +1816,7 @@ "version": "3.0.4", "bundled": true, "dev": true, + "optional": true, "requires": { "brace-expansion": "^1.1.7" } @@ -1816,12 +1824,14 @@ "minimist": { "version": "0.0.8", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "minipass": { "version": "2.2.4", "bundled": true, "dev": true, + "optional": true, "requires": { "safe-buffer": "^5.1.1", "yallist": "^3.0.0" @@ -1840,6 +1850,7 @@ "version": "0.5.1", "bundled": true, "dev": true, + "optional": true, "requires": { "minimist": "0.0.8" } @@ -1920,7 +1931,8 @@ "number-is-nan": { "version": "1.0.1", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "object-assign": { "version": "4.1.1", @@ -1932,6 +1944,7 @@ "version": "1.4.0", "bundled": true, "dev": true, + "optional": true, "requires": { "wrappy": "1" } @@ -2053,6 +2066,7 @@ "version": "1.0.2", "bundled": true, "dev": true, + "optional": true, "requires": { "code-point-at": "^1.0.0", "is-fullwidth-code-point": "^1.0.0", diff --git a/package.json b/package.json index 3c81910..729290d 100644 --- a/package.json +++ b/package.json @@ -1,19 +1,27 @@ { "name": "tk-serializer", - "version": "0.1.30", + "version": "1.0.0", "description": "Serializer of javascript objects", "main": "dist/main.js", "types": "dist/main.d.ts", "scripts": { "build": "tsc", "test": "jest", - "prepare" : "npm run build", - "prepublishOnly" : "npm test" + "prepare": "npm run build", + "prepublishOnly": "npm test" }, "files": [ "dist" ], - "author": "Michael Lemaire", + "author": { + "name": "Michael Lemaire", + "email": "michael@thunderk.net", + "url": "https://thunderk.net" + }, + "repository": { + "type": "git", + "url": "https://code.thunderk.net/michael/tk-serializer.git" + }, "license": "MIT", "devDependencies": { "@types/jest": "^23.3.10", @@ -22,4 +30,4 @@ "ts-node": "^7.0.1", "typescript": "^3.2.2" } -} +} \ No newline at end of file diff --git a/src/main.ts b/src/main.ts index bee0bac..01e7662 100644 --- a/src/main.ts +++ b/src/main.ts @@ -66,8 +66,8 @@ function classname(obj: Object): string { * A deep serializer of javascript objects. */ export class Serializer { - namespace: any; - ignored: string[] = []; + private namespace: any; + private ignored: string[] = []; constructor(namespace: any) { this.namespace = namespace; @@ -83,7 +83,7 @@ export class Serializer { /** * Construct an object from a constructor name */ - constructObject(ctype: string): Object { + private constructObject(ctype: string): Object { if (ctype == "Object") { return {}; } else { diff --git a/tsconfig.json b/tsconfig.json index 10339b1..46a204b 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -11,7 +11,8 @@ "dom" ], "target": "es6", - "module": "es6", + "module": "commonjs", + "esModuleInterop": true, "declaration": true, "outDir": "dist" }, @@ -23,4 +24,4 @@ "out", "node_modules" ] -} +} \ No newline at end of file