BREAKING CHANGE(core): renamed Folable to Smartjson and added deterministic stringify
This commit is contained in:
19
ts/index.ts
19
ts/index.ts
@ -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
7
ts/smartjson.plugins.ts
Normal file
@ -0,0 +1,7 @@
|
||||
import * as lodash from 'lodash';
|
||||
import * as stableJson from 'fast-json-stable-stringify';
|
||||
|
||||
export {
|
||||
lodash,
|
||||
stableJson
|
||||
}
|
Reference in New Issue
Block a user