From 57a16b23c57b600dd446298a26fdf1eb627d0955 Mon Sep 17 00:00:00 2001 From: Emrah Kaya Date: Sat, 13 Jan 2018 21:28:24 +0100 Subject: [PATCH] stringsOnlyObject does typechecking before coercion to string --- Video.js | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/Video.js b/Video.js index b835664d..2db74fbd 100644 --- a/Video.js +++ b/Video.js @@ -23,6 +23,29 @@ export default class Video extends Component { setNativeProps(nativeProps) { this._root.setNativeProps(nativeProps); } + + toTypeString(x) { + switch (typeof x) { + case "object": + return x instanceof Date + ? x.toISOString() + : JSON.stringify(x); // object, null + case "undefined": + return ""; + default: // boolean, number, string + return x.toString(); + } + } + + stringsOnlyObject(obj) { + const strObj = {}; + + Object.keys(obj).forEach(x => { + strObj[x] = this.toTypeString(obj[x]); + }); + + return strObj; + } stringsOnlyObject(obj) { const strObj = {};