Compare commits

...

9 Commits

Author SHA1 Message Date
e11ace6a23 4.0.0 2020-10-05 11:22:17 +00:00
f29b632bd2 BREAKING CHANGE(core): update 2020-10-05 11:22:16 +00:00
25f80b6b59 3.0.12 2020-10-05 11:13:17 +00:00
176ac34504 fix(core): update 2020-10-05 11:13:17 +00:00
2707542234 3.0.11 2020-10-03 11:20:59 +00:00
ee025d094c fix(core): update 2020-10-03 11:20:58 +00:00
9bc1c4bf93 3.0.10 2019-12-15 19:27:19 +00:00
5176a34575 3.0.9 2019-12-15 19:05:21 +00:00
fe9f9299fc fix(core): update 2019-12-15 19:05:20 +00:00
6 changed files with 9731 additions and 803 deletions

View File

@ -3,6 +3,7 @@
"npmAccessLevel": "public" "npmAccessLevel": "public"
}, },
"gitzone": { "gitzone": {
"projectType": "npm",
"module": { "module": {
"githost": "gitlab.com", "githost": "gitlab.com",
"gitscope": "pushrocks", "gitscope": "pushrocks",

10430
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1,13 +1,13 @@
{ {
"name": "@pushrocks/smartjson", "name": "@pushrocks/smartjson",
"version": "3.0.8", "version": "4.0.0",
"private": false, "private": false,
"description": "typed json handlers", "description": "typed json handlers",
"main": "dist/index.js", "main": "dist_ts/index.js",
"typings": "dist/index.d.ts", "typings": "dist_ts/index.d.ts",
"scripts": { "scripts": {
"test": "(tstest test/)", "test": "(tstest test/ --web)",
"build": "(tsbuild)" "build": "(tsbuild --web)"
}, },
"repository": { "repository": {
"type": "git", "type": "git",
@ -20,17 +20,19 @@
}, },
"homepage": "https://gitlab.com/pushrocks/smartjson#README", "homepage": "https://gitlab.com/pushrocks/smartjson#README",
"devDependencies": { "devDependencies": {
"@gitzone/tsbuild": "^2.1.11", "@gitzone/tsbuild": "^2.1.25",
"@gitzone/tsrun": "^1.2.8", "@gitzone/tsrun": "^1.2.12",
"@gitzone/tstest": "^1.0.24", "@gitzone/tstest": "^1.0.52",
"@pushrocks/tapbundle": "^3.0.13", "@pushrocks/tapbundle": "^3.2.9",
"@types/node": "^12.7.2", "@types/node": "^14.11.2",
"tslint": "^5.19.0", "tslint": "^6.1.3",
"tslint-config-prettier": "^1.18.0" "tslint-config-prettier": "^1.18.0"
}, },
"dependencies": { "dependencies": {
"@types/buffer-json": "^2.0.0",
"@types/fast-json-stable-stringify": "^2.0.0", "@types/fast-json-stable-stringify": "^2.0.0",
"fast-json-stable-stringify": "^2.0.0", "buffer-json": "^2.0.0",
"fast-json-stable-stringify": "^2.1.0",
"lodash.clonedeep": "^4.5.0" "lodash.clonedeep": "^4.5.0"
}, },
"files": [ "files": [

View File

@ -26,8 +26,8 @@ tap.test('should create a folded object', async () => {
}); });
tap.test('should enfold from object', async () => { tap.test('should enfold from object', async () => {
mySomeClass.enfoldFromObject({ thisis: 'test2' }); const mySomeClass2 = SomeClass.enfoldFromObject({ thisis: 'test2' });
expect(mySomeClass) expect(mySomeClass2)
.property('thisis') .property('thisis')
.to.equal('test2'); .to.equal('test2');
}); });

View File

@ -1,13 +1,41 @@
import * as plugins from './smartjson.plugins'; import * as plugins from './smartjson.plugins';
export class Smartjson { /**
// ====== * allows you to parse a json
// STATIC */
// ====== export const parse = plugins.bufferJson.parse;
public static parse = JSON.parse;
public static stringify = (objArg: any, optionsArg: plugins.stableJson.Options) => { /**
return plugins.stableJson(objArg, optionsArg); *
* @param objArg
* @param optionsArg
*/
export const stringify = (objArg: any, optionsArg: plugins.IStableJsonTypes['Options'] = {}) => {
const bufferedJson = plugins.bufferJson.stringify(objArg);
objArg = JSON.parse(bufferedJson);
return plugins.stableJson(objArg, optionsArg);
};
export class Smartjson {
/**
* enfolds data from an object
*/
public static enfoldFromObject(objectArg) {
const newInstance = new this();
for (const keyName in objectArg) {
if (newInstance.saveableProperties.indexOf(keyName) !== -1) {
newInstance[keyName] = objectArg[keyName];
}
}
return newInstance;
}
/**
* enfold from json
*/
public static enfoldFromJson(jsonArg: string) {
const objectFromJson = parse(jsonArg);
return this.enfoldFromObject(objectFromJson);
} }
// ======== // ========
@ -28,14 +56,11 @@ export class Smartjson {
} }
/** /**
* enfolds data from an object * folds a class into an object
*/ */
public enfoldFromObject(objectArg) { public foldToJson() {
for (const keyName in objectArg) { const foldedObject = this.foldToObject();
if (this.saveableProperties.indexOf(keyName) !== -1) { return stringify(foldedObject, {});
this[keyName] = objectArg[keyName];
}
}
} }
} }

View File

@ -1,4 +1,20 @@
// third party scope
import lodashCloneDeep from 'lodash.clonedeep'; import lodashCloneDeep from 'lodash.clonedeep';
import stableJson from 'fast-json-stable-stringify'; import stableJson2 from 'fast-json-stable-stringify';
import bufferJson from 'buffer-json';
export { lodashCloneDeep, stableJson }; const stableJson = stableJson2 as any;
export { bufferJson, lodashCloneDeep, stableJson };
export interface IStableJsonTypes {
Comparator: (a: IStableJsonTypes['CompareDescriptor'], b: IStableJsonTypes['CompareDescriptor']) => number;
CompareDescriptor: {
key: string;
value: any;
};
Options: {
cmp?: (a: IStableJsonTypes['CompareDescriptor'], b: IStableJsonTypes['CompareDescriptor']) => number;
cycles?: boolean;
};
}