Compare commits

...

4 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
4 changed files with 43 additions and 23 deletions

2
package-lock.json generated
View File

@ -1,6 +1,6 @@
{
"name": "@pushrocks/smartjson",
"version": "3.0.11",
"version": "4.0.0",
"lockfileVersion": 1,
"requires": true,
"dependencies": {

View File

@ -1,6 +1,6 @@
{
"name": "@pushrocks/smartjson",
"version": "3.0.11",
"version": "4.0.0",
"private": false,
"description": "typed json handlers",
"main": "dist_ts/index.js",

View File

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

View File

@ -1,18 +1,41 @@
import * as plugins from './smartjson.plugins';
export class Smartjson {
// ======
// STATIC
// ======
/**
* allows you to parse a json
*/
public static parse = plugins.bufferJson.parse;
/**
* allows you to parse a json
*/
export const parse = plugins.bufferJson.parse;
public static stringify = (objArg: any, optionsArg: plugins.IStableJsonTypes['Options']) => {
const bufferedJson = plugins.bufferJson.stringify(objArg);
objArg = JSON.parse(bufferedJson);
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);
}
// ========
@ -33,14 +56,11 @@ export class Smartjson {
}
/**
* enfolds data from an object
* folds a class into an object
*/
public enfoldFromObject(objectArg) {
for (const keyName in objectArg) {
if (this.saveableProperties.indexOf(keyName) !== -1) {
this[keyName] = objectArg[keyName];
}
}
public foldToJson() {
const foldedObject = this.foldToObject();
return stringify(foldedObject, {});
}
}