Comparing version 1.4.1 to 1.5.0
@@ -119,3 +119,4 @@ export interface IModelPropertiesMapper { | ||
camelizeType?: boolean; | ||
camelizeMeta?: boolean; | ||
switchChar?: string; | ||
}; |
@@ -17,2 +17,3 @@ import { IModelPropertiesMapper, IJsonPropertiesMapper, TAnyKeyValueObject, TJsonaModel, TJsonaRelationships, SwitchCaseModelMapperOptionsType, SwitchCaseJsonMapperOptionsType } from './JsonaTypes'; | ||
camelizeType: boolean; | ||
camelizeMeta: boolean; | ||
switchChar: string; | ||
@@ -22,3 +23,4 @@ constructor(options?: SwitchCaseJsonMapperOptionsType); | ||
setAttributes(model: TJsonaModel, attributes: TAnyKeyValueObject): void; | ||
setMeta(model: TJsonaModel, meta: TAnyKeyValueObject): void; | ||
setRelationships(model: TJsonaModel, relationships: TJsonaRelationships): void; | ||
} |
@@ -67,6 +67,7 @@ "use strict"; | ||
var _this = _super.call(this) || this; | ||
var _a = options || {}, _b = _a.camelizeAttributes, camelizeAttributes = _b === void 0 ? true : _b, _c = _a.camelizeRelationships, camelizeRelationships = _c === void 0 ? true : _c, _d = _a.camelizeType, camelizeType = _d === void 0 ? true : _d, _e = _a.switchChar, switchChar = _e === void 0 ? '-' : _e; | ||
var _a = options || {}, _b = _a.camelizeAttributes, camelizeAttributes = _b === void 0 ? true : _b, _c = _a.camelizeRelationships, camelizeRelationships = _c === void 0 ? true : _c, _d = _a.camelizeType, camelizeType = _d === void 0 ? true : _d, _e = _a.camelizeMeta, camelizeMeta = _e === void 0 ? false : _e, _f = _a.switchChar, switchChar = _f === void 0 ? '-' : _f; | ||
_this.camelizeAttributes = camelizeAttributes; | ||
_this.camelizeRelationships = camelizeRelationships; | ||
_this.camelizeType = camelizeType; | ||
_this.camelizeMeta = camelizeMeta; | ||
_this.switchChar = switchChar; | ||
@@ -94,2 +95,14 @@ return _this; | ||
}; | ||
SwitchCaseJsonMapper.prototype.setMeta = function (model, meta) { | ||
var _this = this; | ||
if (!this.camelizeMeta) { | ||
return _super.prototype.setMeta.call(this, model, meta); | ||
} | ||
model.meta = {}; | ||
Object.keys(meta).forEach(function (propName) { | ||
var regex = new RegExp(_this.switchChar + "([a-z0-9])", 'g'); | ||
var camelName = propName.replace(regex, function (g) { return g[1].toUpperCase(); }); | ||
model.meta[camelName] = meta[propName]; | ||
}); | ||
}; | ||
SwitchCaseJsonMapper.prototype.setRelationships = function (model, relationships) { | ||
@@ -96,0 +109,0 @@ var _this = this; |
{ | ||
"name": "jsona", | ||
"description": "Provide data formatters (data model builder & json builder) to work with JSON API specification v1.0 in your JavaScript / TypeScript code", | ||
"version": "1.4.1", | ||
"version": "1.5.0", | ||
"keywords": [ | ||
@@ -6,0 +6,0 @@ "json-api", |
@@ -142,3 +142,4 @@ | ||
camelizeType?: boolean, | ||
camelizeMeta?: boolean, | ||
switchChar?: string, | ||
}; |
@@ -81,2 +81,3 @@ import { | ||
camelizeType: boolean; | ||
camelizeMeta: boolean; | ||
switchChar: string; | ||
@@ -91,2 +92,3 @@ | ||
camelizeType = true, | ||
camelizeMeta = false, | ||
switchChar = '-' | ||
@@ -98,2 +100,3 @@ } = options || {}; | ||
this.camelizeType = camelizeType; | ||
this.camelizeMeta = camelizeMeta; | ||
this.switchChar = switchChar; | ||
@@ -124,2 +127,16 @@ } | ||
setMeta(model: TJsonaModel, meta: TAnyKeyValueObject) { | ||
if (!this.camelizeMeta) { | ||
return super.setMeta(model, meta); | ||
} | ||
model.meta = {}; | ||
Object.keys(meta).forEach((propName) => { | ||
const regex = new RegExp(`${this.switchChar}([a-z0-9])`, 'g'); | ||
const camelName = propName.replace(regex, g => g[1].toUpperCase()); | ||
model.meta[camelName] = meta[propName]; | ||
}); | ||
} | ||
setRelationships(model: TJsonaModel, relationships: TJsonaRelationships) { | ||
@@ -126,0 +143,0 @@ // call super.setRelationships first, just for not to copy paste setRelationships logic |
Sorry, the diff of this file is not supported yet
126961
2159