BREAKING CHANGE(core): renamed Folable to Smartjson and added deterministic stringify

This commit is contained in:
2019-02-14 23:16:34 +01:00
parent a9ad89d320
commit 5e945ddad6
9 changed files with 842 additions and 368 deletions

View File

@ -1,15 +1,26 @@
let lodash = require('lodash');
import * as plugins from './smartjson.plugins';
export class Smartjson {
// ======
// STATIC
// ======
static parse = JSON.parse;
static stringify = plugins.stableJson;
// ========
// INSTANCE
// ========
export class Foldable {
saveableProperties: string[];
/**
* folds a class into an object
*/
foldToObject() {
let newFoldedObject = {};
let newFoldedObject: {[key: string]: any} = {};
for (let keyName of this.saveableProperties) {
newFoldedObject[keyName] = lodash.cloneDeep(this[keyName]);
newFoldedObject[keyName] = plugins.lodash.cloneDeep(this[keyName]);
}
return newFoldedObject;
}

7
ts/smartjson.plugins.ts Normal file
View File

@ -0,0 +1,7 @@
import * as lodash from 'lodash';
import * as stableJson from 'fast-json-stable-stringify';
export {
lodash,
stableJson
}