55 lines
1.6 KiB
TypeScript
55 lines
1.6 KiB
TypeScript
/**
|
|
* @author Martin Karkowski
|
|
* @email m.karkowski@zema.de
|
|
* @create date 2018-05-22 12:39:42
|
|
* @modify date 2020-09-08 16:49:53
|
|
* @desc [description]
|
|
*/
|
|
|
|
import { injectable } from 'inversify';
|
|
import { isObject } from '../../../lib/helpers/objectMethods';
|
|
import { AvailableFromConvertes, AvailableToConvertes, IConverter } from '../type/interfaces';
|
|
|
|
@injectable()
|
|
export class ToStringConverter implements IConverter<any, string, any> {
|
|
public readonly name: AvailableFromConvertes | AvailableToConvertes;
|
|
|
|
/**
|
|
* Register only Endpoints.
|
|
*
|
|
* @param {string} identifier The Identifier for the Convertert
|
|
* @param {*} config The Config to use.
|
|
* @memberof ToStringConverter
|
|
*/
|
|
register(_identifier: string, _config: any): void {
|
|
|
|
}
|
|
|
|
/**
|
|
* Converts the Data.
|
|
*
|
|
* @param {*} data The Data to use.
|
|
* @param {string} identifier the Identifier to convert the Data
|
|
* @param {number} timeStamp the given TimeStamp.
|
|
* @returns {string} the Data as String
|
|
* @memberof ToStringConverter
|
|
*/
|
|
convert(data: any, identifier: string, timeStamp: number): string {
|
|
if (isObject(data) || Array.isArray(data)) {
|
|
// return /** Convert the Data to JSON */ JSON.stringify(data, undefined, 4);
|
|
return /** Convert the Data to JSON */ JSON.stringify(data);
|
|
} else {
|
|
return /** Return the Raw-Data */ data.toString();
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Creates an instance of ToStringConverter.
|
|
* @memberof ToStringConverter
|
|
*/
|
|
constructor() {
|
|
/** Set the Name of the Converter */
|
|
this.name = 'to-string';
|
|
}
|
|
}
|