1.0.0 version

This commit is contained in:
Michaël Lemaire 2018-12-30 18:12:21 +01:00
parent aa7db7c3d9
commit 5956fc1751
6 changed files with 82 additions and 20 deletions

View file

@ -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);
```

View file

@ -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"

30
package-lock.json generated
View file

@ -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",

View file

@ -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"
}
}
}

View file

@ -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 {

View file

@ -11,7 +11,8 @@
"dom"
],
"target": "es6",
"module": "es6",
"module": "commonjs",
"esModuleInterop": true,
"declaration": true,
"outDir": "dist"
},
@ -23,4 +24,4 @@
"out",
"node_modules"
]
}
}